Skip to content

Commit

Permalink
Fixed PacketPlayInPluginMessaging & Added default command /version
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed May 1, 2022
1 parent 0ac9810 commit effcbab
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 43 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<groupId>com.loohp</groupId>
<artifactId>Limbo</artifactId>
<name>Limbo</name>
<version>0.6.14-ALPHA</version>
<version>0.6.15-ALPHA</version>

<description>Standalone Limbo Minecraft Server.</description>
<url>https://github.com/LOOHP/Limbo</url>
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/com/loohp/limbo/Limbo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
}

Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/com/loohp/limbo/commands/DefaultCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/loohp/limbo/consolegui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/loohp/limbo/consolegui/SystemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/loohp/limbo/file/ServerProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/loohp/limbo/metrics/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -137,7 +137,7 @@ public String call() throws Exception {
addCustomChart(new Metrics.SimplePie("minecraftVersion", new Callable<String>() {
@Override
public String call() throws Exception {
return Limbo.getInstance().serverImplementationVersion;
return Limbo.getInstance().SERVER_IMPLEMENTATION_VERSION;
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/permission.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ groups:
default:
- limboserver.spawn
- limboserver.chat
- limboserver.version

players:
LOOHP:
Expand Down

0 comments on commit effcbab

Please sign in to comment.