Adds some unfinished changes for improving blacksmith commands
This commit is contained in:
parent
e1191dad7d
commit
f3169c9255
@ -35,6 +35,12 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
"individual NPC. If you really want to change this, change it manually.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
//TODO: Display the current value of the setting
|
||||
} else if (args.length == 2 && isSpecialCase(commandName)) {
|
||||
//TODO: Display the current value for the specified setting and material
|
||||
}
|
||||
|
||||
if (isSpecialCase(settings, commandName, args)) {
|
||||
return true;
|
||||
@ -55,6 +61,18 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether a command name matches a special case command
|
||||
*
|
||||
* @param commandName <p>The command specified</p>
|
||||
* @return <p>True if the command is a special case</p>
|
||||
*/
|
||||
private boolean isSpecialCase(String commandName) {
|
||||
return commandName.equalsIgnoreCase(GlobalSetting.BASE_PRICE.getCommandName()) ||
|
||||
commandName.equalsIgnoreCase(GlobalSetting.PRICE_PER_DURABILITY_POINT.getCommandName()) ||
|
||||
commandName.equalsIgnoreCase(GlobalSetting.ENCHANTMENT_COST.getCommandName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the command could be processed as one of the three special cases
|
||||
*
|
||||
|
@ -3,6 +3,7 @@ package net.knarcraft.blacksmith.command;
|
||||
import net.knarcraft.blacksmith.config.GlobalSetting;
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.util.TabCompleteValuesHelper;
|
||||
import net.knarcraft.blacksmith.util.TabCompletionHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@ -34,9 +35,9 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||
availableCommands.add(globalSetting.getCommandName());
|
||||
}
|
||||
return availableCommands;
|
||||
return TabCompletionHelper.filterMatchingContains(availableCommands, args[0]);
|
||||
} else if (args.length == 2) {
|
||||
return tabCompleteCommandValues(args[0]);
|
||||
return tabCompleteCommandValues(args[0], args[1]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -44,18 +45,24 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
||||
/**
|
||||
* Tab completes the values available for the given command
|
||||
*
|
||||
* @param commandName <p>The name of the used command</p>
|
||||
* @param commandName <p>The name of the used command</p>
|
||||
* @param commandValue <p>The command value used to filter tab-completions</p>
|
||||
* @return <p>Some valid options for the command's argument</p>
|
||||
*/
|
||||
private List<String> tabCompleteCommandValues(String commandName) {
|
||||
private List<String> tabCompleteCommandValues(String commandName, String commandValue) {
|
||||
if (commandName.equalsIgnoreCase("reload")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||
if (globalSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
return TabCompleteValuesHelper.getTabCompletions(globalSetting.getValueType());
|
||||
return TabCompletionHelper.filterMatchingContains(TabCompleteValuesHelper.getTabCompletions(
|
||||
globalSetting.getValueType()), commandValue);
|
||||
}
|
||||
}
|
||||
for (NPCSetting npcSetting : NPCSetting.values()) {
|
||||
if (npcSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
return TabCompleteValuesHelper.getTabCompletions(npcSetting.getValueType());
|
||||
return TabCompletionHelper.filterMatchingContains(TabCompleteValuesHelper.getTabCompletions(
|
||||
npcSetting.getValueType()), commandValue);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -2,6 +2,7 @@ package net.knarcraft.blacksmith.command;
|
||||
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.util.TabCompleteValuesHelper;
|
||||
import net.knarcraft.blacksmith.util.TabCompletionHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@ -29,10 +30,10 @@ public class BlackSmithEditTabCompleter implements TabCompleter {
|
||||
if (!sender.hasPermission("blacksmith.edit")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return npcSettings;
|
||||
return TabCompletionHelper.filterMatchingContains(npcSettings, args[0]);
|
||||
} else {
|
||||
if (npcSettings.contains(args[0]) && args.length <= 2) {
|
||||
return tabCompleteCommandValues(args[0]);
|
||||
return tabCompleteCommandValues(args[0], args[1]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@ -42,13 +43,15 @@ public class BlackSmithEditTabCompleter implements TabCompleter {
|
||||
/**
|
||||
* Tab completes the values available for the given command
|
||||
*
|
||||
* @param commandName <p>The name of the used command</p>
|
||||
* @param commandName <p>The name of the used command</p>
|
||||
* @param commandValue <p>The command value used to filter tab-completions</p>
|
||||
* @return <p>Some valid options for the command's argument</p>
|
||||
*/
|
||||
private List<String> tabCompleteCommandValues(String commandName) {
|
||||
private List<String> tabCompleteCommandValues(String commandName, String commandValue) {
|
||||
for (NPCSetting npcSetting : NPCSetting.values()) {
|
||||
if (npcSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
return TabCompleteValuesHelper.getTabCompletions(npcSetting.getValueType());
|
||||
return TabCompletionHelper.filterMatchingContains(TabCompleteValuesHelper.getTabCompletions(
|
||||
npcSetting.getValueType()), commandValue);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -0,0 +1,32 @@
|
||||
package net.knarcraft.blacksmith.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A helper class for tab complation
|
||||
*/
|
||||
public final class TabCompletionHelper {
|
||||
|
||||
private TabCompletionHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds tab complete values that contain the typed text
|
||||
*
|
||||
* @param values <p>The values to filter</p>
|
||||
* @param typedText <p>The text the player has started typing</p>
|
||||
* @return <p>The given string values that contain the player's typed text</p>
|
||||
*/
|
||||
public static List<String> filterMatchingContains(List<String> values, String typedText) {
|
||||
List<String> configValues = new ArrayList<>();
|
||||
for (String value : values) {
|
||||
if (value.toLowerCase().contains(typedText.toLowerCase())) {
|
||||
configValues.add(value);
|
||||
}
|
||||
}
|
||||
return configValues;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user