Simplify command executor assignment a little more

This commit is contained in:
Jikoo 2020-11-15 12:26:36 -05:00
parent f45d332727
commit 45de495699
No known key found for this signature in database
GPG key ID: 37FF68B07F639098

View file

@ -352,17 +352,11 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
pm.registerEvents(new InventoryListener(this), this); pm.registerEvents(new InventoryListener(this), this);
// Register commands to their executors // Register commands to their executors
OpenInvCommand openInv = new OpenInvCommand(this); this.setCommandExecutor(new OpenInvCommand(this), "openinv", "openender");
this.setCommandExecutor("openinv", openInv); this.setCommandExecutor(new SearchContainerCommand(this), "searchcontainer");
this.setCommandExecutor("openender", openInv); this.setCommandExecutor(new SearchInvCommand(this), "searchinv", "searchender");
this.setCommandExecutor("searchcontainer", new SearchContainerCommand(this)); this.setCommandExecutor(new SearchEnchantCommand(this), "searchenchant");
SearchInvCommand searchInv = new SearchInvCommand(this); this.setCommandExecutor(new ContainerSettingCommand(this), "silentcontainer", "anycontainer");
this.setCommandExecutor("searchinv", searchInv);
this.setCommandExecutor("searchender", searchInv);
this.setCommandExecutor("searchenchant", new SearchEnchantCommand(this));
ContainerSettingCommand settingCommand = new ContainerSettingCommand(this);
this.setCommandExecutor("silentcontainer", settingCommand);
this.setCommandExecutor("anycontainer", settingCommand);
} else { } else {
this.sendVersionError(this.getLogger()::warning); this.sendVersionError(this.getLogger()::warning);
@ -375,10 +369,12 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
messageMethod.accept("Please obtain an appropriate version here: " + accessor.getReleasesLink()); messageMethod.accept("Please obtain an appropriate version here: " + accessor.getReleasesLink());
} }
private void setCommandExecutor(String commandName, CommandExecutor executor) { private void setCommandExecutor(CommandExecutor executor, String... commands) {
PluginCommand command = this.getCommand(commandName); for (String commandName : commands) {
if (command != null) { PluginCommand command = this.getCommand(commandName);
command.setExecutor(executor); if (command != null) {
command.setExecutor(executor);
}
} }
} }