Fixes several bugs and problems
Fixes getting the name of enchantments Fixes inconsistencies in material and enchantment name-checking Allows using "null" or "-1" to unset per-material or per-enchantment configuration options Fixes a bug where basePrice was set to a material name instead of the price for the material being displayed Adds missing tab-completion for material/enchantment costs Prevents inconsistencies in deciding if a value is null
This commit is contained in:
@ -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.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@ -28,6 +29,8 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
//Arguments: <setting> [new value/material or enchantment] []
|
||||
|
||||
if (args.length == 1) {
|
||||
List<String> availableCommands = new ArrayList<>();
|
||||
availableCommands.add("reload");
|
||||
@ -40,10 +43,38 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
||||
return filterMatchingContains(availableCommands, args[0]);
|
||||
} else if (args.length == 2) {
|
||||
return tabCompleteCommandValues(args[0], args[1]);
|
||||
} else if (args.length == 3) {
|
||||
//Get per-material tab completions, or return nothing if an invalid setting was specified
|
||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||
if (globalSetting.getCommandName().equalsIgnoreCase(args[0])) {
|
||||
return getPerTypeTabCompletions(globalSetting, args);
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets tab-completions for a selected material or enchantment
|
||||
*
|
||||
* @param globalSetting <p>The global setting to get tab-completions for</p>
|
||||
* @param args <p>The arguments given by the user</p>
|
||||
* @return <p>The tab-completions to show to the user</p>
|
||||
*/
|
||||
private List<String> getPerTypeTabCompletions(GlobalSetting globalSetting, String[] args) {
|
||||
//Display possible tab-completions only if a valid enchantment or material is provided
|
||||
if (((globalSetting == GlobalSetting.BASE_PRICE ||
|
||||
globalSetting == GlobalSetting.PRICE_PER_DURABILITY_POINT) &&
|
||||
InputParsingHelper.matchMaterial(args[1]) != null) ||
|
||||
(globalSetting == GlobalSetting.ENCHANTMENT_COST &&
|
||||
InputParsingHelper.matchEnchantment(args[1]) != null)) {
|
||||
return filterMatchingContains(getTabCompletions(globalSetting.getValueType()), args[2]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tab completes the values available for the given command
|
||||
*
|
||||
|
Reference in New Issue
Block a user