Starts on the Scrapper implementation
This commit is contained in:
parent
72ea5600fe
commit
3e3a35d02a
@ -7,7 +7,7 @@ import net.knarcraft.blacksmith.command.BlackSmithEditCommand;
|
||||
import net.knarcraft.blacksmith.command.BlackSmithEditTabCompleter;
|
||||
import net.knarcraft.blacksmith.command.PresetCommand;
|
||||
import net.knarcraft.blacksmith.command.PresetTabCompleter;
|
||||
import net.knarcraft.blacksmith.config.GlobalSettings;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings;
|
||||
import net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage;
|
||||
import net.knarcraft.blacksmith.listener.NPCClickListener;
|
||||
import net.knarcraft.blacksmith.listener.PlayerListener;
|
||||
@ -33,7 +33,7 @@ import java.util.logging.Level;
|
||||
public class BlacksmithPlugin extends JavaPlugin {
|
||||
|
||||
private static BlacksmithPlugin instance;
|
||||
private GlobalSettings config;
|
||||
private GlobalBlacksmithSettings config;
|
||||
private static Translator translator;
|
||||
private static StringFormatter stringFormatter;
|
||||
|
||||
@ -67,7 +67,7 @@ public class BlacksmithPlugin extends JavaPlugin {
|
||||
*
|
||||
* @return <p>Settings for the blacksmith plugin</p>
|
||||
*/
|
||||
public GlobalSettings getSettings() {
|
||||
public GlobalBlacksmithSettings getSettings() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ public class BlacksmithPlugin extends JavaPlugin {
|
||||
this.saveConfig();
|
||||
|
||||
//Load settings
|
||||
config = new GlobalSettings(this);
|
||||
config = new GlobalBlacksmithSettings(this);
|
||||
config.load();
|
||||
|
||||
//Prepare the translator
|
||||
|
@ -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;
|
||||
|
@ -1,214 +1,43 @@
|
||||
package net.knarcraft.blacksmith.config;
|
||||
|
||||
/**
|
||||
* An enum representing all of Blacksmith's settings
|
||||
* An interface describing an NPC setting
|
||||
*/
|
||||
public enum NPCSetting {
|
||||
|
||||
/**
|
||||
* The setting for whether the NPC should drop an item to the ground when finished
|
||||
*
|
||||
* <p>If set to false, the item will be directly put in the player's inventory instead</p>
|
||||
*/
|
||||
DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "dropItem"),
|
||||
|
||||
/**
|
||||
* The setting for the chance of a reforging to fail
|
||||
*/
|
||||
FAIL_CHANCE("failReforgeChance", SettingValueType.PERCENTAGE, 10, "failReforgeChance"),
|
||||
|
||||
/**
|
||||
* The setting for whether failing a reforging should downgrade/remove enchantments as well
|
||||
*/
|
||||
FAIL_REMOVE_ENCHANTMENTS("failReforgeRemovesEnchantments", SettingValueType.BOOLEAN, false,
|
||||
"failReforgeRemovesEnchantments"),
|
||||
|
||||
/**
|
||||
* The setting for the chance of an additional enchantment being added
|
||||
*/
|
||||
EXTRA_ENCHANTMENT_CHANCE("extraEnchantmentChance", SettingValueType.PERCENTAGE, 5,
|
||||
"extraEnchantmentChance"),
|
||||
|
||||
/**
|
||||
* The setting for the maximum amount of enchantments that can be added to an item
|
||||
*/
|
||||
MAX_ENCHANTMENTS("maxEnchantments", SettingValueType.POSITIVE_INTEGER, 3, "maxEnchantments"),
|
||||
|
||||
/**
|
||||
* The maximum amount of seconds a player may need to wait for the reforging to finish
|
||||
*/
|
||||
MAX_REFORGE_DELAY("delaysInSeconds.maximum", SettingValueType.POSITIVE_INTEGER, 30, "maxReforgeDelay"),
|
||||
|
||||
/**
|
||||
* The minimum amount of seconds a player may need to wait for the reforging to finish
|
||||
*/
|
||||
MIN_REFORGE_DELAY("delaysInSeconds.minimum", SettingValueType.POSITIVE_INTEGER, 5, "minReforgeDelay"),
|
||||
|
||||
/**
|
||||
* The setting for number of seconds a player has to wait between each usage of the blacksmith
|
||||
*/
|
||||
REFORGE_COOL_DOWN("delaysInSeconds.reforgeCoolDown", SettingValueType.POSITIVE_INTEGER, 60, "reforgeCoolDown"),
|
||||
|
||||
/**
|
||||
* The setting for which items the blacksmith is able to reforge
|
||||
*/
|
||||
REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "reforgeAbleItems"),
|
||||
|
||||
/**
|
||||
* The setting for the title used to display which kind of blacksmith the NPC is
|
||||
*
|
||||
* <p>While this should be entirely configurable, values such as armor-smith, sword-smith and similar, which
|
||||
* describe the blacksmith's specialization, and thus the range of reforge-able items, is expected.</p>
|
||||
*/
|
||||
BLACKSMITH_TITLE("blacksmithTitle", SettingValueType.STRING, "blacksmith", "blacksmithTitle"),
|
||||
|
||||
/**
|
||||
* The setting for the enchantments a blacksmith cannot apply to items
|
||||
*/
|
||||
ENCHANTMENT_BLOCKLIST("enchantmentBlocklist", SettingValueType.STRING_LIST, new String[]{"binding_curse",
|
||||
"mending", "vanishing_curse"}, "enchantmentBlocklist"),
|
||||
|
||||
/**
|
||||
* Whether to allow this blacksmith to repair anvils
|
||||
*/
|
||||
REPAIR_ANVILS("reforgeAnvils", SettingValueType.BOOLEAN, false, "reforgeAnvils"),
|
||||
|
||||
/*-----------
|
||||
| Messages |
|
||||
-----------*/
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith is busy with another player
|
||||
*/
|
||||
BUSY_WITH_PLAYER_MESSAGE("messages.busyPlayerMessage", SettingValueType.STRING,
|
||||
"&cI'm busy at the moment. Come back later!", "busyPlayerMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith is already reforging something for the player
|
||||
*/
|
||||
BUSY_WITH_REFORGE_MESSAGE("messages.busyReforgeMessage", SettingValueType.STRING,
|
||||
"&cI'm working on it. Be patient! I'll finish {time}!", "busyReforgeMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed if the player has to wait for the cool-down to expire
|
||||
*/
|
||||
COOL_DOWN_UNEXPIRED_MESSAGE("messages.coolDownUnexpiredMessage", SettingValueType.STRING,
|
||||
"&cYou've already had your chance! Give me a break! I'll be ready {time}!",
|
||||
"coolDownUnexpiredMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed when displaying the cost of reforging the held item to the player
|
||||
*/
|
||||
COST_MESSAGE("messages.costMessage", SettingValueType.STRING,
|
||||
"&eIt will cost &a{cost}&e to reforge that &a{item}&e! Click again to reforge!", "costMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed if the blacksmith fails reforging an item
|
||||
*/
|
||||
FAIL_MESSAGE("messages.failReforgeMessage", SettingValueType.STRING,
|
||||
"&cWhoops! Didn't mean to do that! Maybe next time?", "failReforgeMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed if a player is unable to pay the blacksmith
|
||||
*/
|
||||
INSUFFICIENT_FUNDS_MESSAGE("messages.insufficientFundsMessage", SettingValueType.STRING,
|
||||
"&cYou don't have enough money to reforge that item!", "insufficientFundsMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed if the blacksmith encounters an item they cannot reforge
|
||||
*/
|
||||
INVALID_ITEM_MESSAGE("messages.invalidItemMessage", SettingValueType.STRING,
|
||||
"&cI'm sorry, but I'm a/an {title}, I don't know how to reforge that!", "invalidItemMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed if a player presents a different item after seeing the price to reforge an item
|
||||
*/
|
||||
ITEM_UNEXPECTEDLY_CHANGED_MESSAGE("messages.itemChangedMessage", SettingValueType.STRING,
|
||||
"&cThat's not the item you wanted to reforge before!", "itemChangedMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith starts reforging an item
|
||||
*/
|
||||
START_REFORGE_MESSAGE("messages.startReforgeMessage", SettingValueType.STRING,
|
||||
"&eOk, let's see what I can do...", "startReforgeMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith successfully finishes reforging an item
|
||||
*/
|
||||
SUCCESS_MESSAGE("messages.successMessage", SettingValueType.STRING,
|
||||
"There you go! All better!", "successMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed when trying to reforge an item with full durability
|
||||
*/
|
||||
NOT_DAMAGED_MESSAGE("messages.notDamagedMessage", SettingValueType.STRING,
|
||||
"&cThat item is not in need of repair", "notDamagedMessage");
|
||||
|
||||
private final String path;
|
||||
private final String childPath;
|
||||
private final Object value;
|
||||
private final String commandName;
|
||||
private final SettingValueType valueType;
|
||||
|
||||
/**
|
||||
* Instantiates a new setting
|
||||
*
|
||||
* @param path <p>The full config path for this setting</p>
|
||||
* @param valueType <p>The type of value used by this setting</p>
|
||||
* @param value <p>The default value of this setting</p>
|
||||
* @param commandName <p>The name of the command used to change this setting</p>
|
||||
*/
|
||||
NPCSetting(String path, SettingValueType valueType, Object value, String commandName) {
|
||||
this.path = "defaults." + path;
|
||||
this.value = value;
|
||||
this.valueType = valueType;
|
||||
this.childPath = path;
|
||||
this.commandName = commandName;
|
||||
}
|
||||
public interface NPCSetting {
|
||||
|
||||
/**
|
||||
* Gets the full config path for this setting
|
||||
*
|
||||
* @return <p>The full config path for this setting</p>
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
String getPath();
|
||||
|
||||
/**
|
||||
* Gets the config path without the root node
|
||||
*
|
||||
* @return <p>The config path without the root node</p>
|
||||
*/
|
||||
public String getChildPath() {
|
||||
return childPath;
|
||||
}
|
||||
String getChildPath();
|
||||
|
||||
/**
|
||||
* Gets the value of this setting
|
||||
*
|
||||
* @return <p>The value of this setting</p>
|
||||
*/
|
||||
public Object getDefaultValue() {
|
||||
return value;
|
||||
}
|
||||
Object getDefaultValue();
|
||||
|
||||
/**
|
||||
* The name of the command used to change this setting
|
||||
*
|
||||
* @return <p>The name of this setting's command</p>
|
||||
*/
|
||||
public String getCommandName() {
|
||||
return commandName;
|
||||
}
|
||||
String getCommandName();
|
||||
|
||||
/**
|
||||
* Gets the value type for this setting
|
||||
*
|
||||
* @return <p>The value type for this setting</p>
|
||||
*/
|
||||
public SettingValueType getValueType() {
|
||||
return this.valueType;
|
||||
}
|
||||
SettingValueType getValueType();
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,197 @@
|
||||
package net.knarcraft.blacksmith.config.blacksmith;
|
||||
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
|
||||
/**
|
||||
* An enum representing all of Blacksmith's settings
|
||||
*/
|
||||
public enum BlacksmithNPCSetting implements NPCSetting {
|
||||
|
||||
/**
|
||||
* The setting for whether the NPC should drop an item to the ground when finished
|
||||
*
|
||||
* <p>If set to false, the item will be directly put in the player's inventory instead</p>
|
||||
*/
|
||||
DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "dropItem"),
|
||||
|
||||
/**
|
||||
* The setting for the chance of a reforging to fail
|
||||
*/
|
||||
FAIL_CHANCE("failReforgeChance", SettingValueType.PERCENTAGE, 10, "failReforgeChance"),
|
||||
|
||||
/**
|
||||
* The setting for whether failing a reforging should downgrade/remove enchantments as well
|
||||
*/
|
||||
FAIL_REMOVE_ENCHANTMENTS("failReforgeRemovesEnchantments", SettingValueType.BOOLEAN, false,
|
||||
"failReforgeRemovesEnchantments"),
|
||||
|
||||
/**
|
||||
* The setting for the chance of an additional enchantment being added
|
||||
*/
|
||||
EXTRA_ENCHANTMENT_CHANCE("extraEnchantmentChance", SettingValueType.PERCENTAGE, 5,
|
||||
"extraEnchantmentChance"),
|
||||
|
||||
/**
|
||||
* The setting for the maximum amount of enchantments that can be added to an item
|
||||
*/
|
||||
MAX_ENCHANTMENTS("maxEnchantments", SettingValueType.POSITIVE_INTEGER, 3, "maxEnchantments"),
|
||||
|
||||
/**
|
||||
* The maximum amount of seconds a player may need to wait for the reforging to finish
|
||||
*/
|
||||
MAX_REFORGE_DELAY("delaysInSeconds.maximum", SettingValueType.POSITIVE_INTEGER, 30, "maxReforgeDelay"),
|
||||
|
||||
/**
|
||||
* The minimum amount of seconds a player may need to wait for the reforging to finish
|
||||
*/
|
||||
MIN_REFORGE_DELAY("delaysInSeconds.minimum", SettingValueType.POSITIVE_INTEGER, 5, "minReforgeDelay"),
|
||||
|
||||
/**
|
||||
* The setting for number of seconds a player has to wait between each usage of the blacksmith
|
||||
*/
|
||||
REFORGE_COOL_DOWN("delaysInSeconds.reforgeCoolDown", SettingValueType.POSITIVE_INTEGER, 60, "reforgeCoolDown"),
|
||||
|
||||
/**
|
||||
* The setting for which items the blacksmith is able to reforge
|
||||
*/
|
||||
REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "reforgeAbleItems"),
|
||||
|
||||
/**
|
||||
* The setting for the title used to display which kind of blacksmith the NPC is
|
||||
*
|
||||
* <p>While this should be entirely configurable, values such as armor-smith, sword-smith and similar, which
|
||||
* describe the blacksmith's specialization, and thus the range of reforge-able items, is expected.</p>
|
||||
*/
|
||||
BLACKSMITH_TITLE("blacksmithTitle", SettingValueType.STRING, "blacksmith", "blacksmithTitle"),
|
||||
|
||||
/**
|
||||
* The setting for the enchantments a blacksmith cannot apply to items
|
||||
*/
|
||||
ENCHANTMENT_BLOCKLIST("enchantmentBlocklist", SettingValueType.STRING_LIST, new String[]{"binding_curse",
|
||||
"mending", "vanishing_curse"}, "enchantmentBlocklist"),
|
||||
|
||||
/**
|
||||
* Whether to allow this blacksmith to repair anvils
|
||||
*/
|
||||
REPAIR_ANVILS("reforgeAnvils", SettingValueType.BOOLEAN, false, "reforgeAnvils"),
|
||||
|
||||
/*-----------
|
||||
| Messages |
|
||||
-----------*/
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith is busy with another player
|
||||
*/
|
||||
BUSY_WITH_PLAYER_MESSAGE("messages.busyPlayerMessage", SettingValueType.STRING,
|
||||
"&cI'm busy at the moment. Come back later!", "busyPlayerMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith is already reforging something for the player
|
||||
*/
|
||||
BUSY_WITH_REFORGE_MESSAGE("messages.busyReforgeMessage", SettingValueType.STRING,
|
||||
"&cI'm working on it. Be patient! I'll finish {time}!", "busyReforgeMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed if the player has to wait for the cool-down to expire
|
||||
*/
|
||||
COOL_DOWN_UNEXPIRED_MESSAGE("messages.coolDownUnexpiredMessage", SettingValueType.STRING,
|
||||
"&cYou've already had your chance! Give me a break! I'll be ready {time}!",
|
||||
"coolDownUnexpiredMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed when displaying the cost of reforging the held item to the player
|
||||
*/
|
||||
COST_MESSAGE("messages.costMessage", SettingValueType.STRING,
|
||||
"&eIt will cost &a{cost}&e to reforge that &a{item}&e! Click again to reforge!", "costMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed if the blacksmith fails reforging an item
|
||||
*/
|
||||
FAIL_MESSAGE("messages.failReforgeMessage", SettingValueType.STRING,
|
||||
"&cWhoops! Didn't mean to do that! Maybe next time?", "failReforgeMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed if a player is unable to pay the blacksmith
|
||||
*/
|
||||
INSUFFICIENT_FUNDS_MESSAGE("messages.insufficientFundsMessage", SettingValueType.STRING,
|
||||
"&cYou don't have enough money to reforge that item!", "insufficientFundsMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed if the blacksmith encounters an item they cannot reforge
|
||||
*/
|
||||
INVALID_ITEM_MESSAGE("messages.invalidItemMessage", SettingValueType.STRING,
|
||||
"&cI'm sorry, but I'm a/an {title}, I don't know how to reforge that!", "invalidItemMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed if a player presents a different item after seeing the price to reforge an item
|
||||
*/
|
||||
ITEM_UNEXPECTEDLY_CHANGED_MESSAGE("messages.itemChangedMessage", SettingValueType.STRING,
|
||||
"&cThat's not the item you wanted to reforge before!", "itemChangedMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith starts reforging an item
|
||||
*/
|
||||
START_REFORGE_MESSAGE("messages.startReforgeMessage", SettingValueType.STRING,
|
||||
"&eOk, let's see what I can do...", "startReforgeMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith successfully finishes reforging an item
|
||||
*/
|
||||
SUCCESS_MESSAGE("messages.successMessage", SettingValueType.STRING,
|
||||
"There you go! All better!", "successMessage"),
|
||||
|
||||
/**
|
||||
* The message displayed when trying to reforge an item with full durability
|
||||
*/
|
||||
NOT_DAMAGED_MESSAGE("messages.notDamagedMessage", SettingValueType.STRING,
|
||||
"&cThat item is not in need of repair", "notDamagedMessage");
|
||||
|
||||
private final String path;
|
||||
private final String childPath;
|
||||
private final Object value;
|
||||
private final String commandName;
|
||||
private final SettingValueType valueType;
|
||||
|
||||
/**
|
||||
* Instantiates a new setting
|
||||
*
|
||||
* @param path <p>The full config path for this setting</p>
|
||||
* @param valueType <p>The type of value used by this setting</p>
|
||||
* @param value <p>The default value of this setting</p>
|
||||
* @param commandName <p>The name of the command used to change this setting</p>
|
||||
*/
|
||||
BlacksmithNPCSetting(String path, SettingValueType valueType, Object value, String commandName) {
|
||||
this.path = "defaults." + path;
|
||||
this.value = value;
|
||||
this.valueType = valueType;
|
||||
this.childPath = path;
|
||||
this.commandName = commandName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChildPath() {
|
||||
return childPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefaultValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return commandName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SettingValueType getValueType() {
|
||||
return this.valueType;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package net.knarcraft.blacksmith.config;
|
||||
package net.knarcraft.blacksmith.config.blacksmith;
|
||||
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.config.SmithPreset;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
@ -20,18 +22,18 @@ import java.util.logging.Level;
|
||||
/**
|
||||
* A class which keeps track of all Blacksmith settings/config values for one NPC
|
||||
*/
|
||||
public class NPCSettings {
|
||||
public class BlacksmithNPCSettings {
|
||||
|
||||
private final List<Material> reforgeAbleItems = new ArrayList<>();
|
||||
private final List<Enchantment> enchantmentBlocklist = new ArrayList<>();
|
||||
private final Map<NPCSetting, Object> currentValues = new HashMap<>();
|
||||
private final GlobalSettings globalSettings;
|
||||
private final Map<BlacksmithNPCSetting, Object> currentValues = new HashMap<>();
|
||||
private final GlobalBlacksmithSettings globalBlacksmithSettings;
|
||||
|
||||
/**
|
||||
* Instantiates a new "Settings" object
|
||||
*/
|
||||
public NPCSettings(GlobalSettings globalSettings) {
|
||||
this.globalSettings = globalSettings;
|
||||
public BlacksmithNPCSettings(GlobalBlacksmithSettings globalBlacksmithSettings) {
|
||||
this.globalBlacksmithSettings = globalBlacksmithSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +42,7 @@ public class NPCSettings {
|
||||
* @param key <p>The data key to load variables from</p>
|
||||
*/
|
||||
public void loadVariables(DataKey key) {
|
||||
for (NPCSetting setting : NPCSetting.values()) {
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
if (key.keyExists(setting.getChildPath())) {
|
||||
currentValues.put(setting, key.getRaw(setting.getChildPath()));
|
||||
}
|
||||
@ -56,7 +58,7 @@ public class NPCSettings {
|
||||
* @param key <p>The data key to save variables to</p>
|
||||
*/
|
||||
public void saveVariables(DataKey key) {
|
||||
for (NPCSetting setting : NPCSetting.values()) {
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
key.setRaw(setting.getChildPath(), currentValues.get(setting));
|
||||
}
|
||||
}
|
||||
@ -67,7 +69,7 @@ public class NPCSettings {
|
||||
* @param setting <p>The setting to change</p>
|
||||
* @param newValue <p>The new value of the setting</p>
|
||||
*/
|
||||
public void changeSetting(NPCSetting setting, Object newValue) {
|
||||
public void changeSetting(BlacksmithNPCSetting setting, Object newValue) {
|
||||
if (setting.getValueType() == SettingValueType.STRING_LIST ||
|
||||
setting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
|
||||
//Workaround to make sure it's treated as the correct type
|
||||
@ -75,10 +77,10 @@ public class NPCSettings {
|
||||
} else {
|
||||
currentValues.put(setting, newValue);
|
||||
}
|
||||
if (setting == NPCSetting.REFORGE_ABLE_ITEMS) {
|
||||
if (setting == BlacksmithNPCSetting.REFORGE_ABLE_ITEMS) {
|
||||
updateReforgeAbleItems();
|
||||
}
|
||||
if (setting == NPCSetting.ENCHANTMENT_BLOCKLIST) {
|
||||
if (setting == BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST) {
|
||||
updateEnchantmentBlocklist();
|
||||
}
|
||||
}
|
||||
@ -89,7 +91,7 @@ public class NPCSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The current value of the setting</p>
|
||||
*/
|
||||
public Object getRawValue(NPCSetting setting) {
|
||||
public Object getRawValue(BlacksmithNPCSetting setting) {
|
||||
return currentValues.get(setting);
|
||||
}
|
||||
|
||||
@ -99,7 +101,7 @@ public class NPCSettings {
|
||||
* @return <p>The busy with player message</p>
|
||||
*/
|
||||
public String getBusyWithPlayerMessage() {
|
||||
return asString(NPCSetting.BUSY_WITH_PLAYER_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.BUSY_WITH_PLAYER_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,7 +110,7 @@ public class NPCSettings {
|
||||
* @return <p>The busy reforging message</p>
|
||||
*/
|
||||
public String getBusyReforgingMessage() {
|
||||
return asString(NPCSetting.BUSY_WITH_REFORGE_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.BUSY_WITH_REFORGE_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,7 +119,7 @@ public class NPCSettings {
|
||||
* @return <p>The message to use for displaying item cost</p>
|
||||
*/
|
||||
public String getCostMessage() {
|
||||
return asString(NPCSetting.COST_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.COST_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,7 +128,7 @@ public class NPCSettings {
|
||||
* @return <p>The invalid item message</p>
|
||||
*/
|
||||
public String getInvalidItemMessage() {
|
||||
return asString(NPCSetting.INVALID_ITEM_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.INVALID_ITEM_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,7 +137,7 @@ public class NPCSettings {
|
||||
* @return <p>The not damaged message</p>
|
||||
*/
|
||||
public String getNotDamagedMessage() {
|
||||
return asString(NPCSetting.NOT_DAMAGED_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.NOT_DAMAGED_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,7 +146,7 @@ public class NPCSettings {
|
||||
* @return <p>The start reforge message</p>
|
||||
*/
|
||||
public String getStartReforgeMessage() {
|
||||
return asString(NPCSetting.START_REFORGE_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.START_REFORGE_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,7 +155,7 @@ public class NPCSettings {
|
||||
* @return <p>The reforge success message</p>
|
||||
*/
|
||||
public String getSuccessMessage() {
|
||||
return asString(NPCSetting.SUCCESS_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.SUCCESS_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,7 +164,7 @@ public class NPCSettings {
|
||||
* @return <p>The reforge fail message</p>
|
||||
*/
|
||||
public String getFailMessage() {
|
||||
return asString(NPCSetting.FAIL_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.FAIL_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,7 +173,7 @@ public class NPCSettings {
|
||||
* @return <p>The insufficient funds message</p>
|
||||
*/
|
||||
public String getInsufficientFundsMessage() {
|
||||
return asString(NPCSetting.INSUFFICIENT_FUNDS_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.INSUFFICIENT_FUNDS_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,7 +182,7 @@ public class NPCSettings {
|
||||
* @return <p>The cool down unexpired message</p>
|
||||
*/
|
||||
public String getCoolDownUnexpiredMessage() {
|
||||
return asString(NPCSetting.COOL_DOWN_UNEXPIRED_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.COOL_DOWN_UNEXPIRED_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,7 +191,7 @@ public class NPCSettings {
|
||||
* @return <p>The item changed message</p>
|
||||
*/
|
||||
public String getItemChangedMessage() {
|
||||
return asString(NPCSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
|
||||
return asString(BlacksmithNPCSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,9 +202,9 @@ public class NPCSettings {
|
||||
* @return <p>All items reforge-able by this NPC</p>
|
||||
*/
|
||||
public List<Material> getReforgeAbleItems() {
|
||||
Object currentValue = currentValues.get(NPCSetting.REFORGE_ABLE_ITEMS);
|
||||
Object currentValue = currentValues.get(BlacksmithNPCSetting.REFORGE_ABLE_ITEMS);
|
||||
if (currentValue == null || String.valueOf(currentValue).isEmpty()) {
|
||||
return globalSettings.getReforgeAbleItems();
|
||||
return globalBlacksmithSettings.getReforgeAbleItems();
|
||||
} else {
|
||||
return new ArrayList<>(this.reforgeAbleItems);
|
||||
}
|
||||
@ -214,9 +216,9 @@ public class NPCSettings {
|
||||
* @return <p>The list of blocked enchantments</p>
|
||||
*/
|
||||
public List<Enchantment> getEnchantmentBlocklist() {
|
||||
Object currentValue = currentValues.get(NPCSetting.ENCHANTMENT_BLOCKLIST);
|
||||
Object currentValue = currentValues.get(BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST);
|
||||
if (currentValue == null || String.valueOf(currentValue).isEmpty()) {
|
||||
return globalSettings.getEnchantmentBlocklist();
|
||||
return globalBlacksmithSettings.getEnchantmentBlocklist();
|
||||
} else {
|
||||
return new ArrayList<>(this.enchantmentBlocklist);
|
||||
}
|
||||
@ -228,7 +230,7 @@ public class NPCSettings {
|
||||
* @return <p>The minimum reforge delay</p>
|
||||
*/
|
||||
public int getMinReforgeDelay() {
|
||||
return asInt(NPCSetting.MIN_REFORGE_DELAY);
|
||||
return asInt(BlacksmithNPCSetting.MIN_REFORGE_DELAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -237,7 +239,7 @@ public class NPCSettings {
|
||||
* @return <p>The maximum reforge delay</p>
|
||||
*/
|
||||
public int getMaxReforgeDelay() {
|
||||
return asInt(NPCSetting.MAX_REFORGE_DELAY);
|
||||
return asInt(BlacksmithNPCSetting.MAX_REFORGE_DELAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -246,7 +248,7 @@ public class NPCSettings {
|
||||
* @return <p>The reforge cool-down</p>
|
||||
*/
|
||||
public int getReforgeCoolDown() {
|
||||
return asInt(NPCSetting.REFORGE_COOL_DOWN);
|
||||
return asInt(BlacksmithNPCSetting.REFORGE_COOL_DOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -255,7 +257,7 @@ public class NPCSettings {
|
||||
* @return <p>The fail chance</p>
|
||||
*/
|
||||
public int getFailChance() {
|
||||
return asInt(NPCSetting.FAIL_CHANCE);
|
||||
return asInt(BlacksmithNPCSetting.FAIL_CHANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,7 +266,7 @@ public class NPCSettings {
|
||||
* @return <p>Whether enchantments should be removed</p>
|
||||
*/
|
||||
public boolean getFailRemovesEnchantments() {
|
||||
return asBoolean(NPCSetting.FAIL_REMOVE_ENCHANTMENTS);
|
||||
return asBoolean(BlacksmithNPCSetting.FAIL_REMOVE_ENCHANTMENTS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -273,7 +275,7 @@ public class NPCSettings {
|
||||
* @return <p>The extra enchantment chance</p>
|
||||
*/
|
||||
public int getExtraEnchantmentChance() {
|
||||
return asInt(NPCSetting.EXTRA_ENCHANTMENT_CHANCE);
|
||||
return asInt(BlacksmithNPCSetting.EXTRA_ENCHANTMENT_CHANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -282,7 +284,7 @@ public class NPCSettings {
|
||||
* @return <p>The maximum enchantments</p>
|
||||
*/
|
||||
public int getMaxEnchantments() {
|
||||
return asInt(NPCSetting.MAX_ENCHANTMENTS);
|
||||
return asInt(BlacksmithNPCSetting.MAX_ENCHANTMENTS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,7 +293,7 @@ public class NPCSettings {
|
||||
* @return <p>Whether to drop reforged items on the ground</p>
|
||||
*/
|
||||
public boolean getDropItem() {
|
||||
return asBoolean(NPCSetting.DROP_ITEM);
|
||||
return asBoolean(BlacksmithNPCSetting.DROP_ITEM);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -300,7 +302,7 @@ public class NPCSettings {
|
||||
* @return <p>The title of the blacksmith</p>
|
||||
*/
|
||||
public String getBlacksmithTitle() {
|
||||
return asString(NPCSetting.BLACKSMITH_TITLE);
|
||||
return asString(BlacksmithNPCSetting.BLACKSMITH_TITLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,7 +311,7 @@ public class NPCSettings {
|
||||
* @return <p>Whether to disable the reforge-cool-down</p>
|
||||
*/
|
||||
public boolean getDisableCoolDown() {
|
||||
return asInt(NPCSetting.REFORGE_COOL_DOWN) <= 0;
|
||||
return asInt(BlacksmithNPCSetting.REFORGE_COOL_DOWN) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -318,7 +320,7 @@ public class NPCSettings {
|
||||
* @return <p>Whether to disable the reforge delay</p>
|
||||
*/
|
||||
public boolean getDisableDelay() {
|
||||
return asInt(NPCSetting.MAX_REFORGE_DELAY) <= 0;
|
||||
return asInt(BlacksmithNPCSetting.MAX_REFORGE_DELAY) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,7 +329,7 @@ public class NPCSettings {
|
||||
* @return <p>True if this blacksmith is able to repair anvils</p>
|
||||
*/
|
||||
public boolean getRepairAnvils() {
|
||||
return asBoolean(NPCSetting.REPAIR_ANVILS);
|
||||
return asBoolean(BlacksmithNPCSetting.REPAIR_ANVILS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -338,7 +340,7 @@ public class NPCSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as an integer</p>
|
||||
*/
|
||||
private int asInt(NPCSetting setting) {
|
||||
private int asInt(BlacksmithNPCSetting setting) {
|
||||
return ConfigHelper.asInt(getValue(setting));
|
||||
}
|
||||
|
||||
@ -348,7 +350,7 @@ public class NPCSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as a string</p>
|
||||
*/
|
||||
private String asString(NPCSetting setting) {
|
||||
private String asString(BlacksmithNPCSetting setting) {
|
||||
return getValue(setting).toString();
|
||||
}
|
||||
|
||||
@ -358,7 +360,7 @@ public class NPCSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as a boolean</p>
|
||||
*/
|
||||
private boolean asBoolean(NPCSetting setting) {
|
||||
private boolean asBoolean(BlacksmithNPCSetting setting) {
|
||||
return ConfigHelper.asBoolean(getValue(setting));
|
||||
}
|
||||
|
||||
@ -368,11 +370,11 @@ public class NPCSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The current value</p>
|
||||
*/
|
||||
private Object getValue(NPCSetting setting) {
|
||||
private Object getValue(BlacksmithNPCSetting setting) {
|
||||
Object value = currentValues.get(setting);
|
||||
//If not set, use the default value from the config.yml file
|
||||
if (value == null) {
|
||||
Map<NPCSetting, Object> defaultNPCSettings = globalSettings.getDefaultNPCSettings();
|
||||
Map<BlacksmithNPCSetting, Object> defaultNPCSettings = globalBlacksmithSettings.getDefaultNPCSettings();
|
||||
if (defaultNPCSettings.containsKey(setting)) {
|
||||
value = defaultNPCSettings.get(setting);
|
||||
}
|
||||
@ -412,7 +414,7 @@ public class NPCSettings {
|
||||
private void updateEnchantmentBlocklist() {
|
||||
this.enchantmentBlocklist.clear();
|
||||
this.enchantmentBlocklist.addAll(getEnchantmentBlocklist(ConfigHelper.asStringList(getValue(
|
||||
NPCSetting.ENCHANTMENT_BLOCKLIST))));
|
||||
BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST))));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -446,7 +448,7 @@ public class NPCSettings {
|
||||
private void updateReforgeAbleItems() {
|
||||
this.reforgeAbleItems.clear();
|
||||
this.reforgeAbleItems.addAll(getReforgeAbleItems(ConfigHelper.asStringList(getValue(
|
||||
NPCSetting.REFORGE_ABLE_ITEMS))));
|
||||
BlacksmithNPCSetting.REFORGE_ABLE_ITEMS))));
|
||||
}
|
||||
|
||||
/**
|
@ -1,8 +1,10 @@
|
||||
package net.knarcraft.blacksmith.config;
|
||||
package net.knarcraft.blacksmith.config.blacksmith;
|
||||
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum GlobalSetting {
|
||||
public enum GlobalBlacksmithSetting {
|
||||
|
||||
/**
|
||||
* The base price for repairing, regardless of durability
|
||||
@ -65,7 +67,7 @@ public enum GlobalSetting {
|
||||
* @param value <p>The default value of this setting</p>
|
||||
* @param commandName <p>The name of the command used to change this setting</p>
|
||||
*/
|
||||
GlobalSetting(String path, SettingValueType valueType, Object value, String commandName) {
|
||||
GlobalBlacksmithSetting(String path, SettingValueType valueType, Object value, String commandName) {
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.commandName = commandName;
|
@ -1,8 +1,9 @@
|
||||
package net.knarcraft.blacksmith.config;
|
||||
package net.knarcraft.blacksmith.config.blacksmith;
|
||||
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.YamlStorage;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
@ -19,15 +20,15 @@ import java.util.logging.Level;
|
||||
/**
|
||||
* A class which keeps track of all default NPC settings and all global settings
|
||||
*/
|
||||
public class GlobalSettings {
|
||||
public class GlobalBlacksmithSettings {
|
||||
|
||||
private final Map<Material, Double> materialBasePrices = new HashMap<>();
|
||||
private final Map<Material, Double> materialPricePerDurabilityPoints = new HashMap<>();
|
||||
private final Map<Enchantment, Double> enchantmentCosts = new HashMap<>();
|
||||
private final Map<NPCSetting, Object> defaultNPCSettings = new HashMap<>();
|
||||
private final Map<BlacksmithNPCSetting, Object> defaultNPCSettings = new HashMap<>();
|
||||
private final List<Material> defaultReforgeAbleMaterials = new ArrayList<>();
|
||||
private final List<Enchantment> defaultEnchantmentBlocklist = new ArrayList<>();
|
||||
private final Map<GlobalSetting, Object> globalSettings = new HashMap<>();
|
||||
private final Map<GlobalBlacksmithSetting, Object> globalSettings = new HashMap<>();
|
||||
|
||||
private final YamlStorage defaultConfig;
|
||||
|
||||
@ -36,7 +37,7 @@ public class GlobalSettings {
|
||||
*
|
||||
* @param plugin <p>A reference to the blacksmith plugin</p>
|
||||
*/
|
||||
public GlobalSettings(BlacksmithPlugin plugin) {
|
||||
public GlobalBlacksmithSettings(BlacksmithPlugin plugin) {
|
||||
defaultConfig = new YamlStorage(new File(plugin.getDataFolder() + File.separator + "config.yml"),
|
||||
"Blacksmith Configuration\nWarning: The values under defaults are the values set for a " +
|
||||
"blacksmith upon creation. To change any values for existing NPCs, edit the citizens NPC file.");
|
||||
@ -70,32 +71,32 @@ public class GlobalSettings {
|
||||
/**
|
||||
* Changes the value of the given setting
|
||||
*
|
||||
* @param globalSetting <p>The global setting to change</p>
|
||||
* @param globalBlacksmithSetting <p>The global setting to change</p>
|
||||
* @param newValue <p>The new value of the setting</p>
|
||||
*/
|
||||
public void changeValue(GlobalSetting globalSetting, Object newValue) {
|
||||
globalSettings.put(globalSetting, newValue);
|
||||
public void changeValue(GlobalBlacksmithSetting globalBlacksmithSetting, Object newValue) {
|
||||
globalSettings.put(globalBlacksmithSetting, newValue);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the value of the given setting
|
||||
*
|
||||
* @param npcSetting <p>The default NPC setting to change</p>
|
||||
* @param blacksmithNpcSetting <p>The default NPC setting to change</p>
|
||||
* @param newValue <p>The new value for the setting</p>
|
||||
*/
|
||||
public void changeValue(NPCSetting npcSetting, Object newValue) {
|
||||
if (npcSetting.getValueType() == SettingValueType.STRING_LIST ||
|
||||
npcSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
|
||||
public void changeValue(BlacksmithNPCSetting blacksmithNpcSetting, Object newValue) {
|
||||
if (blacksmithNpcSetting.getValueType() == SettingValueType.STRING_LIST ||
|
||||
blacksmithNpcSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
|
||||
//Workaround to make sure it's treated as the correct type
|
||||
defaultNPCSettings.put(npcSetting, newValue == null ? null : ConfigHelper.asStringList(newValue));
|
||||
defaultNPCSettings.put(blacksmithNpcSetting, newValue == null ? null : ConfigHelper.asStringList(newValue));
|
||||
} else {
|
||||
defaultNPCSettings.put(npcSetting, newValue);
|
||||
defaultNPCSettings.put(blacksmithNpcSetting, newValue);
|
||||
}
|
||||
save();
|
||||
if (npcSetting == NPCSetting.REFORGE_ABLE_ITEMS) {
|
||||
if (blacksmithNpcSetting == BlacksmithNPCSetting.REFORGE_ABLE_ITEMS) {
|
||||
loadReforgeAbleItems();
|
||||
} else if (npcSetting == NPCSetting.ENCHANTMENT_BLOCKLIST) {
|
||||
} else if (blacksmithNpcSetting == BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST) {
|
||||
loadEnchantmentBlocklist();
|
||||
}
|
||||
}
|
||||
@ -103,21 +104,21 @@ public class GlobalSettings {
|
||||
/**
|
||||
* Gets the current raw value of the given global setting
|
||||
*
|
||||
* @param globalSetting <p>The setting to get</p>
|
||||
* @param globalBlacksmithSetting <p>The setting to get</p>
|
||||
* @return <p>The current raw setting value</p>
|
||||
*/
|
||||
public Object getRawValue(GlobalSetting globalSetting) {
|
||||
return globalSettings.get(globalSetting);
|
||||
public Object getRawValue(GlobalBlacksmithSetting globalBlacksmithSetting) {
|
||||
return globalSettings.get(globalBlacksmithSetting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current raw value of the given default NPC setting
|
||||
*
|
||||
* @param npcSetting <p>The setting to get</p>
|
||||
* @param blacksmithNpcSetting <p>The setting to get</p>
|
||||
* @return <p>The current raw setting value</p>
|
||||
*/
|
||||
public Object getRawValue(NPCSetting npcSetting) {
|
||||
return defaultNPCSettings.get(npcSetting);
|
||||
public Object getRawValue(BlacksmithNPCSetting blacksmithNpcSetting) {
|
||||
return defaultNPCSettings.get(blacksmithNpcSetting);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,7 +132,7 @@ public class GlobalSettings {
|
||||
if (newEnchantmentCost < 0) {
|
||||
throw new IllegalArgumentException("Enchantment cost cannot be negative!");
|
||||
}
|
||||
globalSettings.put(GlobalSetting.ENCHANTMENT_COST, newEnchantmentCost);
|
||||
globalSettings.put(GlobalBlacksmithSetting.ENCHANTMENT_COST, newEnchantmentCost);
|
||||
} else {
|
||||
if (newEnchantmentCost < 0) {
|
||||
enchantmentCosts.put(enchantment, null);
|
||||
@ -153,7 +154,7 @@ public class GlobalSettings {
|
||||
if (newPrice < 0) {
|
||||
throw new IllegalArgumentException("Price per durability point cannot be negative!");
|
||||
}
|
||||
globalSettings.put(GlobalSetting.PRICE_PER_DURABILITY_POINT, newPrice);
|
||||
globalSettings.put(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT, newPrice);
|
||||
} else {
|
||||
//Use a negative price to unset the per-item value
|
||||
if (newPrice < 0) {
|
||||
@ -176,7 +177,7 @@ public class GlobalSettings {
|
||||
if (newBasePrice < 0) {
|
||||
throw new IllegalArgumentException("Base price cannot be negative!");
|
||||
}
|
||||
globalSettings.put(GlobalSetting.BASE_PRICE, newBasePrice);
|
||||
globalSettings.put(GlobalBlacksmithSetting.BASE_PRICE, newBasePrice);
|
||||
} else {
|
||||
//Use a negative price to unset the per-item value
|
||||
if (newBasePrice < 0) {
|
||||
@ -193,7 +194,7 @@ public class GlobalSettings {
|
||||
*
|
||||
* @return <p>The current value of the default NPC settings</p>
|
||||
*/
|
||||
public Map<NPCSetting, Object> getDefaultNPCSettings() {
|
||||
public Map<BlacksmithNPCSetting, Object> getDefaultNPCSettings() {
|
||||
return new HashMap<>(this.defaultNPCSettings);
|
||||
}
|
||||
|
||||
@ -206,7 +207,7 @@ public class GlobalSettings {
|
||||
* @return <p>Whether to use natural cost</p>
|
||||
*/
|
||||
public boolean getUseNaturalCost() {
|
||||
return asBoolean(GlobalSetting.NATURAL_COST);
|
||||
return asBoolean(GlobalBlacksmithSetting.NATURAL_COST);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,7 +216,7 @@ public class GlobalSettings {
|
||||
* @return <p>Whether to show exact time</p>
|
||||
*/
|
||||
public boolean getShowExactTime() {
|
||||
return asBoolean(GlobalSetting.SHOW_EXACT_TIME);
|
||||
return asBoolean(GlobalBlacksmithSetting.SHOW_EXACT_TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,7 +229,7 @@ public class GlobalSettings {
|
||||
if (materialBasePrices.containsKey(material) && materialBasePrices.get(material) != null) {
|
||||
return materialBasePrices.get(material);
|
||||
} else {
|
||||
return asDouble(GlobalSetting.BASE_PRICE);
|
||||
return asDouble(GlobalBlacksmithSetting.BASE_PRICE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +244,7 @@ public class GlobalSettings {
|
||||
materialPricePerDurabilityPoints.get(material) != null) {
|
||||
return materialPricePerDurabilityPoints.get(material);
|
||||
} else {
|
||||
return asDouble(GlobalSetting.PRICE_PER_DURABILITY_POINT);
|
||||
return asDouble(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,7 +258,7 @@ public class GlobalSettings {
|
||||
if (enchantmentCosts.containsKey(enchantment) && enchantmentCosts.get(enchantment) != null) {
|
||||
return enchantmentCosts.get(enchantment);
|
||||
} else {
|
||||
return asDouble(GlobalSetting.ENCHANTMENT_COST);
|
||||
return asDouble(GlobalBlacksmithSetting.ENCHANTMENT_COST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -287,9 +288,9 @@ public class GlobalSettings {
|
||||
*/
|
||||
public double getAnvilCost(Material material) {
|
||||
if (material == Material.CHIPPED_ANVIL) {
|
||||
return asDouble(GlobalSetting.ANVIL_CHIPPED_COST);
|
||||
return asDouble(GlobalBlacksmithSetting.ANVIL_CHIPPED_COST);
|
||||
} else if (material == Material.DAMAGED_ANVIL) {
|
||||
return asDouble(GlobalSetting.ANVIL_DAMAGED_COST);
|
||||
return asDouble(GlobalBlacksmithSetting.ANVIL_DAMAGED_COST);
|
||||
} else {
|
||||
throw new IllegalArgumentException("An unexpected item was encountered!");
|
||||
}
|
||||
@ -303,7 +304,7 @@ public class GlobalSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as a boolean</p>
|
||||
*/
|
||||
public boolean asBoolean(GlobalSetting setting) {
|
||||
public boolean asBoolean(GlobalBlacksmithSetting setting) {
|
||||
return ConfigHelper.asBoolean(getValue(setting));
|
||||
}
|
||||
|
||||
@ -315,7 +316,7 @@ public class GlobalSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as a double</p>
|
||||
*/
|
||||
public double asDouble(GlobalSetting setting) {
|
||||
public double asDouble(GlobalBlacksmithSetting setting) {
|
||||
return ConfigHelper.asDouble(getValue(setting));
|
||||
}
|
||||
|
||||
@ -325,7 +326,7 @@ public class GlobalSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The current value</p>
|
||||
*/
|
||||
private Object getValue(GlobalSetting setting) {
|
||||
private Object getValue(GlobalBlacksmithSetting setting) {
|
||||
Object value = globalSettings.get(setting);
|
||||
//If not set in config.yml, use the default value from the enum
|
||||
if (value == null) {
|
||||
@ -340,13 +341,13 @@ public class GlobalSettings {
|
||||
* @param root <p>The root node of all global settings</p>
|
||||
*/
|
||||
private void loadGlobalSettings(DataKey root) {
|
||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||
if (!root.keyExists(globalSetting.getPath())) {
|
||||
for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) {
|
||||
if (!root.keyExists(globalBlacksmithSetting.getPath())) {
|
||||
//If the setting does not exist in the config file, add it
|
||||
root.setRaw(globalSetting.getPath(), globalSetting.getDefaultValue());
|
||||
root.setRaw(globalBlacksmithSetting.getPath(), globalBlacksmithSetting.getDefaultValue());
|
||||
} else {
|
||||
//Set the setting to the value found in the path
|
||||
globalSettings.put(globalSetting, root.getRaw(globalSetting.getPath()));
|
||||
globalSettings.put(globalBlacksmithSetting, root.getRaw(globalBlacksmithSetting.getPath()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -357,7 +358,7 @@ public class GlobalSettings {
|
||||
loadPricesPerDurabilityPoint(root);
|
||||
|
||||
//Load all enchantment prices
|
||||
DataKey enchantmentCostNode = root.getRelative(GlobalSetting.ENCHANTMENT_COST.getParent());
|
||||
DataKey enchantmentCostNode = root.getRelative(GlobalBlacksmithSetting.ENCHANTMENT_COST.getParent());
|
||||
Map<String, String> relevantKeys = getRelevantKeys(enchantmentCostNode);
|
||||
for (String key : relevantKeys.keySet()) {
|
||||
String enchantmentName = relevantKeys.get(key);
|
||||
@ -372,7 +373,7 @@ public class GlobalSettings {
|
||||
* @param root <p>The configuration root node to search from</p>
|
||||
*/
|
||||
private void loadPricesPerDurabilityPoint(DataKey root) {
|
||||
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalSetting.PRICE_PER_DURABILITY_POINT.getParent());
|
||||
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getParent());
|
||||
Map<String, String> relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
|
||||
|
||||
for (String key : relevantKeys.keySet()) {
|
||||
@ -394,7 +395,7 @@ public class GlobalSettings {
|
||||
* @param root <p>The configuration root node to search from</p>
|
||||
*/
|
||||
private void loadBasePrices(DataKey root) {
|
||||
DataKey basePriceNode = root.getRelative(GlobalSetting.BASE_PRICE.getParent());
|
||||
DataKey basePriceNode = root.getRelative(GlobalBlacksmithSetting.BASE_PRICE.getParent());
|
||||
Map<String, String> relevantKeys = getRelevantKeys(basePriceNode);
|
||||
|
||||
for (String key : relevantKeys.keySet()) {
|
||||
@ -479,7 +480,7 @@ public class GlobalSettings {
|
||||
* @param root <p>The root node of all default NPC settings</p>
|
||||
*/
|
||||
private void loadDefaultNPCSettings(DataKey root) {
|
||||
for (NPCSetting setting : NPCSetting.values()) {
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
if (!root.keyExists(setting.getPath())) {
|
||||
//If the setting does not exist in the config file, add it
|
||||
root.setRaw(setting.getPath(), setting.getDefaultValue());
|
||||
@ -497,8 +498,8 @@ public class GlobalSettings {
|
||||
*/
|
||||
private void loadReforgeAbleItems() {
|
||||
defaultReforgeAbleMaterials.clear();
|
||||
defaultReforgeAbleMaterials.addAll(NPCSettings.getReforgeAbleItems(ConfigHelper.asStringList(
|
||||
defaultNPCSettings.get(NPCSetting.REFORGE_ABLE_ITEMS))));
|
||||
defaultReforgeAbleMaterials.addAll(BlacksmithNPCSettings.getReforgeAbleItems(ConfigHelper.asStringList(
|
||||
defaultNPCSettings.get(BlacksmithNPCSetting.REFORGE_ABLE_ITEMS))));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -506,8 +507,8 @@ public class GlobalSettings {
|
||||
*/
|
||||
private void loadEnchantmentBlocklist() {
|
||||
defaultEnchantmentBlocklist.clear();
|
||||
defaultEnchantmentBlocklist.addAll(NPCSettings.getEnchantmentBlocklist(ConfigHelper.asStringList(
|
||||
defaultNPCSettings.get(NPCSetting.ENCHANTMENT_BLOCKLIST))));
|
||||
defaultEnchantmentBlocklist.addAll(BlacksmithNPCSettings.getEnchantmentBlocklist(ConfigHelper.asStringList(
|
||||
defaultNPCSettings.get(BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST))));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -516,29 +517,29 @@ public class GlobalSettings {
|
||||
private void save() {
|
||||
DataKey root = defaultConfig.getKey("");
|
||||
//Save all default NPC settings
|
||||
for (NPCSetting setting : NPCSetting.values()) {
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
root.setRaw(setting.getPath(), defaultNPCSettings.get(setting));
|
||||
}
|
||||
|
||||
//Save all normal global settings
|
||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||
root.setRaw(globalSetting.getPath(), globalSettings.get(globalSetting));
|
||||
for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) {
|
||||
root.setRaw(globalBlacksmithSetting.getPath(), globalSettings.get(globalBlacksmithSetting));
|
||||
}
|
||||
|
||||
//Save all base prices
|
||||
DataKey basePriceNode = root.getRelative(GlobalSetting.BASE_PRICE.getParent());
|
||||
DataKey basePriceNode = root.getRelative(GlobalBlacksmithSetting.BASE_PRICE.getParent());
|
||||
for (Material material : materialBasePrices.keySet()) {
|
||||
basePriceNode.setRaw(unNormalizeName(material.name()), materialBasePrices.get(material));
|
||||
}
|
||||
|
||||
//Save all per-durability-point prices
|
||||
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalSetting.PRICE_PER_DURABILITY_POINT.getParent());
|
||||
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getParent());
|
||||
for (Material material : materialPricePerDurabilityPoints.keySet()) {
|
||||
basePerDurabilityPriceNode.setRaw(unNormalizeName(material.name()), materialPricePerDurabilityPoints.get(material));
|
||||
}
|
||||
|
||||
//Load all enchantment prices
|
||||
DataKey enchantmentCostNode = root.getRelative(GlobalSetting.ENCHANTMENT_COST.getParent());
|
||||
DataKey enchantmentCostNode = root.getRelative(GlobalBlacksmithSetting.ENCHANTMENT_COST.getParent());
|
||||
for (Enchantment enchantment : enchantmentCosts.keySet()) {
|
||||
enchantmentCostNode.setRaw(unNormalizeName(enchantment.getKey().getKey()), enchantmentCosts.get(enchantment));
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package net.knarcraft.blacksmith.config.scrapper;
|
||||
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
|
||||
public enum ScrapperNPCSetting implements NPCSetting {
|
||||
|
||||
/**
|
||||
* The setting for whether the NPC should drop an item to the ground when finished
|
||||
*
|
||||
* <p>If set to false, the item will be directly put in the player's inventory instead</p>
|
||||
*/
|
||||
DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "dropItem"),
|
||||
|
||||
/**
|
||||
* The chance of a scrapper returning no salvage, regardless of item condition
|
||||
*/
|
||||
FAIL_SALVAGE_CHANCE("failSalvageChance", SettingValueType.POSITIVE_DOUBLE, 0, "failSalvageChance"),
|
||||
|
||||
/**
|
||||
* The setting for which items a scrapper is able to salvage
|
||||
*/
|
||||
SALVAGE_ABLE_ITEMS("salvageAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "salvageAbleItems"),
|
||||
|
||||
/*-----------
|
||||
| Messages |
|
||||
-----------*/
|
||||
|
||||
/**
|
||||
* The message displayed when the scrapper is busy with another player
|
||||
*/
|
||||
BUSY_WITH_PLAYER_MESSAGE("messages.busyPlayerMessage", SettingValueType.STRING,
|
||||
"&cI'm busy at the moment. Come back later!", "busyPlayerMessage"),
|
||||
;
|
||||
|
||||
private final String path;
|
||||
private final String childPath;
|
||||
private final Object value;
|
||||
private final String commandName;
|
||||
private final SettingValueType valueType;
|
||||
|
||||
/**
|
||||
* Instantiates a new setting
|
||||
*
|
||||
* @param path <p>The full config path for this setting</p>
|
||||
* @param valueType <p>The type of value used by this setting</p>
|
||||
* @param value <p>The default value of this setting</p>
|
||||
* @param commandName <p>The name of the command used to change this setting</p>
|
||||
*/
|
||||
ScrapperNPCSetting(String path, SettingValueType valueType, Object value, String commandName) {
|
||||
this.path = "defaults." + path;
|
||||
this.value = value;
|
||||
this.valueType = valueType;
|
||||
this.childPath = path;
|
||||
this.commandName = commandName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChildPath() {
|
||||
return childPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefaultValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return commandName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SettingValueType getValueType() {
|
||||
return this.valueType;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package net.knarcraft.blacksmith.config.scrapper;
|
||||
|
||||
public class ScrapperNPCSettings {
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package net.knarcraft.blacksmith.manager;
|
||||
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.GlobalSettings;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Material;
|
||||
@ -89,15 +89,15 @@ public class EconomyManager {
|
||||
* @return <p>The cost of the repair</p>
|
||||
*/
|
||||
private static double getCost(ItemStack item) {
|
||||
GlobalSettings globalSettings = BlacksmithPlugin.getInstance().getSettings();
|
||||
GlobalBlacksmithSettings globalBlacksmithSettings = BlacksmithPlugin.getInstance().getSettings();
|
||||
Material material = item.getType();
|
||||
|
||||
//Calculate the base price
|
||||
double price = globalSettings.getBasePrice(material);
|
||||
double price = globalBlacksmithSettings.getBasePrice(material);
|
||||
|
||||
// Adjust price based on durability
|
||||
double pricePerDurabilityPoint = globalSettings.getPricePerDurabilityPoint(material);
|
||||
if (globalSettings.getUseNaturalCost()) {
|
||||
double pricePerDurabilityPoint = globalBlacksmithSettings.getPricePerDurabilityPoint(material);
|
||||
if (globalBlacksmithSettings.getUseNaturalCost()) {
|
||||
//Cost increases with damage
|
||||
price += ((double) ItemHelper.getDamage(item)) * pricePerDurabilityPoint;
|
||||
} else {
|
||||
@ -110,7 +110,7 @@ public class EconomyManager {
|
||||
|
||||
//Override the cost for anvils
|
||||
if (ItemHelper.isAnvil(material, true)) {
|
||||
price = globalSettings.getAnvilCost(material);
|
||||
price = globalBlacksmithSettings.getAnvilCost(material);
|
||||
}
|
||||
return price;
|
||||
}
|
||||
@ -122,7 +122,7 @@ public class EconomyManager {
|
||||
* @return <p>The resulting enchantment cost</p>
|
||||
*/
|
||||
private static double getEnchantmentCost(ItemStack item) {
|
||||
GlobalSettings settings = BlacksmithPlugin.getInstance().getSettings();
|
||||
GlobalBlacksmithSettings settings = BlacksmithPlugin.getInstance().getSettings();
|
||||
double price = 0;
|
||||
for (Enchantment enchantment : item.getEnchantments().keySet()) {
|
||||
price += settings.getEnchantmentCost(enchantment) * item.getEnchantmentLevel(enchantment);
|
||||
|
@ -4,7 +4,7 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.NPCSettings;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSettings;
|
||||
import net.knarcraft.blacksmith.formatting.TimeFormatter;
|
||||
import net.knarcraft.blacksmith.manager.EconomyManager;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
@ -31,7 +31,7 @@ public class BlacksmithTrait extends Trait {
|
||||
|
||||
private final Map<UUID, Calendar> coolDowns = new HashMap<>();
|
||||
private ReforgeSession session;
|
||||
private final NPCSettings config;
|
||||
private final BlacksmithNPCSettings config;
|
||||
private long _sessionStart = System.currentTimeMillis();
|
||||
|
||||
/**
|
||||
@ -41,7 +41,7 @@ public class BlacksmithTrait extends Trait {
|
||||
super("blacksmith");
|
||||
//This should crash if the blacksmith plugin hasn't been properly registered
|
||||
Bukkit.getServer().getPluginManager().getPlugin("Blacksmith");
|
||||
this.config = new NPCSettings(BlacksmithPlugin.getInstance().getSettings());
|
||||
this.config = new BlacksmithNPCSettings(BlacksmithPlugin.getInstance().getSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,7 +49,7 @@ public class BlacksmithTrait extends Trait {
|
||||
*
|
||||
* @return <p>The current settings for this NPC</p>
|
||||
*/
|
||||
public NPCSettings getSettings() {
|
||||
public BlacksmithNPCSettings getSettings() {
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package net.knarcraft.blacksmith.trait;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.NPCSettings;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSettings;
|
||||
import net.knarcraft.blacksmith.manager.EconomyManager;
|
||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
@ -33,7 +33,7 @@ public class ReforgeSession implements Runnable {
|
||||
private final ItemStack itemToReforge;
|
||||
private int taskId;
|
||||
private long finishTime = 0;
|
||||
private final NPCSettings config;
|
||||
private final BlacksmithNPCSettings config;
|
||||
private static final String[] enchantments = new String[Enchantment.values().length];
|
||||
private static final Random random = new Random();
|
||||
|
||||
@ -45,7 +45,7 @@ public class ReforgeSession implements Runnable {
|
||||
* @param npc <p>The Blacksmith NPC involved in the session</p>
|
||||
* @param config <p>The config to use for the session</p>
|
||||
*/
|
||||
ReforgeSession(BlacksmithTrait blacksmithTrait, Player player, NPC npc, NPCSettings config) {
|
||||
ReforgeSession(BlacksmithTrait blacksmithTrait, Player player, NPC npc, BlacksmithNPCSettings config) {
|
||||
this.blacksmithTrait = blacksmithTrait;
|
||||
this.player = player;
|
||||
this.npc = npc;
|
||||
|
@ -0,0 +1,17 @@
|
||||
package net.knarcraft.blacksmith.trait;
|
||||
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
|
||||
/**
|
||||
* The class representing a scrapper NPC trait
|
||||
*/
|
||||
public class ScrapperTrait extends Trait {
|
||||
|
||||
protected ScrapperTrait(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
//TODO: A scrapper will take items and turn them into the base ingredients
|
||||
//TODO: If an item is enchanted, give an appropriate amount of exp
|
||||
|
||||
}
|
@ -3,6 +3,8 @@
|
||||
# The language used for messages. Only "en" is supported
|
||||
language: en
|
||||
|
||||
# Settings for the blacksmith trait
|
||||
blacksmith:
|
||||
# The settings which apply to all Blacksmith NPCs. These can also be changed using the /blacksmithconfig command
|
||||
global:
|
||||
# The minimum price of each cost
|
||||
@ -112,6 +114,39 @@ defaults:
|
||||
# The message to display if a player is trying to reforge an item with full durability
|
||||
notDamagedMessage: "&cThat item is not in need of repair"
|
||||
|
||||
# Settings for the scrapper trait
|
||||
scrapper:
|
||||
# The settings which apply to all Scrapper NPCs. These can also be changed using the /scrapperconfig command
|
||||
global:
|
||||
# Exact time displays the exact number of seconds and minutes remaining as part of the scrapping cool-down and
|
||||
# scrapping delay messages, instead of just vaguely hinting at the remaining time.
|
||||
showExactTime: false
|
||||
|
||||
# Whether enchanted salvaged items should return some amount of exp upon salvage
|
||||
giveExperience: true
|
||||
# The settings which are set to any new scrapper NPC. To change any of these settings for an existing NPC, you must
|
||||
# change the Citizens NPC file, or use the /scrapper command
|
||||
defaults:
|
||||
# Whether the item will drop materials resulting from scrapping on the ground, instead of putting them into the user's inventory
|
||||
dropItems: true
|
||||
|
||||
# The chance to fail a salvage, thus destroying the item (0-100)
|
||||
failSalvageChance: 0
|
||||
|
||||
# The items a blacksmith is able to salvage. Setting this only allows NPCs to repair the listed items. This should be
|
||||
# set for each individual NPC, and should not be set here, unless you want to restrict NPCs which have not been set
|
||||
# up yet.
|
||||
salvageAbleItems: [ ]
|
||||
messages:
|
||||
# The message to display when another player is using the scrapper
|
||||
busyPlayerMessage: "&cI'm busy at the moment. Come back later!"
|
||||
|
||||
# The message to display when the blacksmith is working on the salvaging
|
||||
busySalvageMessage: "&cI'm working on it. Be patient! I'll finish {time}!"
|
||||
|
||||
# The message to display when the blacksmith is still on a cool-down from the previous re-forging
|
||||
coolDownUnexpiredMessage: "&cYou've already had your chance! Give me a break! I'll be ready {time}!"
|
||||
|
||||
# The message to display if the player tries to salvage an item the blacksmith cannot salvage
|
||||
cannotSalvageMessage: "&cI'm unable to salvage that item"
|
||||
|
||||
@ -120,3 +155,12 @@ defaults:
|
||||
|
||||
# The message to display when an item is successfully salvaged
|
||||
successSalvagedMessage: "&cThere you go!"
|
||||
|
||||
# The message to display when the blacksmith fails to reforge an item
|
||||
failSalvageMessage: "&cWhoops! The item broke! Maybe next time?"
|
||||
|
||||
# The message to display when presenting a different item than the one just evaluated
|
||||
itemChangedMessage: "&cThat's not the item you wanted to salvage before!"
|
||||
|
||||
# The message to display once the blacksmith starts re-forging
|
||||
startSalvageMessage: "&eOk, let's see what I can do..."
|
Loading…
Reference in New Issue
Block a user