diff --git a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithCommand.java b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithCommand.java index 0a491ee..3bee842 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithCommand.java +++ b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithCommand.java @@ -6,6 +6,9 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +/** + * The main command used for everything blacksmith related + */ public class BlackSmithCommand implements CommandExecutor { @Override diff --git a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithTabCompleter.java b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithTabCompleter.java index f266a62..9fac692 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/BlackSmithTabCompleter.java +++ b/src/main/java/net/knarcraft/blacksmith/command/BlackSmithTabCompleter.java @@ -10,22 +10,35 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +/** + * The tab completer for the main blacksmith command + */ public class BlackSmithTabCompleter implements TabCompleter { @Nullable @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (!sender.hasPermission("blacksmith.admin")) { - return new ArrayList<>(); + List npcSettings = new ArrayList<>(); + for (NPCSetting setting : NPCSetting.values()) { + npcSettings.add(setting.getCommandName()); } - List availableCommands = new ArrayList<>(); - for (NPCSetting setting : NPCSetting.values()) { - availableCommands.add(setting.getCommandName()); + if (args.length == 1) { + if (!sender.hasPermission("blacksmith.admin")) { + return new ArrayList<>(); + } + + List availableCommands = new ArrayList<>(npcSettings); + availableCommands.add("reload"); + return availableCommands; + } else { + if (npcSettings.contains(args[0])) { + return new NPCSettingTabCompleter().onTabComplete(sender, command, label, args); + } else { + return new ArrayList<>(); + } } - availableCommands.add("reload"); - return availableCommands; } } diff --git a/src/main/java/net/knarcraft/blacksmith/command/NPCSettingCommand.java b/src/main/java/net/knarcraft/blacksmith/command/NPCSettingCommand.java index 3e32fea..af1cab6 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/NPCSettingCommand.java +++ b/src/main/java/net/knarcraft/blacksmith/command/NPCSettingCommand.java @@ -4,12 +4,15 @@ import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.npc.NPC; import net.knarcraft.blacksmith.config.NPCSetting; import net.knarcraft.blacksmith.trait.BlacksmithTrait; -import org.bukkit.ChatColor; +import net.md_5.bungee.api.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +/** + * A class to perform everything related to changing a blacksmith's options + */ public class NPCSettingCommand implements CommandExecutor { @Override @@ -26,10 +29,11 @@ public class NPCSettingCommand implements CommandExecutor { if (commandName.equalsIgnoreCase(args[0])) { if (args.length < 2) { sender.sendMessage(ChatColor.GREEN + "Current value of " + commandName + ": " + - blacksmithTrait.getSettings().getRawValue(npcSetting)); + ChatColor.GOLD + blacksmithTrait.getSettings().getRawValue(npcSetting)); } else { - blacksmithTrait.getSettings().changeSetting(npcSetting, args[1]); - sender.sendMessage(ChatColor.GREEN + npcSetting.name() + " set to " + args[1]); + blacksmithTrait.getSettings().changeSetting(npcSetting, + ChatColor.translateAlternateColorCodes('&', args[1])); + sender.sendMessage(ChatColor.GREEN + npcSetting.getNodeName() + " set to " + ChatColor.GOLD + args[1]); } return true; } diff --git a/src/main/java/net/knarcraft/blacksmith/command/NPCSettingTabCompleter.java b/src/main/java/net/knarcraft/blacksmith/command/NPCSettingTabCompleter.java new file mode 100644 index 0000000..be1f0cb --- /dev/null +++ b/src/main/java/net/knarcraft/blacksmith/command/NPCSettingTabCompleter.java @@ -0,0 +1,24 @@ +package net.knarcraft.blacksmith.command; + +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.List; + +/** + * The tab completer for the NPC setting command + */ +public class NPCSettingTabCompleter implements TabCompleter { + + @Nullable + @Override + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, + @NotNull String[] args) { + //TODO: Add tab completions based on each setting's type + return null; + } + +} diff --git a/src/main/java/net/knarcraft/blacksmith/command/ReloadCommand.java b/src/main/java/net/knarcraft/blacksmith/command/ReloadCommand.java index 4f6613a..20e87fc 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/ReloadCommand.java +++ b/src/main/java/net/knarcraft/blacksmith/command/ReloadCommand.java @@ -11,10 +11,14 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +/** + * The command for re-loading the plugin + */ public class ReloadCommand implements TabExecutor { @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) { BlacksmithPlugin.getInstance().reload(); sender.sendMessage(ChatColor.GREEN + "Blacksmith config reloaded!"); return true; @@ -22,7 +26,8 @@ public class ReloadCommand implements TabExecutor { @Nullable @Override - public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, + @NotNull String[] args) { return new ArrayList<>(); } diff --git a/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java b/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java index cb8f1b4..44ac759 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/NPCSetting.java @@ -47,6 +47,7 @@ public enum NPCSetting { private final String childPath; private final Object value; private final String commandName; + private final String nodeName; /** * Instantiates a new setting @@ -61,6 +62,11 @@ public enum NPCSetting { String[] pathParts = path.split("\\."); this.childPath = String.join(".", Arrays.copyOfRange(pathParts, 1, pathParts.length)); this.commandName = commandName; + if (pathParts.length > 0) { + this.nodeName = pathParts[pathParts.length - 1]; + } else { + this.nodeName = ""; + } } /** @@ -99,4 +105,13 @@ public enum NPCSetting { return commandName; } + /** + * Gets the name of this configuration node + * + * @return

The name of this configuration node

+ */ + public String getNodeName() { + return nodeName; + } + }