Splits the blacksmith command into two commands, and much more
This commit is contained in:
@ -0,0 +1,64 @@
|
||||
package net.knarcraft.blacksmith.command;
|
||||
|
||||
import net.knarcraft.blacksmith.config.GlobalSetting;
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.util.TabCompleteValuesHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The tab completer for the command used for changing global configuration options
|
||||
*/
|
||||
public class BlackSmithConfigTabCompleter implements TabCompleter {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
if (!sender.hasPermission("blacksmith.admin")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<String> availableCommands = new ArrayList<>();
|
||||
availableCommands.add("reload");
|
||||
for (NPCSetting setting : NPCSetting.values()) {
|
||||
availableCommands.add(setting.getCommandName());
|
||||
}
|
||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||
availableCommands.add(globalSetting.getCommandName());
|
||||
}
|
||||
return availableCommands;
|
||||
} else if (args.length == 2) {
|
||||
return tabCompleteCommandValues(args[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tab completes the values available for the given command
|
||||
*
|
||||
* @param commandName <p>The name of the used command</p>
|
||||
* @return <p>Some valid options for the command's argument</p>
|
||||
*/
|
||||
private List<String> tabCompleteCommandValues(String commandName) {
|
||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||
if (globalSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
return TabCompleteValuesHelper.getTabCompletions(globalSetting.getValueType());
|
||||
}
|
||||
}
|
||||
for (NPCSetting npcSetting : NPCSetting.values()) {
|
||||
if (npcSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
return TabCompleteValuesHelper.getTabCompletions(npcSetting.getValueType());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user