From 0a8d752c24852172951821410f792b19b56ee959 Mon Sep 17 00:00:00 2001 From: "Andrey (MiTask)" <61359286+MrMasrozYTLIVE@users.noreply.github.com> Date: Sat, 29 Jul 2023 11:56:13 +0300 Subject: [PATCH] Commands can be hidden from being logged in console now (#73) --- .../minecraft/server/NetServerHandler.java | 6 +++-- src/main/java/org/bukkit/Server.java | 22 ++++++++++++++++ src/main/java/org/bukkit/command/Command.java | 19 ++++++++++++++ .../command/PluginCommandYamlParser.java | 5 ++++ .../org/bukkit/craftbukkit/CraftServer.java | 26 +++++++++++++++++++ .../bukkit/plugin/SimplePluginManager.java | 7 +++++ 6 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java index e6c9fa88..862a224c 100644 --- a/src/main/java/net/minecraft/server/NetServerHandler.java +++ b/src/main/java/net/minecraft/server/NetServerHandler.java @@ -846,8 +846,10 @@ private void handleCommand(String s) { try { if (this.server.dispatchCommand(player, s.substring(1))) { //Project Poseidon Start - //Basic XAuth & Authme Firewall - if (s.toLowerCase().startsWith("/register") || s.toLowerCase().startsWith("/login") || s.toLowerCase().startsWith("/changepw") || s.toLowerCase().startsWith("/changepassword") || s.toLowerCase().startsWith("/unregister")) { + //Hide commands from being logged in console + String cmdName = s.split(" ")[0].replaceAll("/", ""); + + if (server.isCommandHidden(cmdName)) { a.info(player.getName() + " issued server command: COMMAND REDACTED"); } else { a.info(player.getName() + " issued server command: " + s); diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java index c6e1cd88..427fb3da 100644 --- a/src/main/java/org/bukkit/Server.java +++ b/src/main/java/org/bukkit/Server.java @@ -467,4 +467,26 @@ public interface Server { * @return Set containing banned players */ public Set getBannedPlayers(); + + /** + * Returns the current hide state of the command from param (Hide from console) + * + * @param cmdName Command name + * @return True if the command from param is hidden and false otherwise + */ + public boolean isCommandHidden(String cmdName); + + /** + * Hides the command from param from being logged to server console + * + * @param cmd Command name + */ + public void addHiddenCommand(String cmd); + + /** + * Hides the commands from param from being logged to server console + * + * @param commands List of command names + */ + public void addHiddenCommands(List commands); } diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java index e0e7b3aa..3a537d5e 100644 --- a/src/main/java/org/bukkit/command/Command.java +++ b/src/main/java/org/bukkit/command/Command.java @@ -22,6 +22,7 @@ public abstract class Command { protected String description = ""; protected String usageMessage; private String permission; + private boolean isHidden; protected Command(String name) { this(name, "", "/" + name, new ArrayList()); @@ -247,4 +248,22 @@ public static void broadcastCommandMessage(CommandSender source, String message) } } } + + /** + * Returns the current hide state of this command (Hide from console) + * + * @return True if the current command is hidden and false otherwise + */ + public boolean isHidden() { + return isHidden; + } + + /** + * Sets the current hide state of this command (Hide from console) + * + * @param hidden New hide state of this command + */ + public void setHidden(boolean hidden) { + isHidden = hidden; + } } diff --git a/src/main/java/org/bukkit/command/PluginCommandYamlParser.java b/src/main/java/org/bukkit/command/PluginCommandYamlParser.java index c735e1b5..76b1eb86 100644 --- a/src/main/java/org/bukkit/command/PluginCommandYamlParser.java +++ b/src/main/java/org/bukkit/command/PluginCommandYamlParser.java @@ -27,6 +27,11 @@ public static List parse(Plugin plugin) { Object usage = entry.getValue().get("usage"); Object aliases = entry.getValue().get("aliases"); Object permission = entry.getValue().get("permission"); + Object isHidden = entry.getValue().get("hidden"); + + if(isHidden != null) { + newCmd.setHidden(String.valueOf(isHidden).equalsIgnoreCase("true")); + } if (description != null) { newCmd.setDescription(description.toString()); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index d541ca10..5372141e 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -69,6 +69,7 @@ public final class CraftServer implements Server { private final Configuration configuration; private final Yaml yaml = new Yaml(new SafeConstructor()); private boolean shuttingdown = false; + private final List hiddenCommands = new ArrayList<>(); //Project Poseidon - Create variable public CraftServer(MinecraftServer console, ServerConfigurationManager server) { this.console = console; @@ -83,6 +84,10 @@ public CraftServer(MinecraftServer console, ServerConfigurationManager server) { enablePlugins(PluginLoadOrder.STARTUP); ChunkCompressionThread.startThread(); + + // Project Poseidon start + addHiddenCommands(Arrays.asList("login", "l", "register", "reg", "unregister", "changepassword", "changepw")); + // Project Poseidon end } private void loadConfig() { @@ -849,6 +854,27 @@ public void setShuttingdown(boolean shuttingdown) { this.shuttingdown = shuttingdown; } + public boolean isCommandHidden(String cmdName) { + return hiddenCommands.contains(cmdName.toLowerCase()); + } + + public void addHiddenCommand(String cmd) { + cmd = cmd.toLowerCase(); + + if(hiddenCommands.contains(cmd)) { + Logger.getLogger(NetServerHandler.class.getName()).warning("List of Hidden commands already contains " + cmd); + return; + } + + hiddenCommands.add(cmd); + } + + public void addHiddenCommands(List commands) { + for(String cmd : commands) { + addHiddenCommand(cmd); + } + } + // public GameMode getDefaultGameMode() { // return GameMode.SURVIVAL; // } diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java index 9e125e09..22a31dee 100644 --- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -289,6 +289,13 @@ public void enablePlugin(final Plugin plugin) { if (!pluginCommands.isEmpty()) { commandMap.registerAll(plugin.getDescription().getName(), pluginCommands); + + for(Command c : pluginCommands) { + if(c.isHidden()) { + server.addHiddenCommand(c.getLabel()); + server.addHiddenCommands(c.getAliases()); + } + } } try {