make chat prettier + turn on flying
All checks were successful
/ build (push) Successful in 39s

This commit is contained in:
Soph :3 2024-05-07 18:03:59 +03:00
parent 27fbb70dd3
commit 8481ee189a
Signed by: sophie
GPG key ID: EDA5D222A0C270F2

View file

@ -5,6 +5,8 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Pos; import net.minestom.server.coordinate.Pos;
@ -12,6 +14,8 @@ import net.minestom.server.entity.GameMode;
import net.minestom.server.event.GlobalEventHandler; import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent; import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
import net.minestom.server.event.player.PlayerBlockInteractEvent; import net.minestom.server.event.player.PlayerBlockInteractEvent;
import net.minestom.server.event.player.PlayerChatEvent;
import net.minestom.server.event.player.PlayerDisconnectEvent;
import net.minestom.server.event.player.PlayerSpawnEvent; import net.minestom.server.event.player.PlayerSpawnEvent;
import net.minestom.server.extras.velocity.VelocityProxy; import net.minestom.server.extras.velocity.VelocityProxy;
import net.minestom.server.instance.AnvilLoader; import net.minestom.server.instance.AnvilLoader;
@ -112,19 +116,40 @@ public class Main {
event.getInstance().setBlock(event.getBlockPosition(), newBlock); event.getInstance().setBlock(event.getBlockPosition(), newBlock);
} }
if (isDoor) { if (isDoor) {
Point pos = event.getBlockPosition().add(0, event.getBlock().getProperty("half").equals("upper") ? -1 : 1, Point pos = event.getBlockPosition().add(0,
event.getBlock().getProperty("half").equals("upper") ? -1 : 1,
0); 0);
Block newBlock = event.getInstance().getBlock(pos).withProperty("open", Block newBlock = event.getInstance().getBlock(pos).withProperty("open",
event.getBlock().getProperty("open").equals("true") ? "false" : "true"); event.getBlock().getProperty("open").equals("true") ? "false" : "true");
event.getInstance().setBlock(pos, newBlock); event.getInstance().setBlock(pos, newBlock);
} }
}); });
globalEventHandler.addListener(PlayerChatEvent.class, event -> {
event.setChatFormat((e) -> {
final String username = e.getPlayer().getUsername();
return Component.empty()
.append(Component.text(username)
.color(TextColor.color(170, 170, 170)))
.append(Component.text(": "))
.append(Component.text(e.getMessage()));
});
});
globalEventHandler.addListener(PlayerDisconnectEvent.class, event -> {
MinecraftServer.LOGGER.info("Player " + event.getPlayer().getUsername() + " left.");
});
globalEventHandler.addListener(PlayerSpawnEvent.class, event -> { globalEventHandler.addListener(PlayerSpawnEvent.class, event -> {
event.getEntity().sendMessage("Welcome to The Alliance!"); MinecraftServer.LOGGER.info("Player " + event.getPlayer().getUsername() + " joined!");
event.getEntity().sendMessage(Component.text("Welcome to The Alliance!").color(TextColor.color(255, 0, 0)));
event.getEntity().sendMessage(""); event.getEntity().sendMessage("");
event.getEntity().sendMessage("Use /server to list the available servers,"); event.getEntity().sendMessage("Use /server to list the available servers,");
event.getEntity().sendMessage("and then join them via /server <server name>"); event.getEntity().sendMessage(Component.text("and then join them via ")
.append(Component.text("/server ").color(TextColor.color(255, 0, 0)))
.append(Component.text("<server name>").color(TextColor.color(0, 255, 0))));
event.getEntity().sendMessage("I hope you enjoy the server! -sophie"); event.getEntity().sendMessage("I hope you enjoy the server! -sophie");
event.getPlayer().setAllowFlying(true);
}); });
// Start the server // Start the server
@ -132,4 +157,5 @@ public class Main {
System.out.println("Server started on host " + json.get("host").getAsString() + " and port " System.out.println("Server started on host " + json.get("host").getAsString() + " and port "
+ json.get("port").getAsInt()); + json.get("port").getAsInt());
} }
} }