From 6c0856d64741ab69efa6f231fe282422a0d4f19e Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Mon, 10 Apr 2023 01:27:30 -0500 Subject: [PATCH] Attempt to intercept native commands --- .../totalfreedommod/TotalFreedomMod.java | 3 +-- .../command/handling/Interceptor.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 041a426b..7a4d20f0 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -161,8 +161,7 @@ public class TotalFreedomMod extends JavaPlugin } cl = new CommandLoader(); - Bukkit.getScheduler().runTaskLater(plugin, cl::loadCommands, 1); - // Deferring command loading allowing TFD4J and Shop to load before registering our commands. + cl.loadCommands(); BackupManager backups = new BackupManager(); backups.createAllBackups(); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/Interceptor.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/Interceptor.java index fbdd2c47..f43a60a1 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/Interceptor.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/handling/Interceptor.java @@ -31,6 +31,13 @@ public class Interceptor .getName() .equalsIgnoreCase(command)) .forEach(entry -> overrides.put(entry.getKey(), entry.getValue())); // Intercept. + + getFallbackCommands().entrySet() + .stream() + .filter(entry -> entry.getValue() // Check that the command is the one we want to intercept + .getName() + .equalsIgnoreCase(command)) + .forEach(entry -> overrides.put(entry.getKey(), entry.getValue())); // Intercept. } public void setOverrides() @@ -42,6 +49,16 @@ public class Interceptor }); } + private Map getFallbackCommands() { + final Map fallbackCommands = new HashMap<>(); + for (final Map.Entry entry : Bukkit.getCommandMap().getKnownCommands().entrySet()) { + if (!(entry.getValue() instanceof PluginIdentifiableCommand)) { + fallbackCommands.put(entry.getKey(), entry.getValue()); + } + } + return fallbackCommands; + } + private Map getPluginCommands() { final Map pluginCommands = new HashMap<>();