From effcbab3e475e0051de74bfccd06afd44744ee39 Mon Sep 17 00:00:00 2001 From: LOOHP Date: Sun, 1 May 2022 15:29:46 +0100 Subject: [PATCH] Fixed PacketPlayInPluginMessaging & Added default command /version --- pom.xml | 2 +- src/main/java/com/loohp/limbo/Limbo.java | 25 +++++++++++-------- .../loohp/limbo/commands/DefaultCommands.java | 20 ++++++++++----- .../java/com/loohp/limbo/consolegui/GUI.java | 5 +++- .../loohp/limbo/consolegui/SystemInfo.java | 19 ++++++++------ .../player/PlayerResourcePackStatusEvent.java | 11 +++----- .../events/player/PluginMessageEvent.java | 1 - .../loohp/limbo/file/ServerProperties.java | 4 +-- .../java/com/loohp/limbo/metrics/Metrics.java | 4 +-- .../packets/PacketPlayInPluginMessaging.java | 6 ++--- src/main/resources/permission.yml | 1 + 11 files changed, 55 insertions(+), 43 deletions(-) diff --git a/pom.xml b/pom.xml index e379901..f6fe01f 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ com.loohp Limbo Limbo - 0.6.14-ALPHA + 0.6.15-ALPHA Standalone Limbo Minecraft Server. https://github.com/LOOHP/Limbo diff --git a/src/main/java/com/loohp/limbo/Limbo.java b/src/main/java/com/loohp/limbo/Limbo.java index 78e5559..d1e0be7 100644 --- a/src/main/java/com/loohp/limbo/Limbo.java +++ b/src/main/java/com/loohp/limbo/Limbo.java @@ -86,6 +86,8 @@ import net.querz.nbt.io.NBTUtil; import net.querz.nbt.tag.CompoundTag; +import javax.swing.UnsupportedLookAndFeelException; + public class Limbo { public static final String LIMBO_BRAND = "Limbo"; @@ -110,12 +112,13 @@ public static void main(String args[]) throws IOException, ParseException, Numbe } if (!noGui) { System.out.println("Launching Server GUI.. Add \"--nogui\" in launch arguments to disable"); - Thread t1 = new Thread(new Runnable() { - @Override - public void run() { - GUI.main(); - } - }); + Thread t1 = new Thread(() -> { + try { + GUI.main(); + } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + }); t1.start(); } @@ -128,9 +131,9 @@ public static Limbo getInstance() { //=========================== - public final String serverImplementationVersion = "1.18.2"; - public final int serverImplementationProtocol = 758; - public final String limboImplementationVersion; + public final String SERVER_IMPLEMENTATION_VERSION = "1.18.2"; + public final int SERVER_IMPLEMENTATION_PROTOCOL = 758; + public final String LIMBO_IMPLEMENTATION_VERSION; private AtomicBoolean isRunning; @@ -176,8 +179,8 @@ public Limbo() throws IOException, ParseException, NumberFormatException, ClassN console = new Console(System.in, System.out, System.err); } - limboImplementationVersion = getLimboVersion(); - console.sendMessage("Loading Limbo Version " + limboImplementationVersion + " on Minecraft " + serverImplementationVersion); + LIMBO_IMPLEMENTATION_VERSION = getLimboVersion(); + console.sendMessage("Loading Limbo Version " + LIMBO_IMPLEMENTATION_VERSION + " on Minecraft " + SERVER_IMPLEMENTATION_VERSION); String spName = "server.properties"; File sp = new File(spName); diff --git a/src/main/java/com/loohp/limbo/commands/DefaultCommands.java b/src/main/java/com/loohp/limbo/commands/DefaultCommands.java index aedcc21..b338344 100644 --- a/src/main/java/com/loohp/limbo/commands/DefaultCommands.java +++ b/src/main/java/com/loohp/limbo/commands/DefaultCommands.java @@ -39,6 +39,16 @@ public void execute(CommandSender sender, String[] args) { if (args.length == 0) { return; } + + if (args[0].equalsIgnoreCase("version")) { + if (sender.hasPermission("limboserver.version")) { + sender.sendMessage(ChatColor.DARK_GRAY + "This server is running Limbo version " + Limbo.getInstance().LIMBO_IMPLEMENTATION_VERSION + " (MC: " + Limbo.getInstance().SERVER_IMPLEMENTATION_VERSION + ")"); + } else { + sender.sendMessage(ChatColor.RED + "You do not have permission to use that command!"); + } + return; + } + if (args[0].equalsIgnoreCase("spawn")) { if (sender.hasPermission("limboserver.spawn")) { if (args.length == 1 && sender instanceof Player) { @@ -78,12 +88,10 @@ public void execute(CommandSender sender, String[] args) { if (args.length > 1) { Player player = Limbo.getInstance().getPlayer(args[1]); if (player != null) { - if (args.length >= 2) { - String reasonRaw = String.join(" ", Arrays.copyOfRange(args, 2, args.length)); - if (reasonRaw.trim().length() > 0) { - reason = LegacyComponentSerializer.legacySection().deserialize(reasonRaw); - customReason = true; - } + String reasonRaw = String.join(" ", Arrays.copyOfRange(args, 2, args.length)); + if (reasonRaw.trim().length() > 0) { + reason = LegacyComponentSerializer.legacySection().deserialize(reasonRaw); + customReason = true; } player.disconnect(reason); if (customReason) { diff --git a/src/main/java/com/loohp/limbo/consolegui/GUI.java b/src/main/java/com/loohp/limbo/consolegui/GUI.java index 5719fa8..e29b4e6 100644 --- a/src/main/java/com/loohp/limbo/consolegui/GUI.java +++ b/src/main/java/com/loohp/limbo/consolegui/GUI.java @@ -39,6 +39,8 @@ import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JTextPane; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; import javax.swing.border.EmptyBorder; import com.loohp.limbo.Limbo; @@ -67,7 +69,8 @@ public class GUI extends JFrame { /** * Launch the application. */ - public static void main() { + public static void main() throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); GUI frame = new GUI(); frame.setVisible(true); diff --git a/src/main/java/com/loohp/limbo/consolegui/SystemInfo.java b/src/main/java/com/loohp/limbo/consolegui/SystemInfo.java index 158a849..781e229 100644 --- a/src/main/java/com/loohp/limbo/consolegui/SystemInfo.java +++ b/src/main/java/com/loohp/limbo/consolegui/SystemInfo.java @@ -39,10 +39,10 @@ public static void printInfo() { long allocatedMemory = runtime.totalMemory(); long freeMemory = runtime.freeMemory(); - sb.append("Free Memory: " + format.format(freeMemory / 1024 / 1024) + " MB\n"); - sb.append("Allocated Memory: " + format.format(allocatedMemory / 1024 / 1024) + " MB\n"); - sb.append("Max Memory: " + format.format(maxMemory / 1024 / 1024) + " MB\n"); - sb.append("Memory Usage: " + format.format((allocatedMemory - freeMemory) / 1024 / 1024) + "/" + format.format(maxMemory / 1024 / 1024) + " MB (" + Math.round((double) (allocatedMemory - freeMemory) / (double) (maxMemory) * 100) + "%)\n"); + sb.append("Free Memory: ").append(format.format(freeMemory / 1024 / 1024)).append(" MB\n"); + sb.append("Allocated Memory: ").append(format.format(allocatedMemory / 1024 / 1024)).append(" MB\n"); + sb.append("Max Memory: ").append(format.format(maxMemory / 1024 / 1024)).append(" MB\n"); + sb.append("Memory Usage: ").append(format.format((allocatedMemory - freeMemory) / 1024 / 1024)).append("/").append(format.format(maxMemory / 1024 / 1024)).append(" MB (").append(Math.round((double) (allocatedMemory - freeMemory) / (double) (maxMemory) * 100)).append("%)\n"); sb.append("\n"); try { @@ -54,13 +54,16 @@ public static void printInfo() { double systemLoad = operatingSystemMXBean.getSystemCpuLoad(); int processors = runtime.availableProcessors(); - sb.append("Available Processors: " + processors + "\n"); - sb.append("Process CPU Load: " + Math.round(processLoad * 100) + "%\n"); - sb.append("System CPU Load: " + Math.round(systemLoad * 100) + "%\n"); + sb.append("Available Processors: ").append(processors).append("\n"); + sb.append("Process CPU Load: ").append(Math.round(processLoad * 100)).append("%\n"); + sb.append("System CPU Load: ").append(Math.round(systemLoad * 100)).append("%\n"); GUI.sysText.setText(sb.toString()); } catch (Exception ignore) {} - try {TimeUnit.MILLISECONDS.sleep(1000);} catch (InterruptedException e) {} + try { + TimeUnit.MILLISECONDS.sleep(1000); + } catch (InterruptedException ignored) { + } } } } diff --git a/src/main/java/com/loohp/limbo/events/player/PlayerResourcePackStatusEvent.java b/src/main/java/com/loohp/limbo/events/player/PlayerResourcePackStatusEvent.java index 4e5f92b..c879700 100644 --- a/src/main/java/com/loohp/limbo/events/player/PlayerResourcePackStatusEvent.java +++ b/src/main/java/com/loohp/limbo/events/player/PlayerResourcePackStatusEvent.java @@ -23,17 +23,12 @@ import com.loohp.limbo.player.Player; public class PlayerResourcePackStatusEvent extends PlayerEvent { - - private Player player; + private EnumResourcePackStatus status; public PlayerResourcePackStatusEvent(Player player, EnumResourcePackStatus status) { - super(player); - } - - @Override - public Player getPlayer() { - return player; + super(player); + this.status = status; } public EnumResourcePackStatus getStatus() { diff --git a/src/main/java/com/loohp/limbo/events/player/PluginMessageEvent.java b/src/main/java/com/loohp/limbo/events/player/PluginMessageEvent.java index 8e15a56..69b6b0e 100644 --- a/src/main/java/com/loohp/limbo/events/player/PluginMessageEvent.java +++ b/src/main/java/com/loohp/limbo/events/player/PluginMessageEvent.java @@ -20,7 +20,6 @@ package com.loohp.limbo.events.player; import com.loohp.limbo.player.Player; -import com.loohp.limbo.utils.NamespacedKey; import java.util.Arrays; diff --git a/src/main/java/com/loohp/limbo/file/ServerProperties.java b/src/main/java/com/loohp/limbo/file/ServerProperties.java index b4c0729..c80cddb 100644 --- a/src/main/java/com/loohp/limbo/file/ServerProperties.java +++ b/src/main/java/com/loohp/limbo/file/ServerProperties.java @@ -104,7 +104,7 @@ public ServerProperties(File file) throws IOException { prop.store(pw, COMMENT); pw.close(); - protocol = Limbo.getInstance().serverImplementationProtocol; + protocol = Limbo.getInstance().SERVER_IMPLEMENTATION_PROTOCOL; maxPlayers = Integer.parseInt(prop.getProperty("max-players")); serverPort = Integer.parseInt(prop.getProperty("server-port")); @@ -186,7 +186,7 @@ public ServerProperties(File file) throws IOException { } public String getServerImplementationVersion() { - return Limbo.getInstance().serverImplementationVersion; + return Limbo.getInstance().SERVER_IMPLEMENTATION_VERSION; } public String getServerModName() { diff --git a/src/main/java/com/loohp/limbo/metrics/Metrics.java b/src/main/java/com/loohp/limbo/metrics/Metrics.java index 01d0a54..2961355 100644 --- a/src/main/java/com/loohp/limbo/metrics/Metrics.java +++ b/src/main/java/com/loohp/limbo/metrics/Metrics.java @@ -111,7 +111,7 @@ public Metrics() throws IOException { } } - limboVersion = Limbo.getInstance().limboImplementationVersion; + limboVersion = Limbo.getInstance().LIMBO_IMPLEMENTATION_VERSION; // Load the data serverUUID = config.get("serverUuid", String.class); @@ -137,7 +137,7 @@ public String call() throws Exception { addCustomChart(new Metrics.SimplePie("minecraftVersion", new Callable() { @Override public String call() throws Exception { - return Limbo.getInstance().serverImplementationVersion; + return Limbo.getInstance().SERVER_IMPLEMENTATION_VERSION; } })); } diff --git a/src/main/java/com/loohp/limbo/network/protocol/packets/PacketPlayInPluginMessaging.java b/src/main/java/com/loohp/limbo/network/protocol/packets/PacketPlayInPluginMessaging.java index 6373a5c..8b0282f 100644 --- a/src/main/java/com/loohp/limbo/network/protocol/packets/PacketPlayInPluginMessaging.java +++ b/src/main/java/com/loohp/limbo/network/protocol/packets/PacketPlayInPluginMessaging.java @@ -36,10 +36,10 @@ public PacketPlayInPluginMessaging(String channel, byte[] data) { } public PacketPlayInPluginMessaging(DataInputStream in, int packetLength, int packetId) throws IOException { - String channel = DataTypeIO.readString(in, StandardCharsets.UTF_8); + this.channel = DataTypeIO.readString(in, StandardCharsets.UTF_8); int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getStringLength(channel, StandardCharsets.UTF_8); - data = new byte[dataLength]; - in.readFully(data); + this.data = new byte[dataLength]; + in.readFully(this.data); } public String getChannel() { diff --git a/src/main/resources/permission.yml b/src/main/resources/permission.yml index 1741352..b6b2334 100644 --- a/src/main/resources/permission.yml +++ b/src/main/resources/permission.yml @@ -7,6 +7,7 @@ groups: default: - limboserver.spawn - limboserver.chat + - limboserver.version players: LOOHP: