diff --git a/.gitignore b/.gitignore index e3c3b0a56..85f8a6e9e 100644 --- a/.gitignore +++ b/.gitignore @@ -242,4 +242,5 @@ logs/ public-key.pem locales/ /cache/ -/packs/ \ No newline at end of file +/packs/ +/dump.json \ No newline at end of file diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GeyserStandaloneGUI.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GeyserStandaloneGUI.java index 50deeb1bc..aeee84624 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GeyserStandaloneGUI.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GeyserStandaloneGUI.java @@ -261,14 +261,30 @@ public class GeyserStandaloneGUI { for (Map.Entry command : geyserCommandManager.getCommands().entrySet()) { // Remove the offhand command and any alias commands to prevent duplicates in the list - if ("offhand".equals(command.getValue().getName()) || command.getValue().getAliases().contains(command.getKey())) { + if (!command.getValue().isExecutableOnConsole() || command.getValue().getAliases().contains(command.getKey())) { continue; } // Create the button that runs the command - JMenuItem commandButton = new JMenuItem(command.getValue().getName()); + boolean hasSubCommands = command.getValue().hasSubCommands(); + // Add an extra menu if there are more commands that can be run + JMenuItem commandButton = hasSubCommands ? new JMenu(command.getValue().getName()) : new JMenuItem(command.getValue().getName()); commandButton.getAccessibleContext().setAccessibleDescription(command.getValue().getDescription()); - commandButton.addActionListener(e -> command.getValue().execute(geyserStandaloneLogger, new String[]{ })); + if (!hasSubCommands) { + commandButton.addActionListener(e -> command.getValue().execute(geyserStandaloneLogger, new String[]{ })); + } else { + // Add a submenu that's the same name as the menu can't be pressed + JMenuItem otherCommandButton = new JMenuItem(command.getValue().getName()); + otherCommandButton.getAccessibleContext().setAccessibleDescription(command.getValue().getDescription()); + otherCommandButton.addActionListener(e -> command.getValue().execute(geyserStandaloneLogger, new String[]{ })); + commandButton.add(otherCommandButton); + // Add a menu option for all possible subcommands + for (String subCommandName : command.getValue().getSubCommands()) { + JMenuItem item = new JMenuItem(subCommandName); + item.addActionListener(e -> command.getValue().execute(geyserStandaloneLogger, new String[]{subCommandName})); + commandButton.add(item); + } + } commandsMenu.add(commandButton); } @@ -291,7 +307,7 @@ public class GeyserStandaloneGUI { playerTableModel.getDataVector().removeAllElements(); for (GeyserSession player : GeyserConnector.getInstance().getPlayers()) { - Vector row = new Vector(); + Vector row = new Vector<>(); row.add(player.getSocketAddress().getHostName()); row.add(player.getPlayerEntity().getUsername()); diff --git a/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java b/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java index 62bc6c73f..2bb8893cb 100644 --- a/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java @@ -30,6 +30,7 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import java.util.ArrayList; +import java.util.Collections; import java.util.List; @Getter @@ -44,4 +45,31 @@ public abstract class GeyserCommand { private List aliases = new ArrayList<>(); public abstract void execute(CommandSender sender, String[] args); + + /** + * If false, hides the command from being shown on the Geyser Standalone GUI. + * + * @return true if the command can be run on the server console + */ + public boolean isExecutableOnConsole() { + return true; + } + + /** + * Used in the GUI to know what subcommands can be run + * + * @return a list of all possible subcommands, or empty if none. + */ + public List getSubCommands() { + return Collections.emptyList(); + } + + /** + * Shortcut to {@link #getSubCommands()}{@code .isEmpty()}. + * + * @return true if there are subcommand present for this command. + */ + public boolean hasSubCommands() { + return !getSubCommands().isEmpty(); + } } \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/DumpCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/DumpCommand.java index 9ad0d23dd..9103755a9 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/DumpCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/DumpCommand.java @@ -27,12 +27,10 @@ package org.geysermc.connector.command.defaults; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; -import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; -import org.geysermc.connector.common.ChatColor; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.command.GeyserCommand; +import org.geysermc.connector.common.ChatColor; import org.geysermc.connector.common.serializer.AsteriskSerializer; import org.geysermc.connector.dump.DumpInfo; import org.geysermc.connector.utils.LanguageUtils; @@ -40,6 +38,8 @@ import org.geysermc.connector.utils.WebUtils; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Arrays; +import java.util.List; public class DumpCommand extends GeyserCommand { @@ -130,4 +130,9 @@ public class DumpCommand extends GeyserCommand { connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.commands.dump.created", sender.getName(), uploadedDumpUrl)); } } + + @Override + public List getSubCommands() { + return Arrays.asList("offline", "full"); + } } diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/OffhandCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/OffhandCommand.java index b1b601328..d5e0a7927 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/OffhandCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/OffhandCommand.java @@ -68,4 +68,9 @@ public class OffhandCommand extends GeyserCommand { } } } + + @Override + public boolean isExecutableOnConsole() { + return false; + } } diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/StatisticsCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/StatisticsCommand.java index ed9db58f5..52379145a 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/StatisticsCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/StatisticsCommand.java @@ -66,4 +66,9 @@ public class StatisticsCommand extends GeyserCommand { ClientRequestPacket clientRequestPacket = new ClientRequestPacket(ClientRequest.STATS); session.sendDownstreamPacket(clientRequestPacket); } + + @Override + public boolean isExecutableOnConsole() { + return false; + } }