GUI Improvements (#1462)

- Added `GeyserCommand.isExecutableOnConsole()`. If this is set to false, the command will not appear as an option in the GUI.
- Added `GeyserCommand.getSubCommands()`. If not empty, the subcommand options will now appear in the GUI.
This commit is contained in:
Camotoy 2020-10-27 18:40:00 -04:00 committed by GitHub
parent 04f0318bd0
commit a2a7e99402
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 8 deletions

1
.gitignore vendored
View file

@ -243,3 +243,4 @@ public-key.pem
locales/
/cache/
/packs/
/dump.json

View file

@ -261,14 +261,30 @@ public class GeyserStandaloneGUI {
for (Map.Entry<String, GeyserCommand> 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<String> row = new Vector<>();
row.add(player.getSocketAddress().getHostName());
row.add(player.getPlayerEntity().getUsername());

View file

@ -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<String> 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<String> 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();
}
}

View file

@ -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<String> getSubCommands() {
return Arrays.asList("offline", "full");
}
}

View file

@ -68,4 +68,9 @@ public class OffhandCommand extends GeyserCommand {
}
}
}
@Override
public boolean isExecutableOnConsole() {
return false;
}
}

View file

@ -66,4 +66,9 @@ public class StatisticsCommand extends GeyserCommand {
ClientRequestPacket clientRequestPacket = new ClientRequestPacket(ClientRequest.STATS);
session.sendDownstreamPacket(clientRequestPacket);
}
@Override
public boolean isExecutableOnConsole() {
return false;
}
}