Adjusts output of blacksmith setting messages
This commit is contained in:
parent
1dea0f6c6a
commit
755db8c497
@ -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
|
||||
|
@ -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<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
List<String> npcSettings = new ArrayList<>();
|
||||
for (NPCSetting setting : NPCSetting.values()) {
|
||||
npcSettings.add(setting.getCommandName());
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
if (!sender.hasPermission("blacksmith.admin")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<String> availableCommands = new ArrayList<>();
|
||||
for (NPCSetting setting : NPCSetting.values()) {
|
||||
availableCommands.add(setting.getCommandName());
|
||||
}
|
||||
List<String> 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<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<String> 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;
|
||||
}
|
||||
|
||||
}
|
@ -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<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@ -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 <p>The name of this configuration node</p>
|
||||
*/
|
||||
public String getNodeName() {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user