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:
@@ -11,7 +11,6 @@ import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||
import net.knarcraft.blacksmith.util.TypeValidationHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -81,7 +80,14 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
//Change the value of the specified setting
|
||||
return changeValue(args, detectedGlobalSetting, detectedNPCSetting, settings, sender);
|
||||
if ((detectedGlobalSetting != null &&
|
||||
TypeValidationHelper.isValid(detectedGlobalSetting.getValueType(), args[1], sender)) ||
|
||||
(detectedNPCSetting != null &&
|
||||
TypeValidationHelper.isValid(detectedNPCSetting.getValueType(), args[1], sender))) {
|
||||
return changeValue(args, detectedGlobalSetting, detectedNPCSetting, settings, sender);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,7 +172,7 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
private boolean displaySpecialCaseValue(String selector, CommandSender sender, GlobalSetting setting,
|
||||
GlobalSettings settings) {
|
||||
if (setting == GlobalSetting.BASE_PRICE || setting == GlobalSetting.PRICE_PER_DURABILITY_POINT) {
|
||||
Material material = Material.matchMaterial(selector);
|
||||
Material material = InputParsingHelper.matchMaterial(selector);
|
||||
if (material == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -176,16 +182,17 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
} else {
|
||||
currentValue = String.valueOf(settings.getPricePerDurabilityPoint(material));
|
||||
}
|
||||
displaySuccessMessage(sender, TranslatableMessage.getItemCurrentValueMessage(setting.getCommandName(), ItemType.MATERIAL,
|
||||
material.name(), currentValue));
|
||||
displaySuccessMessage(sender, TranslatableMessage.getItemCurrentValueMessage(setting.getCommandName(),
|
||||
ItemType.MATERIAL, material.name(), currentValue));
|
||||
return true;
|
||||
} else if (setting == GlobalSetting.ENCHANTMENT_COST) {
|
||||
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(selector));
|
||||
Enchantment enchantment = InputParsingHelper.matchEnchantment(selector);
|
||||
if (enchantment == null) {
|
||||
return false;
|
||||
}
|
||||
displaySuccessMessage(sender, TranslatableMessage.getItemCurrentValueMessage(setting.getCommandName(), ItemType.ENCHANTMENT,
|
||||
enchantment.toString(), String.valueOf(settings.getEnchantmentCost(enchantment))));
|
||||
displaySuccessMessage(sender, TranslatableMessage.getItemCurrentValueMessage(setting.getCommandName(),
|
||||
ItemType.ENCHANTMENT, enchantment.getKey().getKey(),
|
||||
String.valueOf(settings.getEnchantmentCost(enchantment))));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -215,7 +222,9 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
*/
|
||||
private boolean updateSpecialCase(GlobalSettings settings, GlobalSetting detectedGlobalSetting, String[] args,
|
||||
CommandSender sender) {
|
||||
if (!TypeValidationHelper.isValid(SettingValueType.POSITIVE_DOUBLE, args[2], sender)) {
|
||||
if (InputParsingHelper.isEmpty(args[2])) {
|
||||
args[2] = "-1";
|
||||
} else if (!TypeValidationHelper.isValid(SettingValueType.POSITIVE_DOUBLE, args[2], sender)) {
|
||||
return true;
|
||||
}
|
||||
double newPrice = Double.parseDouble(args[2]);
|
||||
@@ -242,7 +251,7 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
itemType = ItemType.ENCHANTMENT;
|
||||
itemChanged = enchantment.toString();
|
||||
itemChanged = enchantment.getKey().getKey();
|
||||
settings.setEnchantmentCost(enchantment, newPrice);
|
||||
} else {
|
||||
return false;
|
||||
|
@@ -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
|
||||
*
|
||||
|
@@ -9,6 +9,7 @@ import net.knarcraft.blacksmith.formatting.StringFormatter;
|
||||
import net.knarcraft.blacksmith.formatting.TranslatableMessage;
|
||||
import net.knarcraft.blacksmith.formatting.Translator;
|
||||
import net.knarcraft.blacksmith.trait.BlacksmithTrait;
|
||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||
import net.knarcraft.blacksmith.util.TypeValidationHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -72,7 +73,7 @@ public class BlackSmithEditCommand implements CommandExecutor {
|
||||
displayNPCSetting(blacksmithTrait, npcSetting, sender);
|
||||
} else {
|
||||
//If an empty value or null, clear the value instead of changing it
|
||||
if (newValue.equalsIgnoreCase("null") || newValue.equals("\"\"") || newValue.trim().isEmpty()) {
|
||||
if (InputParsingHelper.isEmpty(newValue)) {
|
||||
newValue = null;
|
||||
} else {
|
||||
//Abort if an invalid value is given
|
||||
@@ -101,7 +102,7 @@ public class BlackSmithEditCommand implements CommandExecutor {
|
||||
*/
|
||||
private void displayNPCSetting(BlacksmithTrait blacksmithTrait, NPCSetting npcSetting, CommandSender sender) {
|
||||
String rawValue = String.valueOf(blacksmithTrait.getSettings().getRawValue(npcSetting));
|
||||
if (rawValue == null || rawValue.trim().isEmpty() || rawValue.equalsIgnoreCase("null")) {
|
||||
if (InputParsingHelper.isEmpty(rawValue)) {
|
||||
//Display the default value, if no custom value has been specified
|
||||
rawValue = String.valueOf(BlacksmithPlugin.getInstance().getSettings().getRawValue(npcSetting));
|
||||
displaySuccessMessage(sender, getCurrentValueMessage(npcSetting.getCommandName(), rawValue));
|
||||
|
Reference in New Issue
Block a user