implement more shit
All checks were successful
/ build (push) Successful in 39s

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

View file

@ -23,13 +23,15 @@ import net.minestom.server.instance.InstanceContainer;
import net.minestom.server.instance.InstanceManager; import net.minestom.server.instance.InstanceManager;
import net.minestom.server.instance.LightingChunk; import net.minestom.server.instance.LightingChunk;
import net.minestom.server.instance.block.Block; import net.minestom.server.instance.block.Block;
import net.minestom.server.message.ChatPosition;
import net.minestom.server.message.Messenger;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) throws JsonIOException, JsonSyntaxException, FileNotFoundException {
File file = new File("config.json"); File file = new File("config.json");
if (!file.exists()) { if (!file.exists()) {
System.err.println("config.json missing!"); System.err.println("config.json missing!");
@ -40,12 +42,7 @@ public class Main {
return; return;
} }
JsonObject json = JsonParser.parseString("{}").getAsJsonObject(); JsonObject json = JsonParser.parseReader(new FileReader("config.json")).getAsJsonObject();
try {
json = JsonParser.parseReader(new FileReader("config.json")).getAsJsonObject();
} catch (JsonIOException | JsonSyntaxException | FileNotFoundException e) {
e.printStackTrace();
}
MinecraftServer minecraftServer = MinecraftServer.init(); MinecraftServer minecraftServer = MinecraftServer.init();
@ -138,10 +135,28 @@ public class Main {
}); });
globalEventHandler.addListener(PlayerDisconnectEvent.class, event -> { globalEventHandler.addListener(PlayerDisconnectEvent.class, event -> {
MinecraftServer.LOGGER.info("Player " + event.getPlayer().getUsername() + " left."); MinecraftServer.LOGGER.info("Player " + event.getPlayer().getUsername() + " left.");
Messenger.sendMessage(
MinecraftServer.getConnectionManager().getOnlinePlayers(),
Component.empty()
.append(Component.text("[").color(TextColor.color(50, 50, 50)))
.append(Component.text("-").color(TextColor.color(255, 0, 0)))
.append(Component.text("] ").color(TextColor.color(50, 50, 50)))
.append(Component.text(event.getPlayer().getUsername())),
ChatPosition.SYSTEM_MESSAGE,
null);
}); });
globalEventHandler.addListener(PlayerSpawnEvent.class, event -> { globalEventHandler.addListener(PlayerSpawnEvent.class, event -> {
MinecraftServer.LOGGER.info("Player " + event.getPlayer().getUsername() + " joined!"); MinecraftServer.LOGGER.info("Player " + event.getPlayer().getUsername() + " joined!");
Messenger.sendMessage(
MinecraftServer.getConnectionManager().getOnlinePlayers(),
Component.empty()
.append(Component.text("[").color(TextColor.color(50, 50, 50)))
.append(Component.text("+").color(TextColor.color(0, 255, 0)))
.append(Component.text("] ").color(TextColor.color(50, 50, 50)))
.append(Component.text(event.getPlayer().getUsername())),
ChatPosition.SYSTEM_MESSAGE,
null);
event.getEntity().sendMessage(Component.text("Welcome to The Alliance!").color(TextColor.color(255, 0, 0))); 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,");
@ -149,6 +164,13 @@ public class Main {
.append(Component.text("/server ").color(TextColor.color(255, 0, 0))) .append(Component.text("/server ").color(TextColor.color(255, 0, 0)))
.append(Component.text("<server name>").color(TextColor.color(0, 255, 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.getEntity()
.sendMessage(Component.text("https://git.sad.ovh/sophie/lobby version is ")
.color(TextColor.color(155, 155, 155))
.append(Component
.text((json.has("version") ? json.get("version").getAsString() : "not specified"))
.color(TextColor.color(255, 255, 0))));
event.getPlayer().setAllowFlying(true); event.getPlayer().setAllowFlying(true);
}); });