Attempt to intercept native commands

This commit is contained in:
Paul Reilly 2023-04-10 01:27:30 -05:00
parent 33ac3a36ca
commit 6c0856d647
2 changed files with 18 additions and 2 deletions

View File

@ -161,8 +161,7 @@ public class TotalFreedomMod extends JavaPlugin
} }
cl = new CommandLoader(); cl = new CommandLoader();
Bukkit.getScheduler().runTaskLater(plugin, cl::loadCommands, 1); cl.loadCommands();
// Deferring command loading allowing TFD4J and Shop to load before registering our commands.
BackupManager backups = new BackupManager(); BackupManager backups = new BackupManager();
backups.createAllBackups(); backups.createAllBackups();

View File

@ -31,6 +31,13 @@ public class Interceptor
.getName() .getName()
.equalsIgnoreCase(command)) .equalsIgnoreCase(command))
.forEach(entry -> overrides.put(entry.getKey(), entry.getValue())); // Intercept. .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() public void setOverrides()
@ -42,6 +49,16 @@ public class Interceptor
}); });
} }
private Map<String, Command> getFallbackCommands() {
final Map<String, Command> fallbackCommands = new HashMap<>();
for (final Map.Entry<String, Command> entry : Bukkit.getCommandMap().getKnownCommands().entrySet()) {
if (!(entry.getValue() instanceof PluginIdentifiableCommand)) {
fallbackCommands.put(entry.getKey(), entry.getValue());
}
}
return fallbackCommands;
}
private Map<String, Command> getPluginCommands() private Map<String, Command> getPluginCommands()
{ {
final Map<String, Command> pluginCommands = new HashMap<>(); final Map<String, Command> pluginCommands = new HashMap<>();