Skip to content

Commit

Permalink
[1.4.3]更改命令注册方式
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Nov 12, 2023
1 parent 18685e9 commit a1a3fe7
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void enable() {

ItemManager.loadItemManager();
RecipeManager.loadRecipeManager();
regCommands();
regListeners();
PluginHookUtil.hookPlugins();
initArcenciel();
Expand Down Expand Up @@ -75,11 +74,6 @@ private void loadBStat() {
metrics.addCustomChart(new Metrics.SingleLineChart("recipes", () -> RecipeManager.getRecipeFileMap().keySet().size()));
}

private void regCommands() {
Bukkit.getPluginCommand("craftorithm").setExecutor(PluginCommand.INSTANCE);
Bukkit.getPluginCommand("craftorithm").setTabCompleter(PluginCommand.INSTANCE);
}

private void regListeners() {
Bukkit.getPluginManager().registerEvents(CraftHandler.INSTANCE, this);
Bukkit.getPluginManager().registerEvents(this, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum PluginCommand implements IPluginCmdExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
List<String> argList = Arrays.asList(args);
if (argList.size() < 1) {
if (argList.isEmpty()) {
LangUtil.sendMsg(sender, "command.not_enough_param", ContainerUtil.newHashMap("<number>", String.valueOf(1)));
return true;
}
Expand Down Expand Up @@ -74,30 +74,4 @@ public Plugin getPlugin() {
return null;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> argList = Arrays.asList(args);
if (argList.size() <= 1) {
List<String> tabList = new ArrayList<>();
for (String subCmd : subCommandMap.keySet()) {
ISubCmdExecutor subCommand = subCommandMap.get(subCmd);
if (sender.hasPermission(subCommand.permission()))
tabList.add(subCmd);
}
tabList.removeIf(str -> !str.startsWith(args[0]));
return tabList;
}
ISubCmdExecutor subCommand = subCommandMap.get(argList.get(0));
if (subCommand != null) {
if (!sender.hasPermission(subCommand.permission()))
return Collections.singletonList("");
return subCommand.onTabComplete(sender, argList.subList(1, argList.size()));
}
else
return Collections.singletonList("");
}




}
5 changes: 0 additions & 5 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ softdepend: [ Vault, LuckPerms, PlayerPoints, PlaceholderAPI, ItemsAdder, Oraxen
authors: [ YufiriaMazenta ]
folia-supported: true
website: https://github.com/YufiriaMazenta/Craftorithm
commands:
craftorithm:
aliases:
- craft
permission: craftorithm.command
permissions:
craftorithm.command:
description: Plugin command main permissions
Expand Down

0 comments on commit a1a3fe7

Please sign in to comment.