Adds ability to display current value of blacksmith commands
This commit is contained in:
parent
f3169c9255
commit
3cfa7a2a0a
@ -21,42 +21,102 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||||
@NotNull String[] args) {
|
@NotNull String[] args) {
|
||||||
if (args.length > 0) {
|
if (args.length == 0) {
|
||||||
String commandName = args[0];
|
return false;
|
||||||
if (commandName.equalsIgnoreCase("reload")) {
|
}
|
||||||
return new ReloadCommand().onCommand(sender, command, label, args);
|
|
||||||
}
|
|
||||||
GlobalSettings settings = BlacksmithPlugin.getInstance().getSettings();
|
|
||||||
|
|
||||||
//Changing reforge-able items' default isn't recommended
|
String commandName = args[0];
|
||||||
if (commandName.equalsIgnoreCase(NPCSetting.REFORGE_ABLE_ITEMS.getCommandName())) {
|
if (commandName.equalsIgnoreCase("reload")) {
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "Changing reforge-able items globally will make every new " +
|
return new ReloadCommand().onCommand(sender, command, label, args);
|
||||||
"blacksmith unable to re-forge anything not in the list, unless it's changed for the " +
|
}
|
||||||
"individual NPC. If you really want to change this, change it manually.");
|
GlobalSettings settings = BlacksmithPlugin.getInstance().getSettings();
|
||||||
|
|
||||||
|
//Changing reforge-able items' default isn't recommended
|
||||||
|
if (commandName.equalsIgnoreCase(NPCSetting.REFORGE_ABLE_ITEMS.getCommandName())) {
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "Changing reforge-able items globally will make every new " +
|
||||||
|
"blacksmith unable to re-forge anything not in the list, unless it's changed for the " +
|
||||||
|
"individual NPC. If you really want to change this, change it manually.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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;
|
||||||
|
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;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length == 1) {
|
||||||
|
if (detectedGlobalSetting != null) {
|
||||||
|
sender.sendMessage(String.format("Current value of %s: %s", detectedGlobalSetting.getCommandName(),
|
||||||
|
settings.getRawValue(detectedGlobalSetting)));
|
||||||
|
} else if (detectedNPCSetting != null) {
|
||||||
|
sender.sendMessage(String.format("Current value of %s: %s", detectedNPCSetting.getCommandName(),
|
||||||
|
settings.getRawValue(detectedNPCSetting)));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else if (args.length == 2 && isSpecialCase(commandName)) {
|
||||||
|
return displaySpecialCaseValue(args[1], sender, detectedGlobalSetting, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateSpecialCase(settings, commandName, args)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detectedGlobalSetting != null) {
|
||||||
|
settings.changeValue(detectedGlobalSetting, args[1]);
|
||||||
|
return true;
|
||||||
|
} else if (detectedNPCSetting != null) {
|
||||||
|
settings.changeValue(detectedNPCSetting, args[1]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the current value of a special-case configuration value
|
||||||
|
*
|
||||||
|
* @param selector <p>The selector specifying which material/enchantment to display information about</p>
|
||||||
|
* @param sender <p>The sender to display the value to</p>
|
||||||
|
* @param setting <p>The setting to display</p>
|
||||||
|
* @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) {
|
||||||
|
Material material = Material.matchMaterial(selector);
|
||||||
|
if (material == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
sender.sendMessage(String.format("Current value of %s for material %s: %s", setting.getCommandName(),
|
||||||
if (args.length == 1) {
|
material, settings.getBasePrice(material)));
|
||||||
//TODO: Display the current value of the setting
|
return true;
|
||||||
} else if (args.length == 2 && isSpecialCase(commandName)) {
|
} else if (setting == GlobalSetting.PRICE_PER_DURABILITY_POINT) {
|
||||||
//TODO: Display the current value for the specified setting and material
|
Material material = Material.matchMaterial(selector);
|
||||||
|
if (material == null) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
sender.sendMessage(String.format("Current value of %s for material %s: %s", setting.getCommandName(),
|
||||||
if (isSpecialCase(settings, commandName, args)) {
|
material, settings.getPricePerDurabilityPoint(material)));
|
||||||
return true;
|
} else if (setting == GlobalSetting.ENCHANTMENT_COST) {
|
||||||
}
|
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(selector));
|
||||||
|
if (enchantment == null) {
|
||||||
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
return false;
|
||||||
if (commandName.equalsIgnoreCase(globalSetting.getCommandName())) {
|
|
||||||
settings.changeValue(globalSetting, args[1]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (NPCSetting npcSetting : NPCSetting.values()) {
|
|
||||||
if (commandName.equalsIgnoreCase(npcSetting.getCommandName())) {
|
|
||||||
settings.changeValue(npcSetting, args[1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
sender.sendMessage(String.format("Current value of %s for enchantment %s: %s", setting.getCommandName(),
|
||||||
|
enchantment, settings.getEnchantmentCost(enchantment)));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -74,26 +134,38 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether the command could be processed as one of the three special cases
|
* Updates a special-case configuration value if a special-case is encountered
|
||||||
*
|
*
|
||||||
* @param settings <p>The settings to modify</p>
|
* @param settings <p>The settings to modify</p>
|
||||||
* @param commandName <p>The sub-command the player specified</p>
|
* @param commandName <p>The sub-command the player specified</p>
|
||||||
* @param args <p>All arguments given</p>
|
* @param args <p>All arguments given</p>
|
||||||
* @return <p>True if already handled as a special case</p>
|
* @return <p>True if already handled as a special case</p>
|
||||||
*/
|
*/
|
||||||
private boolean isSpecialCase(GlobalSettings settings, String commandName, String[] args) {
|
private boolean updateSpecialCase(GlobalSettings settings, String commandName, String[] args) {
|
||||||
if (commandName.equalsIgnoreCase(GlobalSetting.BASE_PRICE.getCommandName())) {
|
if (commandName.equalsIgnoreCase(GlobalSetting.BASE_PRICE.getCommandName())) {
|
||||||
settings.setBasePrice(Material.matchMaterial(args[1]), Double.parseDouble(args[2]));
|
Material material = Material.matchMaterial(args[1]);
|
||||||
|
if (material == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
settings.setBasePrice(material, Double.parseDouble(args[2]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandName.equalsIgnoreCase(GlobalSetting.PRICE_PER_DURABILITY_POINT.getCommandName())) {
|
if (commandName.equalsIgnoreCase(GlobalSetting.PRICE_PER_DURABILITY_POINT.getCommandName())) {
|
||||||
settings.setPricePerDurabilityPoint(Material.matchMaterial(args[1]), Double.parseDouble(args[2]));
|
Material material = Material.matchMaterial(args[1]);
|
||||||
|
if (material == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
settings.setPricePerDurabilityPoint(material, Double.parseDouble(args[2]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandName.equalsIgnoreCase(GlobalSetting.ENCHANTMENT_COST.getCommandName())) {
|
if (commandName.equalsIgnoreCase(GlobalSetting.ENCHANTMENT_COST.getCommandName())) {
|
||||||
settings.setEnchantmentCost(Enchantment.getByKey(NamespacedKey.minecraft(args[1])), Double.parseDouble(args[2]));
|
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(args[1]));
|
||||||
|
if (enchantment == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
settings.setEnchantmentCost(enchantment, Double.parseDouble(args[2]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,26 @@ public class GlobalSettings {
|
|||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current raw value of the given global setting
|
||||||
|
*
|
||||||
|
* @param globalSetting <p>The setting to get</p>
|
||||||
|
* @return <p>The current raw setting value</p>
|
||||||
|
*/
|
||||||
|
public Object getRawValue(GlobalSetting globalSetting) {
|
||||||
|
return globalSettings.get(globalSetting);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current raw value of the given default NPC setting
|
||||||
|
*
|
||||||
|
* @param npcSetting <p>The setting to get</p>
|
||||||
|
* @return <p>The current raw setting value</p>
|
||||||
|
*/
|
||||||
|
public Object getRawValue(NPCSetting npcSetting) {
|
||||||
|
return defaultNPCSettings.get(npcSetting);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the enchantment cost for the given enchantment
|
* Sets the enchantment cost for the given enchantment
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user