command register relogic
This commit is contained in:
parent
265000e775
commit
759802b586
20
build.gradle
20
build.gradle
@ -12,26 +12,6 @@ spigot {
|
||||
main "ru.themixray.puton.Main"
|
||||
apiVersion "1.17"
|
||||
named "PutOn"
|
||||
|
||||
command {
|
||||
named "helmet"
|
||||
description "Puts on item from your hand as helmet"
|
||||
}
|
||||
|
||||
command {
|
||||
named "chestplate"
|
||||
description "Puts on item from your hand as chestplate"
|
||||
}
|
||||
|
||||
command {
|
||||
named "leggings"
|
||||
description "Puts on item from your hand as leggings"
|
||||
}
|
||||
|
||||
command {
|
||||
named "boots"
|
||||
description "Puts on item from your hand as boots"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package ru.themixray.puton;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import ru.themixray.puton.command.BootsCommand;
|
||||
@ -18,10 +19,10 @@ public final class Main extends JavaPlugin implements Listener {
|
||||
public void onEnable() {
|
||||
Config.loadConfig(new UnrealConfig(this, getDataFolder(), "config.yml"));
|
||||
Bukkit.getPluginManager().registerEvents(new SwapItemListener(), this);
|
||||
registerCommand(getCommand("helmet"), Config.HELMET_COMMANDS, new HelmetCommand());
|
||||
registerCommand(getCommand("chestplate"), Config.CHESTPLATE_COMMANDS, new ChestplateCommand());
|
||||
registerCommand(getCommand("leggings"), Config.LEGGINGS_COMMANDS, new LeggingsCommand());
|
||||
registerCommand(getCommand("boots"), Config.BOOTS_COMMANDS, new BootsCommand());
|
||||
registerCommand(Config.HELMET_COMMANDS, "Puts on item from your hand as helmet", new HelmetCommand());
|
||||
registerCommand(Config.CHESTPLATE_COMMANDS, "Puts on item from your hand as chestplate", new ChestplateCommand());
|
||||
registerCommand(Config.LEGGINGS_COMMANDS, "Puts on item from your hand as leggings", new LeggingsCommand());
|
||||
registerCommand(Config.BOOTS_COMMANDS, "Puts on item from your hand as boots", new BootsCommand());
|
||||
}
|
||||
|
||||
public CommandMap getCommandMap() {
|
||||
@ -34,14 +35,26 @@ public final class Main extends JavaPlugin implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public void registerCommand(PluginCommand command, List<String> names, CommandExecutor executor) {
|
||||
public void registerCommand(List<String> names, String description, CommandExecutor executor) {
|
||||
if (names.isEmpty()) {
|
||||
command.unregister(getCommandMap());
|
||||
return;
|
||||
}
|
||||
command.setExecutor(executor);
|
||||
command.setName(names.get(0));
|
||||
if (names.size() > 1) command.setAliases(names.subList(1, names.size()));
|
||||
command.setTabCompleter((a, b, c, d) -> List.of());
|
||||
BukkitCommand command = new BukkitCommand(
|
||||
names.get(0),
|
||||
description,
|
||||
"/"+names.get(0),
|
||||
names.subList(1, names.size())
|
||||
) {
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String alias, String[] args) {
|
||||
return executor.onCommand(sender, this, alias, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender a, String b, String[] c) throws IllegalArgumentException {
|
||||
return List.of();
|
||||
}
|
||||
};
|
||||
getCommandMap().register(names.get(0), command);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user