mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 16:39:36 +00:00
1.7 Partially Prepared Products
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package net.momirealms.customcrops.commands;
|
||||
|
||||
import net.momirealms.customcrops.commands.subcmd.ReloadCommand;
|
||||
import net.momirealms.customcrops.commands.subcmd.SetSeasonCommand;
|
||||
import net.momirealms.customcrops.config.MessageConfig;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PluginCommand implements TabExecutor {
|
||||
|
||||
private final Map<String, SubCommand> subCommandMap;
|
||||
|
||||
public PluginCommand() {
|
||||
subCommandMap = new ConcurrentHashMap<>();
|
||||
regDefaultSubCommands();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
List<String> argList = Arrays.asList(args);
|
||||
if (argList.size() < 1) {
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.nonArgs);
|
||||
return true;
|
||||
}
|
||||
SubCommand subCommand = subCommandMap.get(argList.get(0));
|
||||
if (subCommand != null)
|
||||
return subCommand.onCommand(sender, argList.subList(1, argList.size()));
|
||||
else {
|
||||
AdventureUtil.sendMessage(sender, MessageConfig.unavailableArgs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void regDefaultSubCommands() {
|
||||
regSubCommand(ReloadCommand.INSTANCE);
|
||||
regSubCommand(SetSeasonCommand.INSTANCE);
|
||||
}
|
||||
|
||||
public void regSubCommand(SubCommand executor) {
|
||||
subCommandMap.put(executor.getSubCommand(), executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
List<String> argList = Arrays.asList(args);
|
||||
if (argList.size() <= 1) {
|
||||
List<String> returnList = new ArrayList<>(subCommandMap.keySet());
|
||||
returnList.removeIf(str -> !str.startsWith(args[0]));
|
||||
return returnList;
|
||||
}
|
||||
SubCommand subCommand = subCommandMap.get(argList.get(0));
|
||||
if (subCommand != null)
|
||||
return subCommand.onTabComplete(sender, argList.subList(1, argList.size()));
|
||||
else
|
||||
return Collections.singletonList("");
|
||||
}
|
||||
|
||||
public Map<String, SubCommand> getSubCommandMap() {
|
||||
return subCommandMap;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user