Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
ee2b503886 | |||
89c1c4a56c | |||
012d1df099 | |||
10bfd29468 | |||
849e9d7a9d | |||
89d1f79f7d | |||
36e254c0df |
15
README.md
15
README.md
@ -19,6 +19,7 @@ fee. Costs are highly customizable.
|
||||
|
||||
- Citizens2
|
||||
- Vault
|
||||
- Any Vault-supported Economy plugin
|
||||
|
||||
## Basic usage
|
||||
|
||||
@ -67,8 +68,15 @@ the default one instead.
|
||||
|
||||
### Presets and filters:
|
||||
|
||||
Note: All of these can be used when specifying reforge-able items, such as "preset:weapon-smith:bow,preset:armor_smith:
|
||||
gold,PRESET:TOOL_SMITH,shield"
|
||||
Note: All of these can be used when specifying reforge-able items, such as
|
||||
"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:
|
||||
|
||||
@ -141,8 +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. |
|
||||
| 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. |
|
||||
| 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
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>blacksmith</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<version>1.0.2-SNAPSHOT</version>
|
||||
<name>Blacksmith</name>
|
||||
<description>Blacksmith Character for the CitizensAPI</description>
|
||||
|
||||
|
@ -81,7 +81,12 @@ public class GlobalSettings {
|
||||
* @param newValue <p>The new value for the setting</p>
|
||||
*/
|
||||
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, ConfigHelper.asStringList(newValue));
|
||||
} else {
|
||||
defaultNPCSettings.put(npcSetting, newValue);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public enum NPCSetting {
|
||||
/**
|
||||
* 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
|
||||
@ -56,6 +56,12 @@ public enum NPCSetting {
|
||||
*/
|
||||
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 |
|
||||
-----------*/
|
||||
|
@ -6,6 +6,7 @@ import net.knarcraft.blacksmith.trait.BlacksmithTrait;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -20,6 +21,7 @@ import java.util.logging.Level;
|
||||
public class NPCSettings {
|
||||
|
||||
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;
|
||||
|
||||
@ -43,6 +45,7 @@ public class NPCSettings {
|
||||
}
|
||||
//Updates the list of reforge-able items/materials
|
||||
updateReforgeAbleItems();
|
||||
updateEnchantmentBlocklist();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,10 +66,18 @@ public class NPCSettings {
|
||||
* @param newValue <p>The new value of the setting</p>
|
||||
*/
|
||||
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, ConfigHelper.asStringList(newValue));
|
||||
} else {
|
||||
currentValues.put(setting, newValue);
|
||||
}
|
||||
if (setting == NPCSetting.REFORGE_ABLE_ITEMS) {
|
||||
updateReforgeAbleItems();
|
||||
}
|
||||
if (setting == NPCSetting.ENCHANTMENT_BLOCKLIST) {
|
||||
updateEnchantmentBlocklist();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,7 +197,16 @@ public class NPCSettings {
|
||||
* @return <p>All items reforge-able by this NPC</p>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -348,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
|
||||
*/
|
||||
|
@ -43,6 +43,11 @@ public enum SettingValueType {
|
||||
/**
|
||||
* An enchantment
|
||||
*/
|
||||
ENCHANTMENT
|
||||
ENCHANTMENT,
|
||||
|
||||
/**
|
||||
* A comma-separated list of reforge-able items
|
||||
*/
|
||||
REFORGE_ABLE_ITEMS,
|
||||
|
||||
}
|
||||
|
@ -145,6 +145,13 @@ public class ReforgeSession implements Runnable {
|
||||
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
|
||||
Enchantment randomEnchantment = usableEnchantments.get(random.nextInt(usableEnchantments.size()));
|
||||
|
@ -1,5 +1,8 @@
|
||||
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
|
||||
*/
|
||||
@ -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
|
||||
*
|
||||
|
@ -32,12 +32,27 @@ public final class TabCompleteValuesHelper {
|
||||
case POSITIVE_DOUBLE -> getPositiveDoubles();
|
||||
case STRING -> getStrings();
|
||||
case PERCENTAGE -> getPercentages();
|
||||
case STRING_LIST -> getReforgeAbleMaterials();
|
||||
case REFORGE_ABLE_ITEMS -> getReforgeAbleMaterials();
|
||||
case MATERIAL -> getAllReforgeAbleMaterials();
|
||||
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
|
||||
*
|
||||
|
@ -4,6 +4,8 @@ import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.formatting.TranslatableMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static net.knarcraft.blacksmith.formatting.StringFormatter.displayErrorMessage;
|
||||
|
||||
/**
|
||||
@ -31,7 +33,7 @@ public final class TypeValidationHelper {
|
||||
case POSITIVE_INTEGER -> isPositiveInteger(value, sender);
|
||||
case PERCENTAGE -> isPercentage(value, sender);
|
||||
case BOOLEAN -> true;
|
||||
case STRING_LIST -> isStringList(value, sender);
|
||||
case STRING_LIST, REFORGE_ABLE_ITEMS -> isStringList(value, sender);
|
||||
case MATERIAL, ENCHANTMENT -> false;
|
||||
};
|
||||
} catch (ClassCastException exception) {
|
||||
@ -48,7 +50,7 @@ public final class TypeValidationHelper {
|
||||
* @return <p>True if the value is a string list</p>
|
||||
*/
|
||||
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) {
|
||||
displayErrorMessage(sender, TranslatableMessage.INPUT_STRING_LIST_REQUIRED);
|
||||
}
|
||||
@ -65,7 +67,7 @@ public final class TypeValidationHelper {
|
||||
private static boolean isPercentage(Object value, CommandSender sender) {
|
||||
try {
|
||||
int intValue = ConfigHelper.asInt(value);
|
||||
return intValue > 0 && intValue <= 100;
|
||||
return intValue >= 0 && intValue <= 100;
|
||||
} catch (NumberFormatException | NullPointerException exception) {
|
||||
if (sender != null) {
|
||||
displayErrorMessage(sender, TranslatableMessage.INPUT_PERCENTAGE_REQUIRED);
|
||||
@ -98,7 +100,7 @@ public final class TypeValidationHelper {
|
||||
*/
|
||||
private static boolean isPositiveDouble(Object value, CommandSender sender) {
|
||||
try {
|
||||
return ConfigHelper.asDouble(value) > 0.0;
|
||||
return ConfigHelper.asDouble(value) >= 0.0;
|
||||
} catch (NumberFormatException | NullPointerException exception) {
|
||||
if (sender != null) {
|
||||
displayErrorMessage(sender, TranslatableMessage.INPUT_POSITIVE_DOUBLE_REQUIRED);
|
||||
@ -116,7 +118,7 @@ public final class TypeValidationHelper {
|
||||
*/
|
||||
private static boolean isPositiveInteger(Object value, CommandSender sender) {
|
||||
try {
|
||||
return ConfigHelper.asInt(value) > 0;
|
||||
return ConfigHelper.asInt(value) >= 0;
|
||||
} catch (NumberFormatException | NullPointerException exception) {
|
||||
if (sender != null) {
|
||||
displayErrorMessage(sender, TranslatableMessage.INPUT_POSITIVE_INTEGER_REQUIRED);
|
||||
|
@ -39,6 +39,9 @@ defaults:
|
||||
# up yet.
|
||||
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)
|
||||
failReforgeChance: 10 # Default = 10%
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: Blacksmith
|
||||
author: EpicKnarvik97, aPunch, jrbudda, HurricanKai
|
||||
authors: [ EpicKnarvik97, aPunch, jrbudda, HurricanKai ]
|
||||
version: 1.0.1
|
||||
version: 1.0.2
|
||||
main: net.knarcraft.blacksmith.BlacksmithPlugin
|
||||
depend: [ Citizens, Vault ]
|
||||
|
||||
|
Reference in New Issue
Block a user