Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
3c4394d6fa | |||
d0f4ff11b7 | |||
ee2b503886 | |||
89c1c4a56c | |||
012d1df099 | |||
10bfd29468 | |||
849e9d7a9d | |||
89d1f79f7d | |||
36e254c0df | |||
05440e66a0 | |||
4d740521f3 | |||
b38cfbe710 | |||
cc7d66f270 | |||
39e164c9c8 | |||
9f433cb0f1 | |||
64004e4267 | |||
3c677c18cb | |||
9b1480453b |
32
README.md
32
README.md
@ -19,6 +19,7 @@ fee. Costs are highly customizable.
|
|||||||
|
|
||||||
- Citizens2
|
- Citizens2
|
||||||
- Vault
|
- Vault
|
||||||
|
- Any Vault-supported Economy plugin
|
||||||
|
|
||||||
## Basic usage
|
## Basic usage
|
||||||
|
|
||||||
@ -55,18 +56,27 @@ In addition to just being able to repair items, blacksmiths have some random fea
|
|||||||
|
|
||||||
For /blacksmith and /blacksmithconfig, if a new value isn't specified, the current value is displayed instead.
|
For /blacksmith and /blacksmithconfig, if a new value isn't specified, the current value is displayed instead.
|
||||||
|
|
||||||
For /blacksmith, using "" or null as the value will clear a custom value, making the NPC use the default value set in
|
For /blacksmith, using -1 or null as the value will clear a custom value, making the NPC use the default value set in
|
||||||
the config instead. Additionally, every value overridden for an NPC will display a marker (default \[NPC]) when
|
the config instead. Additionally, every value overridden for an NPC will display a marker (default: \[NPC]) when
|
||||||
displaying the current value.
|
displaying the current value.
|
||||||
|
|
||||||
Note: basePrice, pricePerDurabilityPoint and enchantmentCost can be set like: `/blacksmithconfig option 4` or
|
Note: basePrice, pricePerDurabilityPoint and enchantmentCost can be set like: `/blacksmithconfig option 4` or
|
||||||
like `/blacksmithconfig option material/enchantment 4` depending on whether you are setting the default or an override
|
like `/blacksmithconfig option material/enchantment 4` depending on whether you are setting the default or an override
|
||||||
for a specific material/enchantment.
|
for a specific material/enchantment. For /blacksmithconfig <basePrice/pricePerDurabilityPoint/enchantmentCost> <
|
||||||
|
material/enchantment>, using -1 or null as the value will clear the cost for the specified material/enchantment, using
|
||||||
|
the default one instead.
|
||||||
|
|
||||||
### Presets and filters:
|
### Presets and filters:
|
||||||
|
|
||||||
Note: All of these can be used when specifying reforge-able items, such as "preset:weapon-smith:bow,preset:armor_smith:
|
Note: All of these can be used when specifying reforge-able items, such as
|
||||||
gold,PRESET:TOOL_SMITH,shield"
|
"preset:weapon-smith:bow,preset:armor_smith:gold,PRESET:TOOL_SMITH,shield"
|
||||||
|
|
||||||
|
The format of reforge-able items requires each preset/material to be separated by a comma. If specifying a preset
|
||||||
|
instead of a material, start by typing "preset:". Then you can type WEAPON_SMITH, ARMOR_SMITH or TOOL_SMITH. If you
|
||||||
|
want, you can add another colon and one of the filters supported by the preset. For example: "preset:WEAPON_SMITH:BOW"
|
||||||
|
to make the blacksmith only repair bows. You can use the same preset several times with different filters. For
|
||||||
|
example: "preset:ARMOR_SMITH:DIAMOND,preset:ARMOR_SMITH:NETHERITE" would allow the blacksmith to repair all diamond and
|
||||||
|
netherite armor.
|
||||||
|
|
||||||
All currently supported presets, and available filters for each preset:
|
All currently supported presets, and available filters for each preset:
|
||||||
|
|
||||||
@ -108,6 +118,12 @@ All currently supported presets, and available filters for each preset:
|
|||||||
|
|
||||||
## Configuration options
|
## Configuration options
|
||||||
|
|
||||||
|
### Plugin Options
|
||||||
|
|
||||||
|
| Key | Value type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| language | string | The language used for this plugin. Only "en" is supported, unless you add a custom language. |
|
||||||
|
|
||||||
### Global-only options
|
### Global-only options
|
||||||
|
|
||||||
| Key | Value type | Description |
|
| Key | Value type | Description |
|
||||||
@ -116,6 +132,7 @@ All currently supported presets, and available filters for each preset:
|
|||||||
| pricePerDurabilityPoint | positive decimal number | The price added for each durability point present/missing (depends on whether natural cost is set to true or false). Setting this without specifying a material sets the pricePerDurabilityPoint for any item the pricePerDurabilityPoint has not been set for. |
|
| pricePerDurabilityPoint | positive decimal number | The price added for each durability point present/missing (depends on whether natural cost is set to true or false). Setting this without specifying a material sets the pricePerDurabilityPoint for any item the pricePerDurabilityPoint has not been set for. |
|
||||||
| enchantmentCost | positive decimal number | The added cost for each level of an enchantment present on the item. The cost can be set for specific enchantments. Not specifying an enchantment sets the value for all enchantments without a set value.
|
| enchantmentCost | positive decimal number | The added cost for each level of an enchantment present on the item. The cost can be set for specific enchantments. Not specifying an enchantment sets the value for all enchantments without a set value.
|
||||||
| useNaturalCost | true/false | If true, each missing durability will add to the cost (price = basePrice + missingDurability * pricePerDurabilityPoint + enchantmentCost). If false, durability will be used to calculate the cost instead of missingDurability (this was the behavior before natural cost was added). |
|
| useNaturalCost | true/false | If true, each missing durability will add to the cost (price = basePrice + missingDurability * pricePerDurabilityPoint + enchantmentCost). If false, durability will be used to calculate the cost instead of missingDurability (this was the behavior before natural cost was added). |
|
||||||
|
| showExactTime | true/false | If true, blacksmiths will display exact time remaining in minutes and seconds, instead of vague expressions |
|
||||||
|
|
||||||
### Per-npc (with default values set in config.yml)
|
### Per-npc (with default values set in config.yml)
|
||||||
|
|
||||||
@ -132,7 +149,9 @@ All currently supported presets, and available filters for each preset:
|
|||||||
| maxReforgeDelay | 0-3600 | The maximum number of seconds a player needs to wait for an item to be repaired. |
|
| maxReforgeDelay | 0-3600 | The maximum number of seconds a player needs to wait for an item to be repaired. |
|
||||||
| minReforgeDelay | 0-3600 | The minimum number of seconds a player needs to wait for an item to be repaired. |
|
| minReforgeDelay | 0-3600 | The minimum number of seconds a player needs to wait for an item to be repaired. |
|
||||||
| reforgeCoolDown | 0-3600 | The cool-down, in seconds, a player has to wait between each time they use one specific blacksmith. |
|
| reforgeCoolDown | 0-3600 | The cool-down, in seconds, a player has to wait between each time they use one specific blacksmith. |
|
||||||
| reforgeAbleItems | DIAMOND_LEGGINGS,GOLD-pickaxe,bow, etc. | Specifies which items this blacksmith is able to reforge. If set to "" or null, all normally repairable items can be repaired. If set to a list of items, only the items specified can be repaired. Some presets have been included for ease of use. Use a preset by specifying "preset:sword-smith" instead of a material such as "gold-pickaxe". Available presets: SWORD_SMITH, WEAPON_SMITH, ARMOR_SMITH, TOOL_SMITH, RANGED_SMITH. |
|
| reforgeAbleItems | DIAMOND_LEGGINGS,GOLD-pickaxe,bow, etc. | Specifies which items this blacksmith is able to reforge. If set to "" or null, all normally repairable items can be repaired. If set to a list of items, only the items specified can be repaired. Some presets have been included for ease of use. Use a preset by specifying "preset:sword-smith" instead of a material such as "gold-pickaxe". |
|
||||||
|
| blacksmithTitle | text string | The title displayed as part of the message explaining that a blacksmith doesn't recognize a player's held item |
|
||||||
|
| enchantmentBlocklist | string list | A string list of all enchantments a blacksmith should not be allowed to add to items. |
|
||||||
|
|
||||||
#### Messages
|
#### Messages
|
||||||
|
|
||||||
@ -148,6 +167,7 @@ All currently supported presets, and available filters for each preset:
|
|||||||
| itemChangedMessage | The message displayed when a player changes their item after being shown the repair cost |
|
| itemChangedMessage | The message displayed when a player changes their item after being shown the repair cost |
|
||||||
| startReforgeMessage | The message displayed when a blacksmith starts reforging an item |
|
| startReforgeMessage | The message displayed when a blacksmith starts reforging an item |
|
||||||
| successMessage | The message displayed when a blacksmith successfully repairs an item |
|
| successMessage | The message displayed when a blacksmith successfully repairs an item |
|
||||||
|
| notDamagedMessage | The message displayed if a player tries to reforge an item with full durability |
|
||||||
|
|
||||||
## Language customization
|
## Language customization
|
||||||
|
|
||||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>net.knarcraft</groupId>
|
<groupId>net.knarcraft</groupId>
|
||||||
<artifactId>blacksmith</artifactId>
|
<artifactId>blacksmith</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.3-SNAPSHOT</version>
|
||||||
<name>Blacksmith</name>
|
<name>Blacksmith</name>
|
||||||
<description>Blacksmith Character for the CitizensAPI</description>
|
<description>Blacksmith Character for the CitizensAPI</description>
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ public class BlacksmithPlugin extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
public void reload() {
|
public void reload() {
|
||||||
config.load();
|
config.load();
|
||||||
|
this.reloadConfig();
|
||||||
|
Translator.loadLanguages(this.getConfig().getString("language", "en"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,7 +75,7 @@ public class BlacksmithPlugin extends JavaPlugin {
|
|||||||
config = new GlobalSettings(this);
|
config = new GlobalSettings(this);
|
||||||
config.load();
|
config.load();
|
||||||
|
|
||||||
Translator.loadLanguages("en");
|
Translator.loadLanguages(fileConfiguration.getString("language", "en"));
|
||||||
|
|
||||||
//Set up Vault integration
|
//Set up Vault integration
|
||||||
if (!setUpVault()) {
|
if (!setUpVault()) {
|
||||||
|
@ -11,7 +11,6 @@ import net.knarcraft.blacksmith.util.InputParsingHelper;
|
|||||||
import net.knarcraft.blacksmith.util.TypeValidationHelper;
|
import net.knarcraft.blacksmith.util.TypeValidationHelper;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -81,7 +80,14 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Change the value of the specified setting
|
//Change the value of the specified setting
|
||||||
return changeValue(args, detectedGlobalSetting, detectedNPCSetting, settings, sender);
|
if ((detectedGlobalSetting != null &&
|
||||||
|
TypeValidationHelper.isValid(detectedGlobalSetting.getValueType(), args[1], sender)) ||
|
||||||
|
(detectedNPCSetting != null &&
|
||||||
|
TypeValidationHelper.isValid(detectedNPCSetting.getValueType(), args[1], sender))) {
|
||||||
|
return changeValue(args, detectedGlobalSetting, detectedNPCSetting, settings, sender);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,7 +172,7 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
|||||||
private boolean displaySpecialCaseValue(String selector, CommandSender sender, GlobalSetting setting,
|
private boolean displaySpecialCaseValue(String selector, CommandSender sender, GlobalSetting setting,
|
||||||
GlobalSettings settings) {
|
GlobalSettings settings) {
|
||||||
if (setting == GlobalSetting.BASE_PRICE || setting == GlobalSetting.PRICE_PER_DURABILITY_POINT) {
|
if (setting == GlobalSetting.BASE_PRICE || setting == GlobalSetting.PRICE_PER_DURABILITY_POINT) {
|
||||||
Material material = Material.matchMaterial(selector);
|
Material material = InputParsingHelper.matchMaterial(selector);
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -176,16 +182,17 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
currentValue = String.valueOf(settings.getPricePerDurabilityPoint(material));
|
currentValue = String.valueOf(settings.getPricePerDurabilityPoint(material));
|
||||||
}
|
}
|
||||||
displaySuccessMessage(sender, TranslatableMessage.getItemCurrentValueMessage(setting.getCommandName(), ItemType.MATERIAL,
|
displaySuccessMessage(sender, TranslatableMessage.getItemCurrentValueMessage(setting.getCommandName(),
|
||||||
material.name(), currentValue));
|
ItemType.MATERIAL, material.name(), currentValue));
|
||||||
return true;
|
return true;
|
||||||
} else if (setting == GlobalSetting.ENCHANTMENT_COST) {
|
} else if (setting == GlobalSetting.ENCHANTMENT_COST) {
|
||||||
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(selector));
|
Enchantment enchantment = InputParsingHelper.matchEnchantment(selector);
|
||||||
if (enchantment == null) {
|
if (enchantment == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
displaySuccessMessage(sender, TranslatableMessage.getItemCurrentValueMessage(setting.getCommandName(), ItemType.ENCHANTMENT,
|
displaySuccessMessage(sender, TranslatableMessage.getItemCurrentValueMessage(setting.getCommandName(),
|
||||||
enchantment.toString(), String.valueOf(settings.getEnchantmentCost(enchantment))));
|
ItemType.ENCHANTMENT, enchantment.getKey().getKey(),
|
||||||
|
String.valueOf(settings.getEnchantmentCost(enchantment))));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -215,7 +222,9 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
|||||||
*/
|
*/
|
||||||
private boolean updateSpecialCase(GlobalSettings settings, GlobalSetting detectedGlobalSetting, String[] args,
|
private boolean updateSpecialCase(GlobalSettings settings, GlobalSetting detectedGlobalSetting, String[] args,
|
||||||
CommandSender sender) {
|
CommandSender sender) {
|
||||||
if (!TypeValidationHelper.isValid(SettingValueType.POSITIVE_DOUBLE, args[2], sender)) {
|
if (InputParsingHelper.isEmpty(args[2])) {
|
||||||
|
args[2] = "-1";
|
||||||
|
} else if (!TypeValidationHelper.isValid(SettingValueType.POSITIVE_DOUBLE, args[2], sender)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
double newPrice = Double.parseDouble(args[2]);
|
double newPrice = Double.parseDouble(args[2]);
|
||||||
@ -242,7 +251,7 @@ public class BlackSmithConfigCommand implements CommandExecutor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
itemType = ItemType.ENCHANTMENT;
|
itemType = ItemType.ENCHANTMENT;
|
||||||
itemChanged = enchantment.toString();
|
itemChanged = enchantment.getKey().getKey();
|
||||||
settings.setEnchantmentCost(enchantment, newPrice);
|
settings.setEnchantmentCost(enchantment, newPrice);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -3,6 +3,7 @@ package net.knarcraft.blacksmith.command;
|
|||||||
import net.knarcraft.blacksmith.config.GlobalSetting;
|
import net.knarcraft.blacksmith.config.GlobalSetting;
|
||||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||||
|
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
@ -28,6 +29,13 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
|||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Arguments: <setting> [new value/material or enchantment] []
|
||||||
|
|
||||||
|
//Prevent tab-completion when typing messages with spaces
|
||||||
|
if (skipCompletionForSpacedMessage(args) != null) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
List<String> availableCommands = new ArrayList<>();
|
List<String> availableCommands = new ArrayList<>();
|
||||||
availableCommands.add("reload");
|
availableCommands.add("reload");
|
||||||
@ -40,10 +48,60 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
|
|||||||
return filterMatchingContains(availableCommands, args[0]);
|
return filterMatchingContains(availableCommands, args[0]);
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
return tabCompleteCommandValues(args[0], args[1]);
|
return tabCompleteCommandValues(args[0], args[1]);
|
||||||
|
} else if (args.length == 3) {
|
||||||
|
//Get per-material tab completions, or return nothing if an invalid setting was specified
|
||||||
|
for (GlobalSetting globalSetting : GlobalSetting.values()) {
|
||||||
|
if (globalSetting.getCommandName().equalsIgnoreCase(args[0])) {
|
||||||
|
return getPerTypeTabCompletions(globalSetting, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether to tab-complete nothing because a message containing spaces is being written
|
||||||
|
*
|
||||||
|
* @param args <p>The arguments given by the user</p>
|
||||||
|
* @return <p>Null if not writing a spaced message</p>
|
||||||
|
*/
|
||||||
|
private List<String> skipCompletionForSpacedMessage(String[] args) {
|
||||||
|
if (args.length > 2) {
|
||||||
|
NPCSetting npcSetting = null;
|
||||||
|
for (NPCSetting setting : NPCSetting.values()) {
|
||||||
|
if (setting.getCommandName().equalsIgnoreCase(args[0])) {
|
||||||
|
npcSetting = setting;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (npcSetting != null && npcSetting.getPath().startsWith("defaults.messages")) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets tab-completions for a selected material or enchantment
|
||||||
|
*
|
||||||
|
* @param globalSetting <p>The global setting to get tab-completions for</p>
|
||||||
|
* @param args <p>The arguments given by the user</p>
|
||||||
|
* @return <p>The tab-completions to show to the user</p>
|
||||||
|
*/
|
||||||
|
private List<String> getPerTypeTabCompletions(GlobalSetting globalSetting, String[] args) {
|
||||||
|
//Display possible tab-completions only if a valid enchantment or material is provided
|
||||||
|
if (((globalSetting == GlobalSetting.BASE_PRICE ||
|
||||||
|
globalSetting == GlobalSetting.PRICE_PER_DURABILITY_POINT) &&
|
||||||
|
InputParsingHelper.matchMaterial(args[1]) != null) ||
|
||||||
|
(globalSetting == GlobalSetting.ENCHANTMENT_COST &&
|
||||||
|
InputParsingHelper.matchEnchantment(args[1]) != null)) {
|
||||||
|
return filterMatchingContains(getTabCompletions(globalSetting.getValueType()), args[2]);
|
||||||
|
} else {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tab completes the values available for the given command
|
* Tab completes the values available for the given command
|
||||||
*
|
*
|
||||||
|
@ -9,6 +9,7 @@ import net.knarcraft.blacksmith.formatting.StringFormatter;
|
|||||||
import net.knarcraft.blacksmith.formatting.TranslatableMessage;
|
import net.knarcraft.blacksmith.formatting.TranslatableMessage;
|
||||||
import net.knarcraft.blacksmith.formatting.Translator;
|
import net.knarcraft.blacksmith.formatting.Translator;
|
||||||
import net.knarcraft.blacksmith.trait.BlacksmithTrait;
|
import net.knarcraft.blacksmith.trait.BlacksmithTrait;
|
||||||
|
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||||
import net.knarcraft.blacksmith.util.TypeValidationHelper;
|
import net.knarcraft.blacksmith.util.TypeValidationHelper;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -72,7 +73,7 @@ public class BlackSmithEditCommand implements CommandExecutor {
|
|||||||
displayNPCSetting(blacksmithTrait, npcSetting, sender);
|
displayNPCSetting(blacksmithTrait, npcSetting, sender);
|
||||||
} else {
|
} else {
|
||||||
//If an empty value or null, clear the value instead of changing it
|
//If an empty value or null, clear the value instead of changing it
|
||||||
if (newValue.equalsIgnoreCase("null") || newValue.equals("\"\"") || newValue.trim().isEmpty()) {
|
if (InputParsingHelper.isEmpty(newValue)) {
|
||||||
newValue = null;
|
newValue = null;
|
||||||
} else {
|
} else {
|
||||||
//Abort if an invalid value is given
|
//Abort if an invalid value is given
|
||||||
@ -101,7 +102,7 @@ public class BlackSmithEditCommand implements CommandExecutor {
|
|||||||
*/
|
*/
|
||||||
private void displayNPCSetting(BlacksmithTrait blacksmithTrait, NPCSetting npcSetting, CommandSender sender) {
|
private void displayNPCSetting(BlacksmithTrait blacksmithTrait, NPCSetting npcSetting, CommandSender sender) {
|
||||||
String rawValue = String.valueOf(blacksmithTrait.getSettings().getRawValue(npcSetting));
|
String rawValue = String.valueOf(blacksmithTrait.getSettings().getRawValue(npcSetting));
|
||||||
if (rawValue == null || rawValue.trim().isEmpty() || rawValue.equalsIgnoreCase("null")) {
|
if (InputParsingHelper.isEmpty(rawValue)) {
|
||||||
//Display the default value, if no custom value has been specified
|
//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(npcSetting));
|
||||||
displaySuccessMessage(sender, getCurrentValueMessage(npcSetting.getCommandName(), rawValue));
|
displaySuccessMessage(sender, getCurrentValueMessage(npcSetting.getCommandName(), rawValue));
|
||||||
|
@ -4,8 +4,8 @@ import net.citizensnpcs.api.util.DataKey;
|
|||||||
import net.citizensnpcs.api.util.YamlStorage;
|
import net.citizensnpcs.api.util.YamlStorage;
|
||||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||||
|
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -81,7 +81,12 @@ public class GlobalSettings {
|
|||||||
* @param newValue <p>The new value for the setting</p>
|
* @param newValue <p>The new value for the setting</p>
|
||||||
*/
|
*/
|
||||||
public void changeValue(NPCSetting npcSetting, Object newValue) {
|
public void changeValue(NPCSetting npcSetting, Object newValue) {
|
||||||
defaultNPCSettings.put(npcSetting, newValue);
|
if (npcSetting.getValueType() == SettingValueType.STRING_LIST) {
|
||||||
|
//Workaround to make sure it's treated as the correct type
|
||||||
|
defaultNPCSettings.put(npcSetting, newValue == null ? null : ConfigHelper.asStringList(newValue));
|
||||||
|
} else {
|
||||||
|
defaultNPCSettings.put(npcSetting, newValue);
|
||||||
|
}
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,13 +117,17 @@ public class GlobalSettings {
|
|||||||
* @param newEnchantmentCost <p>The new enchantment cost</p>
|
* @param newEnchantmentCost <p>The new enchantment cost</p>
|
||||||
*/
|
*/
|
||||||
public void setEnchantmentCost(Enchantment enchantment, double newEnchantmentCost) {
|
public void setEnchantmentCost(Enchantment enchantment, double newEnchantmentCost) {
|
||||||
if (newEnchantmentCost < 0) {
|
|
||||||
throw new IllegalArgumentException("Enchantment cost cannot be negative!");
|
|
||||||
}
|
|
||||||
if (enchantment == null) {
|
if (enchantment == null) {
|
||||||
|
if (newEnchantmentCost < 0) {
|
||||||
|
throw new IllegalArgumentException("Enchantment cost cannot be negative!");
|
||||||
|
}
|
||||||
globalSettings.put(GlobalSetting.ENCHANTMENT_COST, newEnchantmentCost);
|
globalSettings.put(GlobalSetting.ENCHANTMENT_COST, newEnchantmentCost);
|
||||||
} else {
|
} else {
|
||||||
enchantmentCosts.put(enchantment, newEnchantmentCost);
|
if (newEnchantmentCost < 0) {
|
||||||
|
enchantmentCosts.put(enchantment, null);
|
||||||
|
} else {
|
||||||
|
enchantmentCosts.put(enchantment, newEnchantmentCost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
@ -130,13 +139,18 @@ public class GlobalSettings {
|
|||||||
* @param newPrice <p>The new price per durability point price</p>
|
* @param newPrice <p>The new price per durability point price</p>
|
||||||
*/
|
*/
|
||||||
public void setPricePerDurabilityPoint(Material material, double newPrice) {
|
public void setPricePerDurabilityPoint(Material material, double newPrice) {
|
||||||
if (newPrice < 0) {
|
|
||||||
throw new IllegalArgumentException("Price per durability point cannot be negative!");
|
|
||||||
}
|
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
|
if (newPrice < 0) {
|
||||||
|
throw new IllegalArgumentException("Price per durability point cannot be negative!");
|
||||||
|
}
|
||||||
globalSettings.put(GlobalSetting.PRICE_PER_DURABILITY_POINT, newPrice);
|
globalSettings.put(GlobalSetting.PRICE_PER_DURABILITY_POINT, newPrice);
|
||||||
} else {
|
} else {
|
||||||
materialPricePerDurabilityPoints.put(material, newPrice);
|
//Use a negative price to unset the per-item value
|
||||||
|
if (newPrice < 0) {
|
||||||
|
materialPricePerDurabilityPoints.put(material, null);
|
||||||
|
} else {
|
||||||
|
materialPricePerDurabilityPoints.put(material, newPrice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
@ -148,13 +162,18 @@ public class GlobalSettings {
|
|||||||
* @param newBasePrice <p>The new base price</p>
|
* @param newBasePrice <p>The new base price</p>
|
||||||
*/
|
*/
|
||||||
public void setBasePrice(Material material, double newBasePrice) {
|
public void setBasePrice(Material material, double newBasePrice) {
|
||||||
if (newBasePrice < 0) {
|
|
||||||
throw new IllegalArgumentException("Base price cannot be negative!");
|
|
||||||
}
|
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
|
if (newBasePrice < 0) {
|
||||||
|
throw new IllegalArgumentException("Base price cannot be negative!");
|
||||||
|
}
|
||||||
globalSettings.put(GlobalSetting.BASE_PRICE, newBasePrice);
|
globalSettings.put(GlobalSetting.BASE_PRICE, newBasePrice);
|
||||||
} else {
|
} else {
|
||||||
materialBasePrices.put(material, newBasePrice);
|
//Use a negative price to unset the per-item value
|
||||||
|
if (newBasePrice < 0) {
|
||||||
|
materialBasePrices.put(material, null);
|
||||||
|
} else {
|
||||||
|
materialBasePrices.put(material, newBasePrice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
@ -292,7 +311,7 @@ public class GlobalSettings {
|
|||||||
Map<String, String> relevantKeys = getRelevantKeys(basePriceNode);
|
Map<String, String> relevantKeys = getRelevantKeys(basePriceNode);
|
||||||
for (String key : relevantKeys.keySet()) {
|
for (String key : relevantKeys.keySet()) {
|
||||||
String materialName = relevantKeys.get(key);
|
String materialName = relevantKeys.get(key);
|
||||||
Material material = Material.matchMaterial(materialName);
|
Material material = InputParsingHelper.matchMaterial(materialName);
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
materialBasePrices.put(material, basePriceNode.getDouble(key));
|
materialBasePrices.put(material, basePriceNode.getDouble(key));
|
||||||
} else {
|
} else {
|
||||||
@ -306,7 +325,7 @@ public class GlobalSettings {
|
|||||||
relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
|
relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
|
||||||
for (String key : relevantKeys.keySet()) {
|
for (String key : relevantKeys.keySet()) {
|
||||||
String materialName = relevantKeys.get(key);
|
String materialName = relevantKeys.get(key);
|
||||||
Material material = Material.matchMaterial(materialName);
|
Material material = InputParsingHelper.matchMaterial(materialName);
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
materialPricePerDurabilityPoints.put(material, basePerDurabilityPriceNode.getDouble(key));
|
materialPricePerDurabilityPoints.put(material, basePerDurabilityPriceNode.getDouble(key));
|
||||||
} else {
|
} else {
|
||||||
@ -320,7 +339,7 @@ public class GlobalSettings {
|
|||||||
relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
|
relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
|
||||||
for (String key : relevantKeys.keySet()) {
|
for (String key : relevantKeys.keySet()) {
|
||||||
String enchantmentName = relevantKeys.get(key);
|
String enchantmentName = relevantKeys.get(key);
|
||||||
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantmentName));
|
Enchantment enchantment = InputParsingHelper.matchEnchantment(enchantmentName);
|
||||||
if (enchantment != null) {
|
if (enchantment != null) {
|
||||||
enchantmentCosts.put(enchantment, enchantmentCostNode.getDouble(key));
|
enchantmentCosts.put(enchantment, enchantmentCostNode.getDouble(key));
|
||||||
} else {
|
} else {
|
||||||
@ -407,7 +426,7 @@ public class GlobalSettings {
|
|||||||
//Load all enchantment prices
|
//Load all enchantment prices
|
||||||
DataKey enchantmentCostNode = root.getRelative(GlobalSetting.ENCHANTMENT_COST.getParent());
|
DataKey enchantmentCostNode = root.getRelative(GlobalSetting.ENCHANTMENT_COST.getParent());
|
||||||
for (Enchantment enchantment : enchantmentCosts.keySet()) {
|
for (Enchantment enchantment : enchantmentCosts.keySet()) {
|
||||||
enchantmentCostNode.setRaw(unNormalizeName(enchantment.getKey().toString()), enchantmentCosts.get(enchantment));
|
enchantmentCostNode.setRaw(unNormalizeName(enchantment.getKey().getKey()), enchantmentCosts.get(enchantment));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Perform the actual save to disk
|
//Perform the actual save to disk
|
||||||
|
@ -46,7 +46,7 @@ public enum NPCSetting {
|
|||||||
/**
|
/**
|
||||||
* The setting for which items the blacksmith is able to reforge
|
* The setting for which items the blacksmith is able to reforge
|
||||||
*/
|
*/
|
||||||
REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.STRING_LIST, new String[]{}, "reforgeAbleItems"),
|
REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "reforgeAbleItems"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The setting for the title used to display which kind of blacksmith the NPC is
|
* The setting for the title used to display which kind of blacksmith the NPC is
|
||||||
@ -56,6 +56,12 @@ public enum NPCSetting {
|
|||||||
*/
|
*/
|
||||||
BLACKSMITH_TITLE("blacksmithTitle", SettingValueType.STRING, "blacksmith", "blacksmithTitle"),
|
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"),
|
||||||
|
|
||||||
/*-----------
|
/*-----------
|
||||||
| Messages |
|
| Messages |
|
||||||
-----------*/
|
-----------*/
|
||||||
|
@ -4,7 +4,9 @@ import net.citizensnpcs.api.util.DataKey;
|
|||||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||||
import net.knarcraft.blacksmith.trait.BlacksmithTrait;
|
import net.knarcraft.blacksmith.trait.BlacksmithTrait;
|
||||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||||
|
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -19,6 +21,7 @@ import java.util.logging.Level;
|
|||||||
public class NPCSettings {
|
public class NPCSettings {
|
||||||
|
|
||||||
private final List<Material> reforgeAbleItems = new ArrayList<>();
|
private final List<Material> reforgeAbleItems = new ArrayList<>();
|
||||||
|
private final List<Enchantment> enchantmentBlocklist = new ArrayList<>();
|
||||||
private final Map<NPCSetting, Object> currentValues = new HashMap<>();
|
private final Map<NPCSetting, Object> currentValues = new HashMap<>();
|
||||||
private final GlobalSettings globalSettings;
|
private final GlobalSettings globalSettings;
|
||||||
|
|
||||||
@ -42,6 +45,7 @@ public class NPCSettings {
|
|||||||
}
|
}
|
||||||
//Updates the list of reforge-able items/materials
|
//Updates the list of reforge-able items/materials
|
||||||
updateReforgeAbleItems();
|
updateReforgeAbleItems();
|
||||||
|
updateEnchantmentBlocklist();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,10 +66,18 @@ public class NPCSettings {
|
|||||||
* @param newValue <p>The new value of the setting</p>
|
* @param newValue <p>The new value of the setting</p>
|
||||||
*/
|
*/
|
||||||
public void changeSetting(NPCSetting setting, Object newValue) {
|
public void changeSetting(NPCSetting setting, Object newValue) {
|
||||||
currentValues.put(setting, newValue);
|
if (setting.getValueType() == SettingValueType.STRING_LIST) {
|
||||||
|
//Workaround to make sure it's treated as the correct type
|
||||||
|
currentValues.put(setting, newValue == null ? null : ConfigHelper.asStringList(newValue));
|
||||||
|
} else {
|
||||||
|
currentValues.put(setting, newValue);
|
||||||
|
}
|
||||||
if (setting == NPCSetting.REFORGE_ABLE_ITEMS) {
|
if (setting == NPCSetting.REFORGE_ABLE_ITEMS) {
|
||||||
updateReforgeAbleItems();
|
updateReforgeAbleItems();
|
||||||
}
|
}
|
||||||
|
if (setting == NPCSetting.ENCHANTMENT_BLOCKLIST) {
|
||||||
|
updateEnchantmentBlocklist();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -185,7 +197,16 @@ public class NPCSettings {
|
|||||||
* @return <p>All items reforge-able by this NPC</p>
|
* @return <p>All items reforge-able by this NPC</p>
|
||||||
*/
|
*/
|
||||||
public List<Material> getReforgeAbleItems() {
|
public List<Material> getReforgeAbleItems() {
|
||||||
return new ArrayList<>(reforgeAbleItems);
|
return new ArrayList<>(this.reforgeAbleItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the list of blocked enchantments
|
||||||
|
*
|
||||||
|
* @return <p>The list of blocked enchantments</p>
|
||||||
|
*/
|
||||||
|
public List<Enchantment> getEnchantmentBlocklist() {
|
||||||
|
return new ArrayList<>(this.enchantmentBlocklist);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -347,6 +368,29 @@ public class NPCSettings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the list of blocked enchantments
|
||||||
|
*/
|
||||||
|
private void updateEnchantmentBlocklist() {
|
||||||
|
this.enchantmentBlocklist.clear();
|
||||||
|
List<String> newEnchantmentBlocklist = ConfigHelper.asStringList(getValue(NPCSetting.ENCHANTMENT_BLOCKLIST));
|
||||||
|
|
||||||
|
for (String item : newEnchantmentBlocklist) {
|
||||||
|
|
||||||
|
if (InputParsingHelper.isEmpty(item)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Enchantment enchantment = InputParsingHelper.matchEnchantment(item);
|
||||||
|
if (enchantment != null) {
|
||||||
|
this.enchantmentBlocklist.add(enchantment);
|
||||||
|
} else {
|
||||||
|
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Unable to verify " + item +
|
||||||
|
" as a valid enchantment");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the reforge-able items according to the current value of the setting
|
* Updates the reforge-able items according to the current value of the setting
|
||||||
*/
|
*/
|
||||||
@ -361,10 +405,10 @@ public class NPCSettings {
|
|||||||
newReforgeAbleItems = (String) replaceReforgeAblePresets(newReforgeAbleItems);
|
newReforgeAbleItems = (String) replaceReforgeAblePresets(newReforgeAbleItems);
|
||||||
|
|
||||||
for (String item : newReforgeAbleItems.split(",")) {
|
for (String item : newReforgeAbleItems.split(",")) {
|
||||||
if (item == null || item.trim().isEmpty() || item.equalsIgnoreCase("null")) {
|
if (InputParsingHelper.isEmpty(item)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Material material = Material.matchMaterial(item.replace('-', '_'));
|
Material material = InputParsingHelper.matchMaterial(item);
|
||||||
if (material != null && BlacksmithTrait.isRepairable(new ItemStack(material, 1))) {
|
if (material != null && BlacksmithTrait.isRepairable(new ItemStack(material, 1))) {
|
||||||
this.reforgeAbleItems.add(material);
|
this.reforgeAbleItems.add(material);
|
||||||
} else {
|
} else {
|
||||||
|
@ -43,6 +43,11 @@ public enum SettingValueType {
|
|||||||
/**
|
/**
|
||||||
* An enchantment
|
* An enchantment
|
||||||
*/
|
*/
|
||||||
ENCHANTMENT
|
ENCHANTMENT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A comma-separated list of reforge-able items
|
||||||
|
*/
|
||||||
|
REFORGE_ABLE_ITEMS,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ public final class TimeFormatter {
|
|||||||
String durationFormat = Translator.getTranslatedMessage(TranslatableMessage.DURATION_FORMAT);
|
String durationFormat = Translator.getTranslatedMessage(TranslatableMessage.DURATION_FORMAT);
|
||||||
durationFormat = replacePlaceholder(durationFormat, "{unit}",
|
durationFormat = replacePlaceholder(durationFormat, "{unit}",
|
||||||
Translator.getTranslatedMessage(translatableMessage));
|
Translator.getTranslatedMessage(translatableMessage));
|
||||||
return replacePlaceholder(durationFormat, "{duration}", castToInt ? String.valueOf((int) duration) :
|
return replacePlaceholder(durationFormat, "{time}", castToInt ? String.valueOf((int) duration) :
|
||||||
String.valueOf(duration));
|
String.valueOf(duration));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ public enum TimeInterval {
|
|||||||
/**
|
/**
|
||||||
* Less than 10 seconds left
|
* Less than 10 seconds left
|
||||||
*/
|
*/
|
||||||
INTERVAL_LESS_THAN_10_SECONDS("momentarily", 10),
|
INTERVAL_LESS_THAN_10_SECONDS("in just a moment", 10),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Less than 30 seconds left
|
* Less than 30 seconds left
|
||||||
|
@ -122,7 +122,7 @@ public class BlacksmithTrait extends Trait {
|
|||||||
if (coolDowns.get(playerId) != null) {
|
if (coolDowns.get(playerId) != null) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
if (!calendar.after(coolDowns.get(playerId))) {
|
if (!calendar.after(coolDowns.get(playerId))) {
|
||||||
int secondDifference = (int) ((calendar.getTimeInMillis() - coolDowns.get(playerId).getTimeInMillis()) * 1000);
|
int secondDifference = (int) (coolDowns.get(playerId).getTimeInMillis() - calendar.getTimeInMillis()) / 1000;
|
||||||
boolean exactTime = BlacksmithPlugin.getInstance().getSettings().getShowExactTime();
|
boolean exactTime = BlacksmithPlugin.getInstance().getSettings().getShowExactTime();
|
||||||
sendNPCMessage(this.npc, player, replacePlaceholder(config.getCoolDownUnexpiredMessage(),
|
sendNPCMessage(this.npc, player, replacePlaceholder(config.getCoolDownUnexpiredMessage(),
|
||||||
"{time}", TimeFormatter.formatTime(exactTime, secondDifference)));
|
"{time}", TimeFormatter.formatTime(exactTime, secondDifference)));
|
||||||
@ -133,8 +133,8 @@ public class BlacksmithTrait extends Trait {
|
|||||||
|
|
||||||
//If already in a session, but the player has failed to interact, and left the blacksmith, allow a new session
|
//If already in a session, but the player has failed to interact, and left the blacksmith, allow a new session
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
if (System.currentTimeMillis() > _sessionStart + 10 * 1000 &&
|
if (!session.isRunning() && (System.currentTimeMillis() > _sessionStart + 10 * 1000 ||
|
||||||
this.npc.getEntity().getLocation().distance(session.getPlayer().getLocation()) > 20) {
|
this.npc.getEntity().getLocation().distance(session.getPlayer().getLocation()) > 20)) {
|
||||||
session = null;
|
session = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ import net.citizensnpcs.api.npc.NPC;
|
|||||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||||
import net.knarcraft.blacksmith.config.NPCSettings;
|
import net.knarcraft.blacksmith.config.NPCSettings;
|
||||||
import net.knarcraft.blacksmith.manager.EconomyManager;
|
import net.knarcraft.blacksmith.manager.EconomyManager;
|
||||||
|
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -57,7 +57,7 @@ public class ReforgeSession implements Runnable {
|
|||||||
if (enchantments[0] == null) {
|
if (enchantments[0] == null) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Enchantment enchantment : Enchantment.values()) {
|
for (Enchantment enchantment : Enchantment.values()) {
|
||||||
enchantments[i++] = enchantment.getKey().toString();
|
enchantments[i++] = enchantment.getKey().getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,11 +140,18 @@ public class ReforgeSession implements Runnable {
|
|||||||
//Find usable enchantments first
|
//Find usable enchantments first
|
||||||
List<Enchantment> usableEnchantments = new ArrayList<>();
|
List<Enchantment> usableEnchantments = new ArrayList<>();
|
||||||
for (String enchantmentName : enchantments) {
|
for (String enchantmentName : enchantments) {
|
||||||
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.fromString(enchantmentName));
|
Enchantment enchantment = InputParsingHelper.matchEnchantment(enchantmentName);
|
||||||
if (enchantment != null && enchantment.canEnchantItem(itemToReforge)) {
|
if (enchantment != null && enchantment.canEnchantItem(itemToReforge)) {
|
||||||
usableEnchantments.add(enchantment);
|
usableEnchantments.add(enchantment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Remove any enchantments in the block list
|
||||||
|
usableEnchantments.removeAll(blacksmithTrait.getSettings().getEnchantmentBlocklist());
|
||||||
|
|
||||||
|
//In case all usable enchantments have been blocked, abort
|
||||||
|
if (usableEnchantments.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Choose a random enchantment
|
//Choose a random enchantment
|
||||||
Enchantment randomEnchantment = usableEnchantments.get(random.nextInt(usableEnchantments.size()));
|
Enchantment randomEnchantment = usableEnchantments.get(random.nextInt(usableEnchantments.size()));
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package net.knarcraft.blacksmith.util;
|
package net.knarcraft.blacksmith.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper class for getting an object value as the correct type
|
* A helper class for getting an object value as the correct type
|
||||||
*/
|
*/
|
||||||
@ -9,6 +12,25 @@ public final class ConfigHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the given value as a string list
|
||||||
|
*
|
||||||
|
* @param value <p>The raw string list value</p>
|
||||||
|
* @return <p>The value as a string list</p>
|
||||||
|
*/
|
||||||
|
public static List<String> asStringList(Object value) {
|
||||||
|
if (value instanceof String) {
|
||||||
|
return List.of(((String) value).split(","));
|
||||||
|
} else {
|
||||||
|
List<String> strings = new ArrayList<>();
|
||||||
|
List<?> list = (List<?>) value;
|
||||||
|
for (Object object : list) {
|
||||||
|
strings.add(String.valueOf(object));
|
||||||
|
}
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the given value as a double
|
* Gets the given value as a double
|
||||||
*
|
*
|
||||||
|
@ -13,6 +13,17 @@ public final class InputParsingHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether the input is an "empty" value treated as null
|
||||||
|
*
|
||||||
|
* @param input <p>The input to check</p>
|
||||||
|
* @return <p>True if the value is empty</p>
|
||||||
|
*/
|
||||||
|
public static boolean isEmpty(String input) {
|
||||||
|
return input == null || input.equalsIgnoreCase("null") || input.equals("\"\"") ||
|
||||||
|
input.trim().isEmpty() || input.equals("-1");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to find the material matching the given input string
|
* Tries to find the material matching the given input string
|
||||||
*
|
*
|
||||||
|
@ -32,12 +32,27 @@ public final class TabCompleteValuesHelper {
|
|||||||
case POSITIVE_DOUBLE -> getPositiveDoubles();
|
case POSITIVE_DOUBLE -> getPositiveDoubles();
|
||||||
case STRING -> getStrings();
|
case STRING -> getStrings();
|
||||||
case PERCENTAGE -> getPercentages();
|
case PERCENTAGE -> getPercentages();
|
||||||
case STRING_LIST -> getReforgeAbleMaterials();
|
case REFORGE_ABLE_ITEMS -> getReforgeAbleMaterials();
|
||||||
case MATERIAL -> getAllReforgeAbleMaterials();
|
case MATERIAL -> getAllReforgeAbleMaterials();
|
||||||
case ENCHANTMENT -> getAllEnchantments();
|
case ENCHANTMENT -> getAllEnchantments();
|
||||||
|
case STRING_LIST -> getExampleEnchantmentBlockLists();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets example enchantment block lists
|
||||||
|
*
|
||||||
|
* @return <p>Some example enchantment block lists</p>
|
||||||
|
*/
|
||||||
|
private static List<String> getExampleEnchantmentBlockLists() {
|
||||||
|
List<String> exampleBlockLists = new ArrayList<>();
|
||||||
|
exampleBlockLists.add(Enchantment.VANISHING_CURSE.getKey().getKey() + "," +
|
||||||
|
Enchantment.BINDING_CURSE.getKey().getKey() + "," + Enchantment.MENDING.getKey().getKey());
|
||||||
|
exampleBlockLists.add(Enchantment.VANISHING_CURSE.getKey().getKey() + "," +
|
||||||
|
Enchantment.BINDING_CURSE.getKey().getKey());
|
||||||
|
return exampleBlockLists;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a complete list of all reforge-able materials
|
* Gets a complete list of all reforge-able materials
|
||||||
*
|
*
|
||||||
@ -62,7 +77,7 @@ public final class TabCompleteValuesHelper {
|
|||||||
private static List<String> getAllEnchantments() {
|
private static List<String> getAllEnchantments() {
|
||||||
List<String> enchantments = new ArrayList<>();
|
List<String> enchantments = new ArrayList<>();
|
||||||
for (Enchantment enchantment : Enchantment.values()) {
|
for (Enchantment enchantment : Enchantment.values()) {
|
||||||
enchantments.add(enchantment.toString());
|
enchantments.add(enchantment.getKey().getKey());
|
||||||
}
|
}
|
||||||
return enchantments;
|
return enchantments;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import net.knarcraft.blacksmith.config.SettingValueType;
|
|||||||
import net.knarcraft.blacksmith.formatting.TranslatableMessage;
|
import net.knarcraft.blacksmith.formatting.TranslatableMessage;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static net.knarcraft.blacksmith.formatting.StringFormatter.displayErrorMessage;
|
import static net.knarcraft.blacksmith.formatting.StringFormatter.displayErrorMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,7 +33,7 @@ public final class TypeValidationHelper {
|
|||||||
case POSITIVE_INTEGER -> isPositiveInteger(value, sender);
|
case POSITIVE_INTEGER -> isPositiveInteger(value, sender);
|
||||||
case PERCENTAGE -> isPercentage(value, sender);
|
case PERCENTAGE -> isPercentage(value, sender);
|
||||||
case BOOLEAN -> true;
|
case BOOLEAN -> true;
|
||||||
case STRING_LIST -> isStringList(value, sender);
|
case STRING_LIST, REFORGE_ABLE_ITEMS -> isStringList(value, sender);
|
||||||
case MATERIAL, ENCHANTMENT -> false;
|
case MATERIAL, ENCHANTMENT -> false;
|
||||||
};
|
};
|
||||||
} catch (ClassCastException exception) {
|
} catch (ClassCastException exception) {
|
||||||
@ -48,7 +50,7 @@ public final class TypeValidationHelper {
|
|||||||
* @return <p>True if the value is a string list</p>
|
* @return <p>True if the value is a string list</p>
|
||||||
*/
|
*/
|
||||||
private static boolean isStringList(Object value, CommandSender sender) {
|
private static boolean isStringList(Object value, CommandSender sender) {
|
||||||
boolean isStringList = value instanceof String[] || value instanceof String;
|
boolean isStringList = value instanceof String[] || value instanceof List<?> || value instanceof String;
|
||||||
if (!isStringList && sender != null) {
|
if (!isStringList && sender != null) {
|
||||||
displayErrorMessage(sender, TranslatableMessage.INPUT_STRING_LIST_REQUIRED);
|
displayErrorMessage(sender, TranslatableMessage.INPUT_STRING_LIST_REQUIRED);
|
||||||
}
|
}
|
||||||
@ -65,7 +67,7 @@ public final class TypeValidationHelper {
|
|||||||
private static boolean isPercentage(Object value, CommandSender sender) {
|
private static boolean isPercentage(Object value, CommandSender sender) {
|
||||||
try {
|
try {
|
||||||
int intValue = ConfigHelper.asInt(value);
|
int intValue = ConfigHelper.asInt(value);
|
||||||
return intValue > 0 && intValue <= 100;
|
return intValue >= 0 && intValue <= 100;
|
||||||
} catch (NumberFormatException | NullPointerException exception) {
|
} catch (NumberFormatException | NullPointerException exception) {
|
||||||
if (sender != null) {
|
if (sender != null) {
|
||||||
displayErrorMessage(sender, TranslatableMessage.INPUT_PERCENTAGE_REQUIRED);
|
displayErrorMessage(sender, TranslatableMessage.INPUT_PERCENTAGE_REQUIRED);
|
||||||
@ -98,7 +100,7 @@ public final class TypeValidationHelper {
|
|||||||
*/
|
*/
|
||||||
private static boolean isPositiveDouble(Object value, CommandSender sender) {
|
private static boolean isPositiveDouble(Object value, CommandSender sender) {
|
||||||
try {
|
try {
|
||||||
return ConfigHelper.asDouble(value) > 0.0;
|
return ConfigHelper.asDouble(value) >= 0.0;
|
||||||
} catch (NumberFormatException | NullPointerException exception) {
|
} catch (NumberFormatException | NullPointerException exception) {
|
||||||
if (sender != null) {
|
if (sender != null) {
|
||||||
displayErrorMessage(sender, TranslatableMessage.INPUT_POSITIVE_DOUBLE_REQUIRED);
|
displayErrorMessage(sender, TranslatableMessage.INPUT_POSITIVE_DOUBLE_REQUIRED);
|
||||||
@ -116,7 +118,7 @@ public final class TypeValidationHelper {
|
|||||||
*/
|
*/
|
||||||
private static boolean isPositiveInteger(Object value, CommandSender sender) {
|
private static boolean isPositiveInteger(Object value, CommandSender sender) {
|
||||||
try {
|
try {
|
||||||
return ConfigHelper.asInt(value) > 0;
|
return ConfigHelper.asInt(value) >= 0;
|
||||||
} catch (NumberFormatException | NullPointerException exception) {
|
} catch (NumberFormatException | NullPointerException exception) {
|
||||||
if (sender != null) {
|
if (sender != null) {
|
||||||
displayErrorMessage(sender, TranslatableMessage.INPUT_POSITIVE_INTEGER_REQUIRED);
|
displayErrorMessage(sender, TranslatableMessage.INPUT_POSITIVE_INTEGER_REQUIRED);
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
# Blacksmith Configuration
|
# Blacksmith Configuration
|
||||||
|
|
||||||
|
# The language used for messages. Only "en" is supported
|
||||||
|
language: en
|
||||||
|
|
||||||
# The settings which apply to all Blacksmith NPCs. These can also be changed using the /blacksmithconfig command
|
# The settings which apply to all Blacksmith NPCs. These can also be changed using the /blacksmithconfig command
|
||||||
global:
|
global:
|
||||||
# The minimum price of each cost
|
# The minimum price of each cost
|
||||||
@ -36,6 +39,9 @@ defaults:
|
|||||||
# up yet.
|
# up yet.
|
||||||
reforgeAbleItems: [ ]
|
reforgeAbleItems: [ ]
|
||||||
|
|
||||||
|
# The enchantments a blacksmith is denied from applying to an item. Disable anything you find too op or annoying.
|
||||||
|
enchantmentBlocklist: [ "binding_curse", "mending", "vanishing_curse" ]
|
||||||
|
|
||||||
# The chance to fail reforging an item, which only repairs the item a tiny bit or not at all (0-100)
|
# The chance to fail reforging an item, which only repairs the item a tiny bit or not at all (0-100)
|
||||||
failReforgeChance: 10 # Default = 10%
|
failReforgeChance: 10 # Default = 10%
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: Blacksmith
|
name: Blacksmith
|
||||||
author: EpicKnarvik97, aPunch, jrbudda, HurricanKai
|
author: EpicKnarvik97, aPunch, jrbudda, HurricanKai
|
||||||
authors: [ EpicKnarvik97, aPunch, jrbudda, HurricanKai ]
|
authors: [ EpicKnarvik97, aPunch, jrbudda, HurricanKai ]
|
||||||
version: 1.0.0
|
version: 1.0.3
|
||||||
main: net.knarcraft.blacksmith.BlacksmithPlugin
|
main: net.knarcraft.blacksmith.BlacksmithPlugin
|
||||||
depend: [ Citizens, Vault ]
|
depend: [ Citizens, Vault ]
|
||||||
|
|
||||||
|
@ -18,13 +18,13 @@ en:
|
|||||||
INVALID_FILTER_FOR_PRESET: "The specified filter is not valid for that preset"
|
INVALID_FILTER_FOR_PRESET: "The specified filter is not valid for that preset"
|
||||||
INVALID_PRESET_OR_FILTER: "You specified an invalid preset or an invalid filter"
|
INVALID_PRESET_OR_FILTER: "You specified an invalid preset or an invalid filter"
|
||||||
PRESET_MATERIALS: "Materials in preset: {materials}"
|
PRESET_MATERIALS: "Materials in preset: {materials}"
|
||||||
DURATION_FORMAT: "{time} {unit}"
|
DURATION_FORMAT: "in {time} {unit}"
|
||||||
UNIT_NOW: "imminently"
|
UNIT_NOW: "imminently"
|
||||||
UNIT_SECOND: "second"
|
UNIT_SECOND: "second"
|
||||||
UNIT_SECONDS: "seconds"
|
UNIT_SECONDS: "seconds"
|
||||||
UNIT_MINUTE: "minute"
|
UNIT_MINUTE: "minute"
|
||||||
UNIT_MINUTES: "minutes"
|
UNIT_MINUTES: "minutes"
|
||||||
INTERVAL_LESS_THAN_10_SECONDS: "momentarily"
|
INTERVAL_LESS_THAN_10_SECONDS: "in just a moment"
|
||||||
INTERVAL_LESS_THAN_30_SECONDS: "in a little while"
|
INTERVAL_LESS_THAN_30_SECONDS: "in a little while"
|
||||||
INTERVAL_LESS_THAN_1_MINUTE: "in a while"
|
INTERVAL_LESS_THAN_1_MINUTE: "in a while"
|
||||||
INTERVAL_LESS_THAN_5_MINUTES: "after some time"
|
INTERVAL_LESS_THAN_5_MINUTES: "after some time"
|
||||||
|
Reference in New Issue
Block a user