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

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,12 +369,14 @@ 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) {
for (String commandName : commands) {
PluginCommand command = this.getCommand(commandName); PluginCommand command = this.getCommand(commandName);
if (command != null) { if (command != null) {
command.setExecutor(executor); command.setExecutor(executor);
} }
} }
}
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {