Starts on the Scrapper implementation
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package net.knarcraft.blacksmith.command;
|
||||
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.GlobalSetting;
|
||||
import net.knarcraft.blacksmith.config.GlobalSettings;
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSetting;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage;
|
||||
import net.knarcraft.blacksmith.formatting.ItemType;
|
||||
@@ -38,46 +38,46 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
if (commandName.equalsIgnoreCase("reload")) {
|
||||
return new ReloadCommand().onCommand(sender, command, label, args);
|
||||
}
|
||||
GlobalSettings settings = BlacksmithPlugin.getInstance().getSettings();
|
||||
GlobalBlacksmithSettings settings = BlacksmithPlugin.getInstance().getSettings();
|
||||
|
||||
//Find which global setting the user has specified, if any
|
||||
GlobalSetting detectedGlobalSetting = null;
|
||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||
if (commandName.equalsIgnoreCase(globalSetting.getCommandName())) {
|
||||
detectedGlobalSetting = globalSetting;
|
||||
GlobalBlacksmithSetting detectedGlobalBlacksmithSetting = null;
|
||||
for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) {
|
||||
if (commandName.equalsIgnoreCase(globalBlacksmithSetting.getCommandName())) {
|
||||
detectedGlobalBlacksmithSetting = globalBlacksmithSetting;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Find which npc setting the user has specified, if any
|
||||
NPCSetting detectedNPCSetting = null;
|
||||
for (NPCSetting npcSetting : NPCSetting.values()) {
|
||||
if (commandName.equalsIgnoreCase(npcSetting.getCommandName())) {
|
||||
detectedNPCSetting = npcSetting;
|
||||
BlacksmithNPCSetting detectedBlacksmithNPCSetting = null;
|
||||
for (BlacksmithNPCSetting blacksmithNpcSetting : BlacksmithNPCSetting.values()) {
|
||||
if (commandName.equalsIgnoreCase(blacksmithNpcSetting.getCommandName())) {
|
||||
detectedBlacksmithNPCSetting = blacksmithNpcSetting;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Display the current value of a setting
|
||||
if (args.length == 1) {
|
||||
return displayCurrentValue(detectedGlobalSetting, detectedNPCSetting, settings, sender);
|
||||
return displayCurrentValue(detectedGlobalBlacksmithSetting, detectedBlacksmithNPCSetting, settings, sender);
|
||||
} else if (args.length == 2 && isSpecialCase(commandName)) {
|
||||
if (displaySpecialCaseValue(args[1], sender, detectedGlobalSetting, settings)) {
|
||||
if (displaySpecialCaseValue(args[1], sender, detectedGlobalBlacksmithSetting, settings)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Update the value of a special-case setting
|
||||
if (args.length == 3 && updateSpecialCase(settings, detectedGlobalSetting, args, sender)) {
|
||||
if (args.length == 3 && updateSpecialCase(settings, detectedGlobalBlacksmithSetting, args, sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Change the value of the specified setting
|
||||
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);
|
||||
if ((detectedGlobalBlacksmithSetting != null &&
|
||||
TypeValidationHelper.isValid(detectedGlobalBlacksmithSetting.getValueType(), args[1], sender)) ||
|
||||
(detectedBlacksmithNPCSetting != null &&
|
||||
TypeValidationHelper.isValid(detectedBlacksmithNPCSetting.getValueType(), args[1], sender))) {
|
||||
return changeValue(args, detectedGlobalBlacksmithSetting, detectedBlacksmithNPCSetting, settings, sender);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -87,28 +87,28 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
* Changes the value of the setting defined in the user's input
|
||||
*
|
||||
* @param args <p>The arguments given by the user</p>
|
||||
* @param detectedGlobalSetting <p>The global setting recognized from the input, if any</p>
|
||||
* @param detectedNPCSetting <p>The NPC setting recognized from the input, if any</p>
|
||||
* @param detectedGlobalBlacksmithSetting <p>The global setting recognized from the input, if any</p>
|
||||
* @param detectedBlacksmithNPCSetting <p>The NPC setting recognized from the input, if any</p>
|
||||
* @param settings <p>The global settings object to get settings from</p>
|
||||
* @param sender <p>The command sender to display any output to</p>
|
||||
* @return <p>True if the value was successfully changed</p>
|
||||
*/
|
||||
private boolean changeValue(String[] args, GlobalSetting detectedGlobalSetting, NPCSetting detectedNPCSetting,
|
||||
GlobalSettings settings, CommandSender sender) {
|
||||
private boolean changeValue(String[] args, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, BlacksmithNPCSetting detectedBlacksmithNPCSetting,
|
||||
GlobalBlacksmithSettings settings, CommandSender sender) {
|
||||
String newValue = args[1];
|
||||
if (detectedGlobalSetting != null) {
|
||||
settings.changeValue(detectedGlobalSetting, newValue);
|
||||
if (detectedGlobalBlacksmithSetting != null) {
|
||||
settings.changeValue(detectedGlobalBlacksmithSetting, newValue);
|
||||
BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender,
|
||||
getValueChangedMessage(detectedGlobalSetting.getCommandName(), newValue));
|
||||
getValueChangedMessage(detectedGlobalBlacksmithSetting.getCommandName(), newValue));
|
||||
return true;
|
||||
} else if (detectedNPCSetting != null) {
|
||||
} else if (detectedBlacksmithNPCSetting != null) {
|
||||
//This makes sure all arguments are treated as a sentence
|
||||
if (detectedNPCSetting.getValueType() == SettingValueType.STRING) {
|
||||
if (detectedBlacksmithNPCSetting.getValueType() == SettingValueType.STRING) {
|
||||
newValue = String.join(" ", Arrays.asList(args).subList(1, args.length));
|
||||
}
|
||||
settings.changeValue(detectedNPCSetting, newValue);
|
||||
settings.changeValue(detectedBlacksmithNPCSetting, newValue);
|
||||
BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender,
|
||||
getValueChangedMessage(detectedNPCSetting.getCommandName(), newValue));
|
||||
getValueChangedMessage(detectedBlacksmithNPCSetting.getCommandName(), newValue));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -118,28 +118,28 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
/**
|
||||
* Displays the current value of the selected setting
|
||||
*
|
||||
* @param detectedGlobalSetting <p>The global setting recognized from the input, if any</p>
|
||||
* @param detectedNPCSetting <p>The NPC setting recognized from the input, if any</p>
|
||||
* @param detectedGlobalBlacksmithSetting <p>The global setting recognized from the input, if any</p>
|
||||
* @param detectedBlacksmithNPCSetting <p>The NPC setting recognized from the input, if any</p>
|
||||
* @param settings <p>The global settings object to get settings from</p>
|
||||
* @param sender <p>The command sender to display any output to</p>
|
||||
* @return <p>True if a settings was successfully displayed</p>
|
||||
*/
|
||||
private boolean displayCurrentValue(GlobalSetting detectedGlobalSetting, NPCSetting detectedNPCSetting,
|
||||
GlobalSettings settings, CommandSender sender) {
|
||||
private boolean displayCurrentValue(GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, BlacksmithNPCSetting detectedBlacksmithNPCSetting,
|
||||
GlobalBlacksmithSettings settings, CommandSender sender) {
|
||||
String settingValue;
|
||||
String correctCommandName;
|
||||
boolean printRawValue = false;
|
||||
|
||||
//Find the value of the specified setting
|
||||
//TODO: See if there's a way to remove this duplication
|
||||
if (detectedGlobalSetting != null) {
|
||||
settingValue = String.valueOf(settings.getRawValue(detectedGlobalSetting));
|
||||
correctCommandName = detectedGlobalSetting.getCommandName();
|
||||
} else if (detectedNPCSetting != null) {
|
||||
settingValue = String.valueOf(settings.getRawValue(detectedNPCSetting));
|
||||
correctCommandName = detectedNPCSetting.getCommandName();
|
||||
if (detectedGlobalBlacksmithSetting != null) {
|
||||
settingValue = String.valueOf(settings.getRawValue(detectedGlobalBlacksmithSetting));
|
||||
correctCommandName = detectedGlobalBlacksmithSetting.getCommandName();
|
||||
} else if (detectedBlacksmithNPCSetting != null) {
|
||||
settingValue = String.valueOf(settings.getRawValue(detectedBlacksmithNPCSetting));
|
||||
correctCommandName = detectedBlacksmithNPCSetting.getCommandName();
|
||||
//For messages, print an additional raw value showing which color codes are used
|
||||
if (detectedNPCSetting.getPath().startsWith("defaults.messages")) {
|
||||
if (detectedBlacksmithNPCSetting.getPath().startsWith("defaults.messages")) {
|
||||
printRawValue = true;
|
||||
}
|
||||
} else {
|
||||
@@ -165,15 +165,15 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
* @param settings <p>The settings object to query</p>
|
||||
* @return <p>True if the value was successfully displayed</p>
|
||||
*/
|
||||
private boolean displaySpecialCaseValue(String selector, CommandSender sender, GlobalSetting setting,
|
||||
GlobalSettings settings) {
|
||||
if (setting == GlobalSetting.BASE_PRICE || setting == GlobalSetting.PRICE_PER_DURABILITY_POINT) {
|
||||
private boolean displaySpecialCaseValue(String selector, CommandSender sender, GlobalBlacksmithSetting setting,
|
||||
GlobalBlacksmithSettings settings) {
|
||||
if (setting == GlobalBlacksmithSetting.BASE_PRICE || setting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) {
|
||||
Material material = InputParsingHelper.matchMaterial(selector);
|
||||
if (material == null) {
|
||||
return false;
|
||||
}
|
||||
String currentValue;
|
||||
if (setting == GlobalSetting.BASE_PRICE) {
|
||||
if (setting == GlobalBlacksmithSetting.BASE_PRICE) {
|
||||
currentValue = String.valueOf(settings.getBasePrice(material));
|
||||
} else {
|
||||
currentValue = String.valueOf(settings.getPricePerDurabilityPoint(material));
|
||||
@@ -182,7 +182,7 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
BlacksmithTranslatableMessage.getItemCurrentValueMessage(setting.getCommandName(),
|
||||
ItemType.MATERIAL, material.name(), currentValue));
|
||||
return true;
|
||||
} else if (setting == GlobalSetting.ENCHANTMENT_COST) {
|
||||
} else if (setting == GlobalBlacksmithSetting.ENCHANTMENT_COST) {
|
||||
Enchantment enchantment = InputParsingHelper.matchEnchantment(selector);
|
||||
if (enchantment == null) {
|
||||
return false;
|
||||
@@ -204,21 +204,21 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
* @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());
|
||||
return commandName.equalsIgnoreCase(GlobalBlacksmithSetting.BASE_PRICE.getCommandName()) ||
|
||||
commandName.equalsIgnoreCase(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getCommandName()) ||
|
||||
commandName.equalsIgnoreCase(GlobalBlacksmithSetting.ENCHANTMENT_COST.getCommandName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a special-case configuration value if a special-case is encountered
|
||||
*
|
||||
* @param settings <p>The settings to modify</p>
|
||||
* @param detectedGlobalSetting <p>The global setting specified</p>
|
||||
* @param detectedGlobalBlacksmithSetting <p>The global setting specified</p>
|
||||
* @param args <p>All arguments given</p>
|
||||
* @param sender <p>The command sender to notify if successful</p>
|
||||
* @return <p>True if already handled as a special case</p>
|
||||
*/
|
||||
private boolean updateSpecialCase(GlobalSettings settings, GlobalSetting detectedGlobalSetting, String[] args,
|
||||
private boolean updateSpecialCase(GlobalBlacksmithSettings settings, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, String[] args,
|
||||
CommandSender sender) {
|
||||
if (InputParsingHelper.isEmpty(args[2])) {
|
||||
args[2] = "-1";
|
||||
@@ -228,10 +228,10 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
double newPrice = Double.parseDouble(args[2]);
|
||||
String newValue = String.valueOf(newPrice);
|
||||
|
||||
if (detectedGlobalSetting == GlobalSetting.BASE_PRICE ||
|
||||
detectedGlobalSetting == GlobalSetting.PRICE_PER_DURABILITY_POINT) {
|
||||
return updatePriceSpecialCase(settings, detectedGlobalSetting, args[1], newPrice, sender);
|
||||
} else if (detectedGlobalSetting == GlobalSetting.ENCHANTMENT_COST) {
|
||||
if (detectedGlobalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE ||
|
||||
detectedGlobalBlacksmithSetting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) {
|
||||
return updatePriceSpecialCase(settings, detectedGlobalBlacksmithSetting, args[1], newPrice, sender);
|
||||
} else if (detectedGlobalBlacksmithSetting == GlobalBlacksmithSetting.ENCHANTMENT_COST) {
|
||||
//Update enchantment cost for an item
|
||||
Enchantment enchantment = InputParsingHelper.matchEnchantment(args[1]);
|
||||
if (enchantment == null) {
|
||||
@@ -241,7 +241,7 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
String itemChanged = enchantment.getKey().getKey();
|
||||
settings.setEnchantmentCost(enchantment, newPrice);
|
||||
BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender,
|
||||
BlacksmithTranslatableMessage.getItemValueChangedMessage(detectedGlobalSetting.getCommandName(),
|
||||
BlacksmithTranslatableMessage.getItemValueChangedMessage(detectedGlobalBlacksmithSetting.getCommandName(),
|
||||
itemType, itemChanged, newValue));
|
||||
return true;
|
||||
} else {
|
||||
@@ -253,27 +253,27 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
* Updates a special case price configuration value if a special case is encountered
|
||||
*
|
||||
* @param settings <p>The settings to modify</p>
|
||||
* @param detectedGlobalSetting <p>The global setting specified</p>
|
||||
* @param detectedGlobalBlacksmithSetting <p>The global setting specified</p>
|
||||
* @param materialName <p>The material name to update the price for</p>
|
||||
* @param newPrice <p>The new price to update to</p>
|
||||
* @param sender <p>The command sender to respond to</p>
|
||||
* @return <p>True if the input was valid, and the item(s) was/were updated</p>
|
||||
*/
|
||||
private boolean updatePriceSpecialCase(GlobalSettings settings, GlobalSetting detectedGlobalSetting,
|
||||
private boolean updatePriceSpecialCase(GlobalBlacksmithSettings settings, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting,
|
||||
String materialName, double newPrice, CommandSender sender) {
|
||||
ItemType itemType = ItemType.MATERIAL;
|
||||
String itemChanged;
|
||||
//Update base price or price per durability point for an item
|
||||
if (materialName.contains("*")) {
|
||||
itemChanged = materialName;
|
||||
updateAllMatchedPrices(settings, detectedGlobalSetting, materialName, newPrice);
|
||||
updateAllMatchedPrices(settings, detectedGlobalBlacksmithSetting, materialName, newPrice);
|
||||
} else {
|
||||
Material material = InputParsingHelper.matchMaterial(materialName);
|
||||
if (material == null) {
|
||||
return false;
|
||||
}
|
||||
itemChanged = material.name();
|
||||
if (detectedGlobalSetting == GlobalSetting.BASE_PRICE) {
|
||||
if (detectedGlobalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE) {
|
||||
settings.setBasePrice(material, newPrice);
|
||||
} else {
|
||||
settings.setPricePerDurabilityPoint(material, newPrice);
|
||||
@@ -281,7 +281,7 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender,
|
||||
BlacksmithTranslatableMessage.getItemValueChangedMessage(detectedGlobalSetting.getCommandName(),
|
||||
BlacksmithTranslatableMessage.getItemValueChangedMessage(detectedGlobalBlacksmithSetting.getCommandName(),
|
||||
itemType, itemChanged, String.valueOf(newPrice)));
|
||||
return true;
|
||||
}
|
||||
@@ -290,11 +290,11 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
* Updates all materials matching the material name wildcard
|
||||
*
|
||||
* @param settings <p>The settings to modify</p>
|
||||
* @param detectedGlobalSetting <p>The global setting specified</p>
|
||||
* @param detectedGlobalBlacksmithSetting <p>The global setting specified</p>
|
||||
* @param materialName <p>The wildcard material name to update cost for</p>
|
||||
* @param newPrice <p>The new cost for the matched items</p>
|
||||
*/
|
||||
private void updateAllMatchedPrices(GlobalSettings settings, GlobalSetting detectedGlobalSetting,
|
||||
private void updateAllMatchedPrices(GlobalBlacksmithSettings settings, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting,
|
||||
String materialName, double newPrice) {
|
||||
String search = InputParsingHelper.regExIfy(materialName);
|
||||
for (Material material : ItemHelper.getAllReforgeAbleMaterials()) {
|
||||
@@ -302,7 +302,7 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (detectedGlobalSetting == GlobalSetting.BASE_PRICE) {
|
||||
if (detectedGlobalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE) {
|
||||
settings.setBasePrice(material, newPrice);
|
||||
} else {
|
||||
settings.setPricePerDurabilityPoint(material, newPrice);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package net.knarcraft.blacksmith.command;
|
||||
|
||||
import net.knarcraft.blacksmith.config.GlobalSetting;
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSetting;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -39,20 +39,20 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
||||
if (args.length == 1) {
|
||||
List<String> availableCommands = new ArrayList<>();
|
||||
availableCommands.add("reload");
|
||||
for (NPCSetting setting : NPCSetting.values()) {
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
availableCommands.add(setting.getCommandName());
|
||||
}
|
||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||
availableCommands.add(globalSetting.getCommandName());
|
||||
for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) {
|
||||
availableCommands.add(globalBlacksmithSetting.getCommandName());
|
||||
}
|
||||
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);
|
||||
for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) {
|
||||
if (globalBlacksmithSetting.getCommandName().equalsIgnoreCase(args[0])) {
|
||||
return getPerTypeTabCompletions(globalBlacksmithSetting, args);
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
@@ -68,14 +68,14 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
||||
*/
|
||||
private List<String> skipCompletionForSpacedMessage(String[] args) {
|
||||
if (args.length > 2) {
|
||||
NPCSetting npcSetting = null;
|
||||
for (NPCSetting setting : NPCSetting.values()) {
|
||||
BlacksmithNPCSetting blacksmithNpcSetting = null;
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
if (setting.getCommandName().equalsIgnoreCase(args[0])) {
|
||||
npcSetting = setting;
|
||||
blacksmithNpcSetting = setting;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (npcSetting != null && npcSetting.getPath().startsWith("defaults.messages")) {
|
||||
if (blacksmithNpcSetting != null && blacksmithNpcSetting.getPath().startsWith("defaults.messages")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -85,18 +85,18 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
||||
/**
|
||||
* Gets tab-completions for a selected material or enchantment
|
||||
*
|
||||
* @param globalSetting <p>The global setting to get tab-completions for</p>
|
||||
* @param globalBlacksmithSetting <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) {
|
||||
private List<String> getPerTypeTabCompletions(GlobalBlacksmithSetting globalBlacksmithSetting, 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) &&
|
||||
if (((globalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE ||
|
||||
globalBlacksmithSetting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) &&
|
||||
InputParsingHelper.matchMaterial(args[1]) != null) ||
|
||||
(globalSetting == GlobalSetting.ENCHANTMENT_COST &&
|
||||
(globalBlacksmithSetting == GlobalBlacksmithSetting.ENCHANTMENT_COST &&
|
||||
InputParsingHelper.matchEnchantment(args[1]) != null)) {
|
||||
return filterMatchingContains(getTabCompletions(globalSetting.getValueType()), args[2]);
|
||||
return filterMatchingContains(getTabCompletions(globalBlacksmithSetting.getValueType()), args[2]);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -113,15 +113,15 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
||||
if (commandName.equalsIgnoreCase("reload")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||
if (globalSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
return getCompletions(globalSetting, commandValue);
|
||||
for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) {
|
||||
if (globalBlacksmithSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
return getCompletions(globalBlacksmithSetting, commandValue);
|
||||
}
|
||||
}
|
||||
for (NPCSetting npcSetting : NPCSetting.values()) {
|
||||
if (npcSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
for (BlacksmithNPCSetting blacksmithNpcSetting : BlacksmithNPCSetting.values()) {
|
||||
if (blacksmithNpcSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
return filterMatchingContains(getTabCompletions(
|
||||
npcSetting.getValueType()), commandValue);
|
||||
blacksmithNpcSetting.getValueType()), commandValue);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -130,15 +130,15 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
||||
/**
|
||||
* Gets tab-completions for the given global setting and filters on the command value
|
||||
*
|
||||
* @param globalSetting <p>The global setting to get tab-completions for</p>
|
||||
* @param globalBlacksmithSetting <p>The global setting to get tab-completions for</p>
|
||||
* @param commandValue <p>The command value used to filter between available tab-completions</p>
|
||||
* @return <p>The available tab-completions</p>
|
||||
*/
|
||||
private List<String> getCompletions(GlobalSetting globalSetting, String commandValue) {
|
||||
List<String> returnValues = filterMatchingContains(getTabCompletions(globalSetting.getValueType()), commandValue);
|
||||
if (globalSetting == GlobalSetting.BASE_PRICE || globalSetting == GlobalSetting.PRICE_PER_DURABILITY_POINT) {
|
||||
private List<String> getCompletions(GlobalBlacksmithSetting globalBlacksmithSetting, String commandValue) {
|
||||
List<String> returnValues = filterMatchingContains(getTabCompletions(globalBlacksmithSetting.getValueType()), commandValue);
|
||||
if (globalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE || globalBlacksmithSetting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) {
|
||||
returnValues.addAll(filterMatchingContains(getTabCompletions(SettingValueType.MATERIAL), commandValue));
|
||||
} else if (globalSetting == GlobalSetting.ENCHANTMENT_COST) {
|
||||
} else if (globalBlacksmithSetting == GlobalBlacksmithSetting.ENCHANTMENT_COST) {
|
||||
returnValues.addAll(filterMatchingContains(getTabCompletions(SettingValueType.ENCHANTMENT), commandValue));
|
||||
}
|
||||
return returnValues;
|
||||
|
@@ -3,7 +3,7 @@ package net.knarcraft.blacksmith.command;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage;
|
||||
import net.knarcraft.blacksmith.trait.BlacksmithTrait;
|
||||
@@ -41,15 +41,15 @@ public class BlackSmithEditCommand implements CommandExecutor {
|
||||
|
||||
BlacksmithTrait blacksmithTrait = npc.getTraitNullable(BlacksmithTrait.class);
|
||||
|
||||
for (NPCSetting npcSetting : NPCSetting.values()) {
|
||||
String commandName = npcSetting.getCommandName();
|
||||
for (BlacksmithNPCSetting blacksmithNpcSetting : BlacksmithNPCSetting.values()) {
|
||||
String commandName = blacksmithNpcSetting.getCommandName();
|
||||
if (commandName.equalsIgnoreCase(args[0])) {
|
||||
String newValue = args.length < 2 ? null : args[1];
|
||||
//This makes sure all arguments are treated as a sentence
|
||||
if (npcSetting.getValueType() == SettingValueType.STRING && args.length > 2) {
|
||||
if (blacksmithNpcSetting.getValueType() == SettingValueType.STRING && args.length > 2) {
|
||||
newValue = String.join(" ", Arrays.asList(args).subList(1, args.length));
|
||||
}
|
||||
return displayOrChangeNPCSetting(blacksmithTrait, npcSetting, newValue, sender);
|
||||
return displayOrChangeNPCSetting(blacksmithTrait, blacksmithNpcSetting, newValue, sender);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -59,23 +59,23 @@ public class BlackSmithEditCommand implements CommandExecutor {
|
||||
* Changes the given NPC setting, or displays the current value if a new value isn't specified
|
||||
*
|
||||
* @param blacksmithTrait <p>The blacksmith trait belonging to the selected NPC</p>
|
||||
* @param npcSetting <p>The NPC setting to change</p>
|
||||
* @param blacksmithNpcSetting <p>The NPC setting to change</p>
|
||||
* @param newValue <p>The value to change the setting to</p>
|
||||
* @param sender <p>The command sender to notify about results</p>
|
||||
* @return <p>True if everything went successfully</p>
|
||||
*/
|
||||
private boolean displayOrChangeNPCSetting(BlacksmithTrait blacksmithTrait, NPCSetting npcSetting, String newValue,
|
||||
private boolean displayOrChangeNPCSetting(BlacksmithTrait blacksmithTrait, BlacksmithNPCSetting blacksmithNpcSetting, String newValue,
|
||||
CommandSender sender) {
|
||||
if (newValue == null) {
|
||||
//Display the current value of the setting
|
||||
displayNPCSetting(blacksmithTrait, npcSetting, sender);
|
||||
displayNPCSetting(blacksmithTrait, blacksmithNpcSetting, sender);
|
||||
} else {
|
||||
//If an empty value or null, clear the value instead of changing it
|
||||
if (InputParsingHelper.isEmpty(newValue)) {
|
||||
newValue = null;
|
||||
} else {
|
||||
//Abort if an invalid value is given
|
||||
boolean isValidType = TypeValidationHelper.isValid(npcSetting.getValueType(), newValue, sender);
|
||||
boolean isValidType = TypeValidationHelper.isValid(blacksmithNpcSetting.getValueType(), newValue, sender);
|
||||
if (!isValidType) {
|
||||
return false;
|
||||
}
|
||||
@@ -83,9 +83,9 @@ public class BlackSmithEditCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
//Change the setting
|
||||
blacksmithTrait.getSettings().changeSetting(npcSetting, newValue);
|
||||
blacksmithTrait.getSettings().changeSetting(blacksmithNpcSetting, newValue);
|
||||
BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender,
|
||||
getValueChangedMessage(npcSetting.getCommandName(), String.valueOf(newValue)));
|
||||
getValueChangedMessage(blacksmithNpcSetting.getCommandName(), String.valueOf(newValue)));
|
||||
//Save the changes immediately to prevent data loss on server crash
|
||||
CitizensAPI.getNPCRegistry().saveToStore();
|
||||
}
|
||||
@@ -96,24 +96,24 @@ public class BlackSmithEditCommand implements CommandExecutor {
|
||||
* Displays the current value of the given NPC setting
|
||||
*
|
||||
* @param blacksmithTrait <p>The blacksmith trait of the NPC to get the value from</p>
|
||||
* @param npcSetting <p>The NPC setting to see the value of</p>
|
||||
* @param blacksmithNpcSetting <p>The NPC setting to see the value of</p>
|
||||
* @param sender <p>The command sender to display the value to</p>
|
||||
*/
|
||||
private void displayNPCSetting(BlacksmithTrait blacksmithTrait, NPCSetting npcSetting, CommandSender sender) {
|
||||
String rawValue = String.valueOf(blacksmithTrait.getSettings().getRawValue(npcSetting));
|
||||
private void displayNPCSetting(BlacksmithTrait blacksmithTrait, BlacksmithNPCSetting blacksmithNpcSetting, CommandSender sender) {
|
||||
String rawValue = String.valueOf(blacksmithTrait.getSettings().getRawValue(blacksmithNpcSetting));
|
||||
if (InputParsingHelper.isEmpty(rawValue)) {
|
||||
//Display the default value, if no custom value has been specified
|
||||
rawValue = String.valueOf(BlacksmithPlugin.getInstance().getSettings().getRawValue(npcSetting));
|
||||
rawValue = String.valueOf(BlacksmithPlugin.getInstance().getSettings().getRawValue(blacksmithNpcSetting));
|
||||
BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender,
|
||||
getCurrentValueMessage(npcSetting.getCommandName(), rawValue));
|
||||
getCurrentValueMessage(blacksmithNpcSetting.getCommandName(), rawValue));
|
||||
} else {
|
||||
//Add a marker if the value has been customized
|
||||
String marker = BlacksmithPlugin.getTranslator().getTranslatedMessage(
|
||||
BlacksmithTranslatableMessage.SETTING_OVERRIDDEN_MARKER);
|
||||
BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender,
|
||||
getCurrentValueMessage(npcSetting.getCommandName(), rawValue) + marker);
|
||||
getCurrentValueMessage(blacksmithNpcSetting.getCommandName(), rawValue) + marker);
|
||||
}
|
||||
if (npcSetting.getPath().startsWith("defaults.messages")) {
|
||||
if (blacksmithNpcSetting.getPath().startsWith("defaults.messages")) {
|
||||
sender.sendMessage(BlacksmithTranslatableMessage.getRawValueMessage(
|
||||
rawValue.replace(ChatColor.COLOR_CHAR, '&')));
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package net.knarcraft.blacksmith.command;
|
||||
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
|
||||
import net.knarcraft.blacksmith.util.TabCompleteValuesHelper;
|
||||
import net.knarcraft.knarlib.util.TabCompletionHelper;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -26,7 +26,7 @@ public class BlackSmithEditTabCompleter implements TabCompleter {
|
||||
}
|
||||
|
||||
List<String> npcSettings = new ArrayList<>();
|
||||
for (NPCSetting setting : NPCSetting.values()) {
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
npcSettings.add(setting.getCommandName());
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ public class BlackSmithEditTabCompleter implements TabCompleter {
|
||||
* @return <p>Some valid options for the command's argument</p>
|
||||
*/
|
||||
private List<String> tabCompleteCommandValues(String commandName, String commandValue) {
|
||||
for (NPCSetting npcSetting : NPCSetting.values()) {
|
||||
if (npcSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
for (BlacksmithNPCSetting blacksmithNpcSetting : BlacksmithNPCSetting.values()) {
|
||||
if (blacksmithNpcSetting.getCommandName().equalsIgnoreCase(commandName)) {
|
||||
return TabCompletionHelper.filterMatchingContains(TabCompleteValuesHelper.getTabCompletions(
|
||||
npcSetting.getValueType()), commandValue);
|
||||
blacksmithNpcSetting.getValueType()), commandValue);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user