Skip to content

Commit

Permalink
Commands can be hidden from being logged in console now (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMasrozYTLIVE authored Jul 29, 2023
1 parent 48ec986 commit 0a8d752
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/net/minecraft/server/NetServerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/bukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,26 @@ public interface Server {
* @return Set containing banned players
*/
public Set<OfflinePlayer> 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<String> commands);
}
19 changes: 19 additions & 0 deletions src/main/java/org/bukkit/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>());
Expand Down Expand Up @@ -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;
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/bukkit/command/PluginCommandYamlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public static List<Command> 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());
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/bukkit/craftbukkit/CraftServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> hiddenCommands = new ArrayList<>(); //Project Poseidon - Create variable

public CraftServer(MinecraftServer console, ServerConfigurationManager server) {
this.console = console;
Expand All @@ -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() {
Expand Down Expand Up @@ -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<String> commands) {
for(String cmd : commands) {
addHiddenCommand(cmd);
}
}

// public GameMode getDefaultGameMode() {
// return GameMode.SURVIVAL;
// }
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/bukkit/plugin/SimplePluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0a8d752

Please sign in to comment.