Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
d73fcfd778 | |||
0993fbe15f | |||
f3372a13a5 | |||
cf702c0e48 | |||
afb608b609 | |||
523e4cb47a | |||
384893b01a | |||
904adf46f0 | |||
81dda85405 | |||
92c1b96fba | |||
62e58ba291 | |||
21b860b5c8 | |||
51d79c21c2 |
15
README.md
15
README.md
@ -1,7 +1,8 @@
|
|||||||
# Blacksmith
|
# Blacksmith
|
||||||
|
|
||||||
The blacksmith plugin adds a new blacksmith trait to Citizens NPCs. NPCs are able to repair a player's held item for a
|
The blacksmith plugin adds a blacksmith trait and a scrapper to Citizens NPCs. Blacksmith NPCs are able to repair a
|
||||||
fee. Costs are highly customizable.
|
player's held item for a fee. Costs are highly customizable. Scrapper NPCs can break down items into their crafting
|
||||||
|
recipe.
|
||||||
|
|
||||||
### Important changes from the original fork
|
### Important changes from the original fork
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ fee. Costs are highly customizable.
|
|||||||
- By default, natural cost is used. The original fork made it cheaper the more damaged an item is, but natural cost
|
- By default, natural cost is used. The original fork made it cheaper the more damaged an item is, but natural cost
|
||||||
makes the cost increase the more damaged the item is.
|
makes the cost increase the more damaged the item is.
|
||||||
- EnchantmentTarget is used instead of a hard-coded list of repairable items
|
- EnchantmentTarget is used instead of a hard-coded list of repairable items
|
||||||
- All settings, both global and for each blacksmith, can be changed using commands,
|
- All settings, both global and for each blacksmith / scrapper, can be changed using commands,
|
||||||
and support tab-completion.
|
and support tab-completion.
|
||||||
- This plugin is not directly compatible with the original. If you are using the old one, you will need to set it up
|
- This plugin is not directly compatible with the original. If you are using the old one, you will need to set it up
|
||||||
again!
|
again!
|
||||||
@ -135,10 +136,10 @@ repair all items, except diamond armor.
|
|||||||
All currently supported presets, and available filters for each preset:
|
All currently supported presets, and available filters for each preset:
|
||||||
|
|
||||||
- BLACKSMITH (WEAPON_SMITH + ARMOR_SMITH + TOOL_SMITH)
|
- BLACKSMITH (WEAPON_SMITH + ARMOR_SMITH + TOOL_SMITH)
|
||||||
- GOLD
|
- GOLD (all gold armor, tools and weapons)
|
||||||
- IRON
|
- IRON (all iron armor, tools and weapons)
|
||||||
- DIAMOND
|
- DIAMOND (all diamond armor, tools and weapons)
|
||||||
- NETHERITE
|
- NETHERITE (all netherite armor, tools and weapons)
|
||||||
- WEAPON_SMITH: (RANGED + SWORD + SHIELD)
|
- WEAPON_SMITH: (RANGED + SWORD + SHIELD)
|
||||||
- BOW (bows and crossbows)
|
- BOW (bows and crossbows)
|
||||||
- SWORD (swords)
|
- SWORD (swords)
|
||||||
|
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.1.0</version>
|
<version>1.1.1</version>
|
||||||
<name>Blacksmith</name>
|
<name>Blacksmith</name>
|
||||||
<description>Blacksmith NPC for the Citizens API</description>
|
<description>Blacksmith NPC for the Citizens API</description>
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import org.bukkit.command.PluginCommand;
|
|||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -141,7 +142,7 @@ public class BlacksmithPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " disabled.");
|
log(" v" + getDescription().getVersion() + " disabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -177,7 +178,7 @@ public class BlacksmithPlugin extends JavaPlugin {
|
|||||||
//Register all listeners
|
//Register all listeners
|
||||||
registerListeners();
|
registerListeners();
|
||||||
|
|
||||||
getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " enabled.");
|
log(" v" + getDescription().getVersion() + " enabled.");
|
||||||
|
|
||||||
//Alert about an update in the console
|
//Alert about an update in the console
|
||||||
UpdateChecker.checkForUpdate(this, "https://api.spigotmc.org/legacy/update.php?resource=105938",
|
UpdateChecker.checkForUpdate(this, "https://api.spigotmc.org/legacy/update.php?resource=105938",
|
||||||
@ -192,7 +193,7 @@ public class BlacksmithPlugin extends JavaPlugin {
|
|||||||
try {
|
try {
|
||||||
this.configuration.load(new File(getDataFolder(), CONFIG_FILE_NAME));
|
this.configuration.load(new File(getDataFolder(), CONFIG_FILE_NAME));
|
||||||
} catch (IOException | InvalidConfigurationException exception) {
|
} catch (IOException | InvalidConfigurationException exception) {
|
||||||
getLogger().log(Level.SEVERE, "Unable to load the configuration! Message: " + exception.getMessage());
|
error("Unable to load the configuration! Message: " + exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,10 +203,55 @@ public class BlacksmithPlugin extends JavaPlugin {
|
|||||||
try {
|
try {
|
||||||
this.configuration.save(new File(getDataFolder(), CONFIG_FILE_NAME));
|
this.configuration.save(new File(getDataFolder(), CONFIG_FILE_NAME));
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
getLogger().log(Level.SEVERE, "Unable to save the configuration! Message: " + exception.getMessage());
|
error("Unable to save the configuration! Message: " + exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls an event
|
||||||
|
*
|
||||||
|
* @param event <p>The event to call</p>
|
||||||
|
*/
|
||||||
|
public void callEvent(@NotNull Event event) {
|
||||||
|
this.getServer().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints an info message to the console
|
||||||
|
*
|
||||||
|
* @param message <p>The message to print</p>
|
||||||
|
*/
|
||||||
|
public static void log(@NotNull String message) {
|
||||||
|
BlacksmithPlugin.getInstance().getLogger().log(Level.INFO, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints a warning message to the console
|
||||||
|
*
|
||||||
|
* @param message <p>The message to print</p>
|
||||||
|
*/
|
||||||
|
public static void warn(@NotNull String message) {
|
||||||
|
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints an error message to the console
|
||||||
|
*
|
||||||
|
* @param message <p>The message to print</p>
|
||||||
|
*/
|
||||||
|
public static void error(@NotNull String message) {
|
||||||
|
BlacksmithPlugin.getInstance().getLogger().log(Level.SEVERE, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints a debug message to the console
|
||||||
|
*
|
||||||
|
* @param message <p>The message to print</p>
|
||||||
|
*/
|
||||||
|
public static void debug(@NotNull String message) {
|
||||||
|
BlacksmithPlugin.getInstance().getLogger().log(Level.FINE, message);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes custom configuration and translation
|
* Initializes custom configuration and translation
|
||||||
*
|
*
|
||||||
@ -243,10 +289,10 @@ public class BlacksmithPlugin extends JavaPlugin {
|
|||||||
* @return <p>True if Vault setup/integration succeeded</p>
|
* @return <p>True if Vault setup/integration succeeded</p>
|
||||||
*/
|
*/
|
||||||
private boolean setUpVault() {
|
private boolean setUpVault() {
|
||||||
getLogger().log(Level.INFO, "Setting Up Vault now....");
|
log("Setting Up Vault now....");
|
||||||
boolean canLoad = EconomyManager.setUp(getServer().getServicesManager(), getLogger());
|
boolean canLoad = EconomyManager.setUp(getServer().getServicesManager());
|
||||||
if (!canLoad) {
|
if (!canLoad) {
|
||||||
getLogger().log(Level.SEVERE, "Vault Integration Failed....");
|
error("Vault Integration Failed....");
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import static net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage.getCurrentValueMessage;
|
import static net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage.getCurrentValueMessage;
|
||||||
import static net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage.getDefaultValueMessage;
|
import static net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage.getDefaultValueMessage;
|
||||||
@ -127,8 +126,7 @@ public abstract class EditCommand<K extends CustomTrait<L>, L extends Setting> i
|
|||||||
//Change the setting
|
//Change the setting
|
||||||
Settings<L> settings = trait.getTraitSettings();
|
Settings<L> settings = trait.getTraitSettings();
|
||||||
if (settings == null) {
|
if (settings == null) {
|
||||||
BlacksmithPlugin.getInstance().getLogger().log(Level.SEVERE, "Settings for a CustomTrait has not " +
|
BlacksmithPlugin.error("Settings for a CustomTrait has not been initialized! Please inform the developer!");
|
||||||
"been initialized! Please inform the developer!");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
settings.changeValue(setting, newValue);
|
settings.changeValue(setting, newValue);
|
||||||
@ -154,8 +152,7 @@ public abstract class EditCommand<K extends CustomTrait<L>, L extends Setting> i
|
|||||||
@NotNull CommandSender sender) {
|
@NotNull CommandSender sender) {
|
||||||
Settings<L> settings = trait.getTraitSettings();
|
Settings<L> settings = trait.getTraitSettings();
|
||||||
if (settings == null) {
|
if (settings == null) {
|
||||||
BlacksmithPlugin.getInstance().getLogger().log(Level.SEVERE, "Settings for a CustomTrait has not " +
|
BlacksmithPlugin.error("Settings for a CustomTrait has not been initialized! Please inform the developer!");
|
||||||
"been initialized! Please inform the developer!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ public interface Settings<K extends Setting> {
|
|||||||
* @param setting <p>The setting to get</p>
|
* @param setting <p>The setting to get</p>
|
||||||
* @return <p>The current raw setting value</p>
|
* @return <p>The current raw setting value</p>
|
||||||
*/
|
*/
|
||||||
@NotNull Object getRawValue(@NotNull K setting);
|
@NotNull
|
||||||
|
Object getRawValue(@NotNull K setting);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A representation of the presets for different kinds of smiths
|
* A representation of the presets for different kinds of smiths
|
||||||
@ -133,8 +132,8 @@ public enum SmithPreset {
|
|||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
/* This case means that either the preset or the filter given is invalid, and thus the preset string should
|
/* This case means that either the preset or the filter given is invalid, and thus the preset string should
|
||||||
be ignored to prevent any problems. */
|
be ignored to prevent any problems. */
|
||||||
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, String.format("The smith preset %s is " +
|
BlacksmithPlugin.warn(String.format("The smith preset %s is invalid, and will be ignored. Please fix it!",
|
||||||
"invalid, and will be ignored. Please fix it!", possiblePreset));
|
possiblePreset));
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which keeps track of all Blacksmith settings/config values for one NPC
|
* A class which keeps track of all Blacksmith settings/config values for one NPC
|
||||||
@ -384,8 +383,7 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
|
|||||||
if (enchantment != null) {
|
if (enchantment != null) {
|
||||||
enchantmentBlockList.add(enchantment);
|
enchantmentBlockList.add(enchantment);
|
||||||
} else {
|
} else {
|
||||||
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Unable to verify " + item +
|
BlacksmithPlugin.warn("Unable to verify " + item + " as a valid enchantment");
|
||||||
" as a valid enchantment");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return enchantmentBlockList;
|
return enchantmentBlockList;
|
||||||
|
@ -241,7 +241,8 @@ public enum BlacksmithSetting implements Setting {
|
|||||||
* The cost for repairing a damaged anvil
|
* The cost for repairing a damaged anvil
|
||||||
*/
|
*/
|
||||||
ANVIL_DAMAGED_COST("damagedAnvilReforgingCost", SettingValueType.POSITIVE_DOUBLE, 20.0,
|
ANVIL_DAMAGED_COST("damagedAnvilReforgingCost", SettingValueType.POSITIVE_DOUBLE, 20.0,
|
||||||
"The cost of fully repairing a damaged anvil", false, false);
|
"The cost of fully repairing a damaged anvil", false, false),
|
||||||
|
;
|
||||||
|
|
||||||
private final String path;
|
private final String path;
|
||||||
private final String childPath;
|
private final String childPath;
|
||||||
@ -262,7 +263,7 @@ public enum BlacksmithSetting implements Setting {
|
|||||||
* @param isPerNPC <p>Whether this setting is per-NPC or global</p>
|
* @param isPerNPC <p>Whether this setting is per-NPC or global</p>
|
||||||
* @param isMessage <p>Whether this option is for an NPC message</p>
|
* @param isMessage <p>Whether this option is for an NPC message</p>
|
||||||
*/
|
*/
|
||||||
BlacksmithSetting(@NotNull String key, @NotNull SettingValueType valueType, @NotNull Object value,
|
BlacksmithSetting(@NotNull String key, @NotNull SettingValueType valueType, @Nullable Object value,
|
||||||
@NotNull String description, boolean isPerNPC, boolean isMessage) {
|
@NotNull String description, boolean isPerNPC, boolean isMessage) {
|
||||||
if (isPerNPC) {
|
if (isPerNPC) {
|
||||||
if (isMessage) {
|
if (isMessage) {
|
||||||
|
@ -19,7 +19,6 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which keeps track of all default blacksmith NPC settings and all global blacksmith settings
|
* A class which keeps track of all default blacksmith NPC settings and all global blacksmith settings
|
||||||
@ -344,15 +343,14 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
|
|||||||
ConfigurationSection enchantmentCostNode = fileConfiguration.getConfigurationSection(
|
ConfigurationSection enchantmentCostNode = fileConfiguration.getConfigurationSection(
|
||||||
getBase(BlacksmithSetting.ENCHANTMENT_COST.getPath()));
|
getBase(BlacksmithSetting.ENCHANTMENT_COST.getPath()));
|
||||||
if (enchantmentCostNode == null) {
|
if (enchantmentCostNode == null) {
|
||||||
instance.getLogger().log(Level.WARNING, "Could not load enchantment prices. because the " +
|
BlacksmithPlugin.warn("Could not load enchantment prices. because the configuration section doesn't exist");
|
||||||
"configuration section doesn't exist");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Map<String, String> relevantKeys = getRelevantKeys(enchantmentCostNode);
|
Map<String, String> relevantKeys = getRelevantKeys(enchantmentCostNode);
|
||||||
for (String key : relevantKeys.keySet()) {
|
for (String key : relevantKeys.keySet()) {
|
||||||
String enchantmentName = relevantKeys.get(key);
|
String enchantmentName = relevantKeys.get(key);
|
||||||
Enchantment enchantment = InputParsingHelper.matchEnchantment(enchantmentName);
|
Enchantment enchantment = InputParsingHelper.matchEnchantment(enchantmentName);
|
||||||
instance.getLogger().log(Level.WARNING, "loadEnchantmentPrices " + enchantmentName);
|
BlacksmithPlugin.warn("loadEnchantmentPrices " + enchantmentName);
|
||||||
setItemPrice(this.enchantmentCosts, enchantmentName, enchantment, enchantmentCostNode.getDouble(key));
|
setItemPrice(this.enchantmentCosts, enchantmentName, enchantment, enchantmentCostNode.getDouble(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,8 +364,7 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
|
|||||||
ConfigurationSection basePerDurabilityPriceNode = fileConfiguration.getConfigurationSection(
|
ConfigurationSection basePerDurabilityPriceNode = fileConfiguration.getConfigurationSection(
|
||||||
getBase(BlacksmithSetting.PRICE_PER_DURABILITY_POINT.getPath()));
|
getBase(BlacksmithSetting.PRICE_PER_DURABILITY_POINT.getPath()));
|
||||||
if (basePerDurabilityPriceNode == null) {
|
if (basePerDurabilityPriceNode == null) {
|
||||||
instance.getLogger().log(Level.WARNING, "Could not load per durability prices. because the " +
|
BlacksmithPlugin.warn("Could not load per durability prices. because the configuration section doesn't exist");
|
||||||
"configuration section doesn't exist");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Map<String, String> relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
|
Map<String, String> relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
|
||||||
@ -394,8 +391,7 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
|
|||||||
ConfigurationSection basePriceNode = fileConfiguration.getConfigurationSection(
|
ConfigurationSection basePriceNode = fileConfiguration.getConfigurationSection(
|
||||||
getBase(BlacksmithSetting.BASE_PRICE.getPath()));
|
getBase(BlacksmithSetting.BASE_PRICE.getPath()));
|
||||||
if (basePriceNode == null) {
|
if (basePriceNode == null) {
|
||||||
instance.getLogger().log(Level.WARNING, "Could not load base prices, because the configuration " +
|
BlacksmithPlugin.warn("Could not load base prices, because the configuration section doesn't exist");
|
||||||
"section doesn't exist");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Map<String, String> relevantKeys = getRelevantKeys(basePriceNode);
|
Map<String, String> relevantKeys = getRelevantKeys(basePriceNode);
|
||||||
@ -442,7 +438,7 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
|
|||||||
if (item != null) {
|
if (item != null) {
|
||||||
prices.put(item, price);
|
prices.put(item, price);
|
||||||
} else {
|
} else {
|
||||||
instance.getLogger().log(Level.WARNING, "Unable to find a material/enchantment matching " + itemName);
|
BlacksmithPlugin.warn("Unable to find a material/enchantment matching " + itemName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which keeps track of all default scrapper NPC settings and all global scrapper settings
|
* A class which keeps track of all default scrapper NPC settings and all global scrapper settings
|
||||||
@ -251,8 +250,7 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
|
|||||||
for (String trashSalvageInfo : allTrashSalvage) {
|
for (String trashSalvageInfo : allTrashSalvage) {
|
||||||
// Ignore invalid lines
|
// Ignore invalid lines
|
||||||
if (!trashSalvageInfo.contains(":")) {
|
if (!trashSalvageInfo.contains(":")) {
|
||||||
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, String.format("The trash salvage " +
|
BlacksmithPlugin.warn(String.format("The trash salvage configuration line %s is invalid", trashSalvageInfo));
|
||||||
"configuration line %s is invalid", trashSalvageInfo));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ public enum ScrapperSetting implements Setting {
|
|||||||
* @param isPerNPC <p>Whether this setting is per-NPC or global</p>
|
* @param isPerNPC <p>Whether this setting is per-NPC or global</p>
|
||||||
* @param isMessage <p>Whether this option is for an NPC message</p>
|
* @param isMessage <p>Whether this option is for an NPC message</p>
|
||||||
*/
|
*/
|
||||||
ScrapperSetting(@NotNull String key, @NotNull SettingValueType valueType, @NotNull Object value,
|
ScrapperSetting(@NotNull String key, @NotNull SettingValueType valueType, @Nullable Object value,
|
||||||
@NotNull String description, boolean isPerNPC, boolean isMessage) {
|
@NotNull String description, boolean isPerNPC, boolean isMessage) {
|
||||||
if (isPerNPC) {
|
if (isPerNPC) {
|
||||||
if (isMessage) {
|
if (isMessage) {
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package net.knarcraft.blacksmith.container;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.Recipe;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The result of a recipe's salvage
|
||||||
|
*
|
||||||
|
* @param recipe <p>The selected recipe</p>
|
||||||
|
* @param salvage <p>The resulting salvage</p>
|
||||||
|
*/
|
||||||
|
public record RecipeResult(@NotNull Recipe recipe, @NotNull List<ItemStack> salvage) {
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package net.knarcraft.blacksmith.container;
|
||||||
|
|
||||||
|
import net.knarcraft.blacksmith.property.SalvageMethod;
|
||||||
|
import net.knarcraft.blacksmith.property.SalvageState;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The result of an attempted salvage
|
||||||
|
*
|
||||||
|
* @param salvageMethod <p>The salvage method used</p>
|
||||||
|
* @param salvage <p>The produced salvage</p>
|
||||||
|
* @param salvageState <p>The state of the salvage result</p>
|
||||||
|
* @param requiredAmount <p>The amount of items required for the salvage</p>
|
||||||
|
*/
|
||||||
|
public record SalvageResult(@NotNull SalvageMethod salvageMethod, @NotNull List<ItemStack> salvage,
|
||||||
|
@NotNull SalvageState salvageState, int requiredAmount) {
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base class for all blacksmith plugin events
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public abstract class AbstractBlacksmithPluginEvent extends Event implements BlacksmithPluginEvent {
|
||||||
|
|
||||||
|
protected final NPC npc;
|
||||||
|
protected final Player player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new blacksmith plugin event
|
||||||
|
*
|
||||||
|
* @param npc <p>The NPC involved in the event</p>
|
||||||
|
* @param player <p>The player involved in the event</p>
|
||||||
|
*/
|
||||||
|
public AbstractBlacksmithPluginEvent(@NotNull NPC npc, @NotNull Player player) {
|
||||||
|
this.npc = npc;
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public NPC getNpc() {
|
||||||
|
return this.npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event triggered when a blacksmith or scrapper starts reforging or salvaging an item
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public interface ActionStartEvent extends BlacksmithPluginEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the amount of ticks this action will take
|
||||||
|
*
|
||||||
|
* @return <p>The duration in ticks</p>
|
||||||
|
*/
|
||||||
|
long getActionDurationTicks();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event triggered by the Blacksmith plugin
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public interface BlacksmithPluginEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the NPC involved in the event
|
||||||
|
*
|
||||||
|
* @return <p>The NPC</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
NPC getNpc();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player involved in the event
|
||||||
|
*
|
||||||
|
* @return <p>The player</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
Player getPlayer();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event triggered when a blacksmith reforging fails
|
||||||
|
*/
|
||||||
|
public class BlacksmithReforgeFailEvent extends AbstractBlacksmithPluginEvent implements ReforgeEndEvent {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new blacksmith reforge fail event
|
||||||
|
*
|
||||||
|
* @param npc <p>The NPC involved in the event</p>
|
||||||
|
*/
|
||||||
|
public BlacksmithReforgeFailEvent(@NotNull NPC npc, @NotNull Player player) {
|
||||||
|
super(npc, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a handler-list containing all event handlers
|
||||||
|
*
|
||||||
|
* @return <p>A handler-list with all event handlers</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event triggered when a blacksmith reforging starts
|
||||||
|
*/
|
||||||
|
public class BlacksmithReforgeStartEvent extends AbstractBlacksmithPluginEvent implements ActionStartEvent {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final long durationTicks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new blacksmith reforge start event
|
||||||
|
*
|
||||||
|
* @param npc <p>The NPC involved in the event</p>
|
||||||
|
* @param player <p>The player involved in the event</p>
|
||||||
|
* @param durationTicks <p>The duration of the reforge</p>
|
||||||
|
*/
|
||||||
|
public BlacksmithReforgeStartEvent(@NotNull NPC npc, @NotNull Player player, long durationTicks) {
|
||||||
|
super(npc, player);
|
||||||
|
this.durationTicks = durationTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getActionDurationTicks() {
|
||||||
|
return durationTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a handler-list containing all event handlers
|
||||||
|
*
|
||||||
|
* @return <p>A handler-list with all event handlers</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event triggered when a blacksmith reforging succeeds
|
||||||
|
*/
|
||||||
|
public class BlacksmithReforgeSucceedEvent extends AbstractBlacksmithPluginEvent implements ReforgeEndEvent {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new blacksmith reforge succeed event
|
||||||
|
*
|
||||||
|
* @param npc <p>The NPC involved in the event</p>
|
||||||
|
* @param player <p>The player involved in the event</p>
|
||||||
|
*/
|
||||||
|
public BlacksmithReforgeSucceedEvent(@NotNull NPC npc, @NotNull Player player) {
|
||||||
|
super(npc, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a handler-list containing all event handlers
|
||||||
|
*
|
||||||
|
* @return <p>A handler-list with all event handlers</p>
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
142
src/main/java/net/knarcraft/blacksmith/event/NPCSoundEvent.java
Normal file
142
src/main/java/net/knarcraft/blacksmith/event/NPCSoundEvent.java
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.SoundCategory;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event triggered when an NPC plays a sound indicating an action
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class NPCSoundEvent extends AbstractBlacksmithPluginEvent implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled;
|
||||||
|
private float pitch;
|
||||||
|
private float volume;
|
||||||
|
private SoundCategory soundCategory;
|
||||||
|
private Sound sound;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new NPC sound event
|
||||||
|
*
|
||||||
|
* @param npc <p>The NPC playing the sound</p>
|
||||||
|
* @param player <p>The player whose interaction triggered the sound</p>
|
||||||
|
* @param soundCategory <p>The category the sound is to play in</p>
|
||||||
|
* @param sound <p>The sound to play</p>
|
||||||
|
* @param volume <p>The volume of the played sound</p>
|
||||||
|
* @param pitch <p>The pitch of the played sound</p>
|
||||||
|
*/
|
||||||
|
public NPCSoundEvent(@NotNull NPC npc, @NotNull Player player, @NotNull SoundCategory soundCategory,
|
||||||
|
@NotNull Sound sound, float volume, float pitch) {
|
||||||
|
super(npc, player);
|
||||||
|
this.soundCategory = soundCategory;
|
||||||
|
this.sound = sound;
|
||||||
|
this.volume = volume;
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the pitch of the played sound
|
||||||
|
*
|
||||||
|
* @return <p>The pitch of the played sound</p>
|
||||||
|
*/
|
||||||
|
public float getPitch() {
|
||||||
|
return this.pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the volume of the played sound
|
||||||
|
*
|
||||||
|
* @return <p>The volume of the played sound</p>
|
||||||
|
*/
|
||||||
|
public float getVolume() {
|
||||||
|
return this.volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the category the sound is played in
|
||||||
|
*
|
||||||
|
* @return <p>The sound category used</p>
|
||||||
|
*/
|
||||||
|
public @NotNull SoundCategory getSoundCategory() {
|
||||||
|
return this.soundCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the sound to play
|
||||||
|
*
|
||||||
|
* @return <p>The sound to play</p>
|
||||||
|
*/
|
||||||
|
public @NotNull Sound getSound() {
|
||||||
|
return this.sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pitch of the played sound
|
||||||
|
*
|
||||||
|
* @param pitch <p>The new pitch</p>
|
||||||
|
*/
|
||||||
|
public void setPitch(float pitch) {
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the volume of the played sound
|
||||||
|
*
|
||||||
|
* @param volume <p>The new volume</p>
|
||||||
|
*/
|
||||||
|
public void setVolume(float volume) {
|
||||||
|
this.volume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the sound to play
|
||||||
|
*
|
||||||
|
* @param sound <p>The new sound to play</p>
|
||||||
|
*/
|
||||||
|
public void setSound(@NotNull Sound sound) {
|
||||||
|
this.sound = sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the category the sound is played in
|
||||||
|
*
|
||||||
|
* @param soundCategory <p>The new sound category</p>
|
||||||
|
*/
|
||||||
|
public void setSoundCategory(@NotNull SoundCategory soundCategory) {
|
||||||
|
this.soundCategory = soundCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a handler-list containing all event handlers
|
||||||
|
*
|
||||||
|
* @return <p>A handler-list with all event handlers</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event triggered when a reforge finishes
|
||||||
|
*/
|
||||||
|
public interface ReforgeEndEvent extends BlacksmithPluginEvent {
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event triggered when a salvaging finishes
|
||||||
|
*/
|
||||||
|
public interface SalvageEndEvent extends BlacksmithPluginEvent {
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event triggered when a scrapper salvaging fails
|
||||||
|
*/
|
||||||
|
public class ScrapperSalvageFailEvent extends AbstractBlacksmithPluginEvent implements SalvageEndEvent {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new scrapper salvage fail event
|
||||||
|
*
|
||||||
|
* @param npc <p>The NPC involved in the event</p>
|
||||||
|
* @param player <p>The player involved in the event</p>
|
||||||
|
*/
|
||||||
|
public ScrapperSalvageFailEvent(@NotNull NPC npc, @NotNull Player player) {
|
||||||
|
super(npc, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a handler-list containing all event handlers
|
||||||
|
*
|
||||||
|
* @return <p>A handler-list with all event handlers</p>
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event triggered when a scrapper salvaging starts
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class ScrapperSalvageStartEvent extends AbstractBlacksmithPluginEvent implements ActionStartEvent {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final long durationTicks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new scrapper salvage start event
|
||||||
|
*
|
||||||
|
* @param npc <p>The NPC involved in the event</p>
|
||||||
|
* @param player <p>The player involved in the event</p>
|
||||||
|
* @param durationTicks <p>The duration of the salvage</p>
|
||||||
|
*/
|
||||||
|
public ScrapperSalvageStartEvent(@NotNull NPC npc, @NotNull Player player, long durationTicks) {
|
||||||
|
super(npc, player);
|
||||||
|
this.durationTicks = durationTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getActionDurationTicks() {
|
||||||
|
return this.durationTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a handler-list containing all event handlers
|
||||||
|
*
|
||||||
|
* @return <p>A handler-list with all event handlers</p>
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package net.knarcraft.blacksmith.event;
|
||||||
|
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event triggered when a scrapper salvaging succeeds
|
||||||
|
*/
|
||||||
|
public class ScrapperSalvageSucceedEvent extends AbstractBlacksmithPluginEvent implements SalvageEndEvent {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new scrapper salvage succeed event
|
||||||
|
*
|
||||||
|
* @param npc <p>The NPC involved in the event</p>
|
||||||
|
* @param player <p>The player involved in the event</p>
|
||||||
|
*/
|
||||||
|
public ScrapperSalvageSucceedEvent(@NotNull NPC npc, @NotNull Player player) {
|
||||||
|
super(npc, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a handler-list containing all event handlers
|
||||||
|
*
|
||||||
|
* @return <p>A handler-list with all event handlers</p>
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@NotNull
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,8 +12,6 @@ import org.bukkit.event.Listener;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A listener for detecting and handling a Blacksmith being right-clicked
|
* A listener for detecting and handling a Blacksmith being right-clicked
|
||||||
*/
|
*/
|
||||||
@ -21,7 +19,7 @@ public class NPCClickListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onRightClick(@NotNull NPCRightClickEvent event) {
|
public void onRightClick(@NotNull NPCRightClickEvent event) {
|
||||||
//We only care about blacksmiths
|
//We only care about blacksmiths and scrappers
|
||||||
if (event.getNPC().hasTrait(BlacksmithTrait.class)) {
|
if (event.getNPC().hasTrait(BlacksmithTrait.class)) {
|
||||||
handleNPCClick(event, event.getNPC().getTraitNullable(BlacksmithTrait.class));
|
handleNPCClick(event, event.getNPC().getTraitNullable(BlacksmithTrait.class));
|
||||||
} else if (event.getNPC().hasTrait(ScrapperTrait.class)) {
|
} else if (event.getNPC().hasTrait(ScrapperTrait.class)) {
|
||||||
@ -37,7 +35,7 @@ public class NPCClickListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
private void handleNPCClick(@NotNull NPCRightClickEvent event, @Nullable CustomTrait<?> customTrait) {
|
private void handleNPCClick(@NotNull NPCRightClickEvent event, @Nullable CustomTrait<?> customTrait) {
|
||||||
if (customTrait == null) {
|
if (customTrait == null) {
|
||||||
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Could not get trait from NPC!");
|
BlacksmithPlugin.warn("Could not get trait from NPC!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package net.knarcraft.blacksmith.manager;
|
package net.knarcraft.blacksmith.manager;
|
||||||
|
|
||||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||||
import net.knarcraft.blacksmith.config.SalvageMethod;
|
|
||||||
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings;
|
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings;
|
||||||
import net.knarcraft.blacksmith.config.scrapper.GlobalScrapperSettings;
|
import net.knarcraft.blacksmith.config.scrapper.GlobalScrapperSettings;
|
||||||
|
import net.knarcraft.blacksmith.property.SalvageMethod;
|
||||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -14,9 +14,6 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
|||||||
import org.bukkit.plugin.ServicesManager;
|
import org.bukkit.plugin.ServicesManager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which deals with everything economy
|
* A class which deals with everything economy
|
||||||
*/
|
*/
|
||||||
@ -32,15 +29,14 @@ public class EconomyManager {
|
|||||||
* Sets up Vault economy support
|
* Sets up Vault economy support
|
||||||
*
|
*
|
||||||
* @param servicesManager <p>The services manager to use for finding a Vault provider</p>
|
* @param servicesManager <p>The services manager to use for finding a Vault provider</p>
|
||||||
* @param logger <p>The logger to use for logging</p>
|
|
||||||
* @return <p>True if Vault was successfully set up</p>
|
* @return <p>True if Vault was successfully set up</p>
|
||||||
*/
|
*/
|
||||||
public static boolean setUp(@NotNull ServicesManager servicesManager, @NotNull Logger logger) {
|
public static boolean setUp(@NotNull ServicesManager servicesManager) {
|
||||||
//If already set up, there is nothing to do
|
//If already set up, there is nothing to do
|
||||||
if (economy != null) {
|
if (economy != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return setupVault(servicesManager, logger);
|
return setupVault(servicesManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -191,10 +187,9 @@ public class EconomyManager {
|
|||||||
* Sets up Vault for economy
|
* Sets up Vault for economy
|
||||||
*
|
*
|
||||||
* @param servicesManager <p>The services manager to use for finding a Vault provider</p>
|
* @param servicesManager <p>The services manager to use for finding a Vault provider</p>
|
||||||
* @param logger <p>The logger to use for logging</p>
|
|
||||||
* @return <p>True if Vault was successfully set up</p>
|
* @return <p>True if Vault was successfully set up</p>
|
||||||
*/
|
*/
|
||||||
private static boolean setupVault(@NotNull ServicesManager servicesManager, @NotNull Logger logger) {
|
private static boolean setupVault(@NotNull ServicesManager servicesManager) {
|
||||||
// Setup Vault
|
// Setup Vault
|
||||||
RegisteredServiceProvider<Economy> economyProvider = servicesManager.getRegistration(Economy.class);
|
RegisteredServiceProvider<Economy> economyProvider = servicesManager.getRegistration(Economy.class);
|
||||||
if (economyProvider != null) {
|
if (economyProvider != null) {
|
||||||
@ -202,7 +197,7 @@ public class EconomyManager {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Disable if no economy plugin was found
|
// Disable if no economy plugin was found
|
||||||
logger.log(Level.SEVERE, "Failed to load an economy plugin. Disabling...");
|
BlacksmithPlugin.error("Failed to load an economy plugin. Disabling...");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package net.knarcraft.blacksmith.config;
|
package net.knarcraft.blacksmith.property;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A representation of the different ways an item can be salvaged
|
* A representation of the different ways an item can be salvaged
|
@ -0,0 +1,23 @@
|
|||||||
|
package net.knarcraft.blacksmith.property;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The state of trying to find salvage for an item
|
||||||
|
*/
|
||||||
|
public enum SalvageState {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Found useful salvage that can be given to a player
|
||||||
|
*/
|
||||||
|
FOUND_SALVAGE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item cannot be salvaged using the used method
|
||||||
|
*/
|
||||||
|
INCORRECT_METHOD,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* While the method was correct, no useful salvage was created
|
||||||
|
*/
|
||||||
|
NO_SALVAGE,
|
||||||
|
|
||||||
|
}
|
@ -21,6 +21,7 @@ import static net.knarcraft.blacksmith.formatting.BlacksmithStringFormatter.send
|
|||||||
* The class representing the Blacksmith NPC trait
|
* The class representing the Blacksmith NPC trait
|
||||||
*/
|
*/
|
||||||
public class BlacksmithTrait extends CustomTrait<BlacksmithSetting> {
|
public class BlacksmithTrait extends CustomTrait<BlacksmithSetting> {
|
||||||
|
|
||||||
private final BlacksmithNPCSettings config;
|
private final BlacksmithNPCSettings config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,7 +7,6 @@ import net.knarcraft.blacksmith.config.Settings;
|
|||||||
import net.knarcraft.blacksmith.config.TraitSettings;
|
import net.knarcraft.blacksmith.config.TraitSettings;
|
||||||
import net.knarcraft.blacksmith.formatting.TimeFormatter;
|
import net.knarcraft.blacksmith.formatting.TimeFormatter;
|
||||||
import net.knarcraft.blacksmith.manager.EconomyManager;
|
import net.knarcraft.blacksmith.manager.EconomyManager;
|
||||||
import net.knarcraft.blacksmith.util.SalvageHelper;
|
|
||||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -196,9 +195,9 @@ public abstract class CustomTrait<K extends Setting> extends Trait {
|
|||||||
Objects.requireNonNull(((LivingEntity) npc.getEntity()).getEquipment()).setItemInMainHand(heldItem);
|
Objects.requireNonNull(((LivingEntity) npc.getEntity()).getEquipment()).setItemInMainHand(heldItem);
|
||||||
}
|
}
|
||||||
//Remove the item from the player's inventory
|
//Remove the item from the player's inventory
|
||||||
if (!isBlacksmith) {
|
if (this.session instanceof SalvageSession salvageSession) {
|
||||||
// For scrappers, just reduce the amounts of items, unless the remaining stack is salvaged
|
// For scrappers, just reduce the amounts of items, unless the remaining stack is salvaged
|
||||||
int amount = SalvageHelper.getRequiredAmountForSalvage(player.getServer(), heldItem);
|
int amount = salvageSession.getItemsConsumed();
|
||||||
if (amount != heldItem.getAmount()) {
|
if (amount != heldItem.getAmount()) {
|
||||||
heldItem.setAmount(heldItem.getAmount() - amount);
|
heldItem.setAmount(heldItem.getAmount() - amount);
|
||||||
playerInventory.setItemInMainHand(heldItem);
|
playerInventory.setItemInMainHand(heldItem);
|
||||||
|
@ -3,12 +3,15 @@ package net.knarcraft.blacksmith.trait;
|
|||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||||
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSettings;
|
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSettings;
|
||||||
|
import net.knarcraft.blacksmith.event.BlacksmithReforgeFailEvent;
|
||||||
|
import net.knarcraft.blacksmith.event.BlacksmithReforgeSucceedEvent;
|
||||||
import net.knarcraft.blacksmith.manager.EconomyManager;
|
import net.knarcraft.blacksmith.manager.EconomyManager;
|
||||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Registry;
|
import org.bukkit.Registry;
|
||||||
|
import org.bukkit.Sound;
|
||||||
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;
|
||||||
@ -20,7 +23,6 @@ import java.util.Calendar;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import static net.knarcraft.blacksmith.formatting.BlacksmithStringFormatter.sendNPCMessage;
|
import static net.knarcraft.blacksmith.formatting.BlacksmithStringFormatter.sendNPCMessage;
|
||||||
|
|
||||||
@ -30,7 +32,6 @@ import static net.knarcraft.blacksmith.formatting.BlacksmithStringFormatter.send
|
|||||||
public class ReforgeSession extends Session implements Runnable {
|
public class ReforgeSession extends Session implements Runnable {
|
||||||
|
|
||||||
private final BlacksmithTrait blacksmithTrait;
|
private final BlacksmithTrait blacksmithTrait;
|
||||||
private final NPC npc;
|
|
||||||
private final ItemStack itemToReforge;
|
private final ItemStack itemToReforge;
|
||||||
private final BlacksmithNPCSettings config;
|
private final BlacksmithNPCSettings config;
|
||||||
private static List<String> enchantments = null;
|
private static List<String> enchantments = null;
|
||||||
@ -45,9 +46,8 @@ public class ReforgeSession extends Session implements Runnable {
|
|||||||
*/
|
*/
|
||||||
ReforgeSession(@NotNull BlacksmithTrait blacksmithTrait, @NotNull Player player, @NotNull NPC npc,
|
ReforgeSession(@NotNull BlacksmithTrait blacksmithTrait, @NotNull Player player, @NotNull NPC npc,
|
||||||
@NotNull BlacksmithNPCSettings config) {
|
@NotNull BlacksmithNPCSettings config) {
|
||||||
super(player);
|
super(player, npc);
|
||||||
this.blacksmithTrait = blacksmithTrait;
|
this.blacksmithTrait = blacksmithTrait;
|
||||||
this.npc = npc;
|
|
||||||
this.itemToReforge = player.getInventory().getItemInMainHand();
|
this.itemToReforge = player.getInventory().getItemInMainHand();
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
@ -97,7 +97,9 @@ public class ReforgeSession extends Session implements Runnable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
sendNPCMessage(this.npc, this.player, reforgeItem() ? this.config.getSuccessMessage() : this.config.getFailMessage());
|
boolean success = reforgeItem();
|
||||||
|
sendNPCMessage(this.npc, this.player, success ? this.config.getSuccessMessage() : this.config.getFailMessage());
|
||||||
|
playSound(success ? Sound.BLOCK_ANVIL_USE : Sound.ENTITY_VILLAGER_NO);
|
||||||
|
|
||||||
//Stop the reforged item from displaying in the blacksmith's hand
|
//Stop the reforged item from displaying in the blacksmith's hand
|
||||||
if (this.npc.getEntity() instanceof Player) {
|
if (this.npc.getEntity() instanceof Player) {
|
||||||
@ -134,9 +136,11 @@ public class ReforgeSession extends Session implements Runnable {
|
|||||||
private boolean reforgeItem() {
|
private boolean reforgeItem() {
|
||||||
if (random.nextInt(100) < this.config.getFailChance()) {
|
if (random.nextInt(100) < this.config.getFailChance()) {
|
||||||
failReforge();
|
failReforge();
|
||||||
|
BlacksmithPlugin.getInstance().callEvent(new BlacksmithReforgeFailEvent(this.npc, this.player));
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
succeedReforge();
|
succeedReforge();
|
||||||
|
BlacksmithPlugin.getInstance().callEvent(new BlacksmithReforgeSucceedEvent(this.npc, this.player));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,8 +151,7 @@ public class ReforgeSession extends Session implements Runnable {
|
|||||||
private void succeedReforge() {
|
private void succeedReforge() {
|
||||||
// Remove any damage done to the item
|
// Remove any damage done to the item
|
||||||
if (ItemHelper.updateDamage(this.itemToReforge, 0)) {
|
if (ItemHelper.updateDamage(this.itemToReforge, 0)) {
|
||||||
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Unable to update damage for " +
|
BlacksmithPlugin.warn("Unable to update damage for " + this.itemToReforge);
|
||||||
this.itemToReforge);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Replace damaged anvils with a normal anvil
|
//Replace damaged anvils with a normal anvil
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package net.knarcraft.blacksmith.trait;
|
package net.knarcraft.blacksmith.trait;
|
||||||
|
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.knarcraft.blacksmith.config.SalvageMethod;
|
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||||
import net.knarcraft.blacksmith.config.scrapper.ScrapperNPCSettings;
|
import net.knarcraft.blacksmith.config.scrapper.ScrapperNPCSettings;
|
||||||
|
import net.knarcraft.blacksmith.event.ScrapperSalvageFailEvent;
|
||||||
|
import net.knarcraft.blacksmith.event.ScrapperSalvageSucceedEvent;
|
||||||
import net.knarcraft.blacksmith.manager.EconomyManager;
|
import net.knarcraft.blacksmith.manager.EconomyManager;
|
||||||
|
import net.knarcraft.blacksmith.property.SalvageMethod;
|
||||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||||
import net.knarcraft.blacksmith.util.SalvageHelper;
|
import net.knarcraft.blacksmith.util.SalvageHelper;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -25,7 +29,6 @@ import static net.knarcraft.blacksmith.formatting.BlacksmithStringFormatter.send
|
|||||||
public class SalvageSession extends Session implements Runnable {
|
public class SalvageSession extends Session implements Runnable {
|
||||||
|
|
||||||
private final ScrapperTrait scrapperTrait;
|
private final ScrapperTrait scrapperTrait;
|
||||||
private final NPC npc;
|
|
||||||
private final ItemStack itemToSalvage;
|
private final ItemStack itemToSalvage;
|
||||||
private final ScrapperNPCSettings config;
|
private final ScrapperNPCSettings config;
|
||||||
private final List<ItemStack> salvage;
|
private final List<ItemStack> salvage;
|
||||||
@ -44,12 +47,11 @@ public class SalvageSession extends Session implements Runnable {
|
|||||||
* @param salvageMethod <p>The salvage method performed in this session</p>
|
* @param salvageMethod <p>The salvage method performed in this session</p>
|
||||||
* @param itemsConsumed <p>The number of items actually consumed, in case a salvaging fails</p>
|
* @param itemsConsumed <p>The number of items actually consumed, in case a salvaging fails</p>
|
||||||
*/
|
*/
|
||||||
SalvageSession(@NotNull ScrapperTrait scrapperTrait, @NotNull Player player, @NotNull NPC npc,
|
public SalvageSession(@NotNull ScrapperTrait scrapperTrait, @NotNull Player player, @NotNull NPC npc,
|
||||||
@NotNull ScrapperNPCSettings config, @NotNull List<ItemStack> salvage,
|
@NotNull ScrapperNPCSettings config, @NotNull List<ItemStack> salvage,
|
||||||
@NotNull SalvageMethod salvageMethod, int itemsConsumed) {
|
@NotNull SalvageMethod salvageMethod, int itemsConsumed) {
|
||||||
super(player);
|
super(player, npc);
|
||||||
this.scrapperTrait = scrapperTrait;
|
this.scrapperTrait = scrapperTrait;
|
||||||
this.npc = npc;
|
|
||||||
this.itemToSalvage = player.getInventory().getItemInMainHand().clone();
|
this.itemToSalvage = player.getInventory().getItemInMainHand().clone();
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.salvage = salvage;
|
this.salvage = salvage;
|
||||||
@ -108,14 +110,27 @@ public class SalvageSession extends Session implements Runnable {
|
|||||||
this.scrapperTrait.addCoolDown(this.player.getUniqueId(), wait);
|
this.scrapperTrait.addCoolDown(this.player.getUniqueId(), wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of items consumed in order to perform the salvage
|
||||||
|
*
|
||||||
|
* @return <p>The number of items consumed as part of this salvage</p>
|
||||||
|
*/
|
||||||
|
public int getItemsConsumed() {
|
||||||
|
return this.itemsConsumed;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trues to salvage an item, and gives the return item
|
* Trues to salvage an item, and gives the return item
|
||||||
*/
|
*/
|
||||||
private void salvageItem() {
|
private void salvageItem() {
|
||||||
if (random.nextInt(100) < this.config.getFailChance()) {
|
if (random.nextInt(100) < this.config.getFailChance()) {
|
||||||
|
playSound(Sound.ENTITY_VILLAGER_NO);
|
||||||
failSalvage();
|
failSalvage();
|
||||||
|
BlacksmithPlugin.getInstance().callEvent(new ScrapperSalvageFailEvent(this.npc, this.player));
|
||||||
} else {
|
} else {
|
||||||
|
playSound(Sound.BLOCK_ANVIL_USE);
|
||||||
giveSalvage();
|
giveSalvage();
|
||||||
|
BlacksmithPlugin.getInstance().callEvent(new ScrapperSalvageSucceedEvent(this.npc, this.player));
|
||||||
sendNPCMessage(this.npc, this.player, this.config.getSuccessMessage());
|
sendNPCMessage(this.npc, this.player, this.config.getSuccessMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,6 +165,7 @@ public class SalvageSession extends Session implements Runnable {
|
|||||||
// TODO: Find a better calculation than 1 enchantment level = 1 exp level
|
// TODO: Find a better calculation than 1 enchantment level = 1 exp level
|
||||||
// Gives the player back some of the EXP used on an item
|
// Gives the player back some of the EXP used on an item
|
||||||
this.player.giveExpLevels(this.enchantmentLevels);
|
this.player.giveExpLevels(this.enchantmentLevels);
|
||||||
|
BlacksmithPlugin.debug("Giving salvage " + this.salvage);
|
||||||
for (ItemStack item : this.salvage) {
|
for (ItemStack item : this.salvage) {
|
||||||
giveResultingItem(this.config.getMaxSalvageDelay() > 0, this.config.getDropItem(), this.npc, item);
|
giveResultingItem(this.config.getMaxSalvageDelay() > 0, this.config.getDropItem(), this.npc, item);
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,15 @@ package net.knarcraft.blacksmith.trait;
|
|||||||
|
|
||||||
import net.citizensnpcs.api.util.DataKey;
|
import net.citizensnpcs.api.util.DataKey;
|
||||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||||
import net.knarcraft.blacksmith.config.SalvageMethod;
|
|
||||||
import net.knarcraft.blacksmith.config.SmithPreset;
|
import net.knarcraft.blacksmith.config.SmithPreset;
|
||||||
import net.knarcraft.blacksmith.config.SmithPresetFilter;
|
import net.knarcraft.blacksmith.config.SmithPresetFilter;
|
||||||
import net.knarcraft.blacksmith.config.scrapper.ScrapperNPCSettings;
|
import net.knarcraft.blacksmith.config.scrapper.ScrapperNPCSettings;
|
||||||
import net.knarcraft.blacksmith.config.scrapper.ScrapperSetting;
|
import net.knarcraft.blacksmith.config.scrapper.ScrapperSetting;
|
||||||
|
import net.knarcraft.blacksmith.container.RecipeResult;
|
||||||
|
import net.knarcraft.blacksmith.container.SalvageResult;
|
||||||
import net.knarcraft.blacksmith.manager.EconomyManager;
|
import net.knarcraft.blacksmith.manager.EconomyManager;
|
||||||
|
import net.knarcraft.blacksmith.property.SalvageMethod;
|
||||||
|
import net.knarcraft.blacksmith.property.SalvageState;
|
||||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||||
import net.knarcraft.blacksmith.util.SalvageHelper;
|
import net.knarcraft.blacksmith.util.SalvageHelper;
|
||||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||||
@ -20,6 +23,7 @@ import org.bukkit.inventory.meta.ArmorMeta;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -88,66 +92,147 @@ public class ScrapperTrait extends CustomTrait<ScrapperSetting> {
|
|||||||
if (!canBeSalvaged(itemInHand, salvageAbleItems, extended)) {
|
if (!canBeSalvaged(itemInHand, salvageAbleItems, extended)) {
|
||||||
sendNPCMessage(this.npc, player, StringFormatter.replacePlaceholder(getSettings().getInvalidItemMessage(),
|
sendNPCMessage(this.npc, player, StringFormatter.replacePlaceholder(getSettings().getInvalidItemMessage(),
|
||||||
"{title}", getSettings().getScrapperTitle()));
|
"{title}", getSettings().getScrapperTitle()));
|
||||||
|
BlacksmithPlugin.debug("Cannot salvage provided item: " + itemInHand);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ItemStack> salvage = null;
|
SalvageResult result = getBestResult(player, itemInHand, extended);
|
||||||
|
|
||||||
// Deal with armor trim salvage
|
if (result == null || result.salvage().isEmpty()) {
|
||||||
SalvageMethod salvageMethod = SalvageMethod.SALVAGE;
|
|
||||||
if (itemInHand.getItemMeta() instanceof ArmorMeta armorMeta && armorMeta.hasTrim()) {
|
|
||||||
if (!getSettings().salvageArmorTrims()) {
|
|
||||||
sendNPCMessage(this.npc, player, getSettings().getCannotSalvageArmorTrimMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
salvage = SalvageHelper.getArmorTrimSalvage(itemInHand, armorMeta);
|
|
||||||
if (salvage == null) {
|
|
||||||
sendNPCMessage(this.npc, player, getSettings().getArmorTrimSalvageNotFoundMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
salvageMethod = SalvageMethod.ARMOR_TRIM;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the netherite ingot from the item
|
|
||||||
if (salvage == null && SmithPreset.BLACKSMITH.getFilteredMaterials(SmithPresetFilter.NETHERITE).contains(itemInHand.getType())) {
|
|
||||||
if (!getSettings().salvageNetherite()) {
|
|
||||||
sendNPCMessage(this.npc, player, getSettings().getCannotSalvageNetheriteMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
salvage = SalvageHelper.getNetheriteSalvage(itemInHand);
|
|
||||||
salvageMethod = SalvageMethod.NETHERITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// As there is no recipe for netherite items, the check needs to be after the netherite salvage check
|
|
||||||
if (salvageMethod == SalvageMethod.SALVAGE && !SalvageHelper.isSalvageable(player.getServer(), itemInHand)) {
|
|
||||||
sendNPCMessage(this.npc, player, StringFormatter.replacePlaceholder(getSettings().getInvalidItemMessage(),
|
|
||||||
"{title}", getSettings().getScrapperTitle()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the item is enchanted, and whether this blacksmith can salvage it
|
|
||||||
if (!itemInHand.getEnchantments().isEmpty() && !getSettings().salvageEnchanted()) {
|
|
||||||
sendNPCMessage(this.npc, player, getSettings().getCannotSalvageEnchantedMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if any salvage will be produced
|
|
||||||
if (salvage == null) {
|
|
||||||
salvage = getSalvage(itemInHand, extended);
|
|
||||||
}
|
|
||||||
boolean noUsefulSalvage = salvage == null || salvage.isEmpty();
|
|
||||||
if (noUsefulSalvage) {
|
|
||||||
sendNPCMessage(this.npc, player, getSettings().getTooDamagedMessage());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Start a new scrapper session for the player
|
//Start a new scrapper session for the player
|
||||||
currentSessionStartTime = System.currentTimeMillis();
|
currentSessionStartTime = System.currentTimeMillis();
|
||||||
int itemsConsumed = SalvageHelper.getRequiredAmountForSalvage(player.getServer(), itemInHand);
|
session = new SalvageSession(this, player, npc, getSettings(), result.salvage(),
|
||||||
session = new SalvageSession(this, player, npc, getSettings(), salvage, salvageMethod, itemsConsumed);
|
result.salvageMethod(), result.requiredAmount());
|
||||||
// Print the cost to the player
|
// Print the cost to the player
|
||||||
printCostMessage(player, itemInHand, EconomyManager.formatSalvageCost(salvageMethod), salvageMethod);
|
printCostMessage(player, itemInHand, EconomyManager.formatSalvageCost(result.salvageMethod()),
|
||||||
|
result.salvageMethod());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the best available salvage result
|
||||||
|
*
|
||||||
|
* @param player <p>The player attempting to salvage an item</p>
|
||||||
|
* @param itemInHand <p>The item the player is attempting to salvage</p>
|
||||||
|
* @param extended <p>Whether extended salvage is enabled</p>
|
||||||
|
* @return <p>The best result, or null if no valid result exists</p>
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private SalvageResult getBestResult(@NotNull Player player, @NotNull ItemStack itemInHand, boolean extended) {
|
||||||
|
SalvageResult result = isArmorTrimSalvage(player, itemInHand);
|
||||||
|
if (result.salvageState() == SalvageState.NO_SALVAGE) {
|
||||||
|
return null;
|
||||||
|
} else if (result.salvageState() == SalvageState.FOUND_SALVAGE) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = isNetheriteSalvage(player, itemInHand);
|
||||||
|
if (result.salvageState() == SalvageState.NO_SALVAGE) {
|
||||||
|
return null;
|
||||||
|
} else if (result.salvageState() == SalvageState.FOUND_SALVAGE) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = isNormalSalvage(player, itemInHand, extended);
|
||||||
|
if (result.salvageState() == SalvageState.NO_SALVAGE) {
|
||||||
|
return null;
|
||||||
|
} else if (result.salvageState() == SalvageState.FOUND_SALVAGE) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the result of trying to salvage the item normally
|
||||||
|
*
|
||||||
|
* @param player <p>The player trying to salvage the item</p>
|
||||||
|
* @param itemInHand <p>The item to be salvaged</p>
|
||||||
|
* @param extended <p>Whether extended salvage is enabled</p>
|
||||||
|
* @return <p>The result of attempting the salvage</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private SalvageResult isNormalSalvage(@NotNull Player player, @NotNull ItemStack itemInHand, boolean extended) {
|
||||||
|
|
||||||
|
// As there is no recipe for netherite items, the check needs to be after the netherite salvage check
|
||||||
|
if (!SalvageHelper.isSalvageable(player.getServer(), itemInHand)) {
|
||||||
|
sendNPCMessage(this.npc, player, StringFormatter.replacePlaceholder(getSettings().getInvalidItemMessage(),
|
||||||
|
"{title}", getSettings().getScrapperTitle()));
|
||||||
|
BlacksmithPlugin.debug("Provided with non-salvage-able item " + itemInHand);
|
||||||
|
return new SalvageResult(SalvageMethod.SALVAGE, new ArrayList<>(), SalvageState.NO_SALVAGE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the item is enchanted, and whether this blacksmith can salvage it
|
||||||
|
if (!itemInHand.getEnchantments().isEmpty() && !getSettings().salvageEnchanted()) {
|
||||||
|
sendNPCMessage(this.npc, player, getSettings().getCannotSalvageEnchantedMessage());
|
||||||
|
return new SalvageResult(SalvageMethod.SALVAGE, new ArrayList<>(), SalvageState.NO_SALVAGE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any salvage will be produced
|
||||||
|
RecipeResult recipeResult = getSalvage(itemInHand, extended);
|
||||||
|
boolean noUsefulSalvage = recipeResult == null || recipeResult.salvage().isEmpty();
|
||||||
|
if (noUsefulSalvage) {
|
||||||
|
sendNPCMessage(this.npc, player, getSettings().getTooDamagedMessage());
|
||||||
|
return new SalvageResult(SalvageMethod.SALVAGE, new ArrayList<>(), SalvageState.NO_SALVAGE, 0);
|
||||||
|
} else {
|
||||||
|
return new SalvageResult(SalvageMethod.SALVAGE, recipeResult.salvage(), SalvageState.FOUND_SALVAGE,
|
||||||
|
recipeResult.recipe().getResult().getAmount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the result of trying to salvage the item as a netherite applied item
|
||||||
|
*
|
||||||
|
* @param player <p>The player trying to salvage the item</p>
|
||||||
|
* @param itemInHand <p>The item to be salvaged</p>
|
||||||
|
* @return <p>The result of attempting the salvage</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private SalvageResult isNetheriteSalvage(@NotNull Player player, @NotNull ItemStack itemInHand) {
|
||||||
|
if (!SmithPreset.BLACKSMITH.getFilteredMaterials(SmithPresetFilter.NETHERITE).contains(itemInHand.getType())) {
|
||||||
|
return new SalvageResult(SalvageMethod.NETHERITE, new ArrayList<>(), SalvageState.INCORRECT_METHOD, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!getSettings().salvageNetherite()) {
|
||||||
|
sendNPCMessage(this.npc, player, getSettings().getCannotSalvageNetheriteMessage());
|
||||||
|
return new SalvageResult(SalvageMethod.NETHERITE, new ArrayList<>(), SalvageState.NO_SALVAGE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ItemStack> salvage = SalvageHelper.getNetheriteSalvage(itemInHand);
|
||||||
|
if (salvage == null || salvage.isEmpty()) {
|
||||||
|
return new SalvageResult(SalvageMethod.NETHERITE, new ArrayList<>(), SalvageState.NO_SALVAGE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SalvageResult(SalvageMethod.NETHERITE, salvage, SalvageState.FOUND_SALVAGE, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the result of trying to salvage the item as an armor trim
|
||||||
|
*
|
||||||
|
* @param player <p>The player trying to salvage the item</p>
|
||||||
|
* @param itemInHand <p>The item to be salvaged</p>
|
||||||
|
* @return <p>The result of attempting the salvage</p>
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private SalvageResult isArmorTrimSalvage(@NotNull Player player, @NotNull ItemStack itemInHand) {
|
||||||
|
if (!(itemInHand.getItemMeta() instanceof ArmorMeta armorMeta) || !armorMeta.hasTrim()) {
|
||||||
|
return new SalvageResult(SalvageMethod.ARMOR_TRIM, new ArrayList<>(), SalvageState.INCORRECT_METHOD, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!getSettings().salvageArmorTrims()) {
|
||||||
|
sendNPCMessage(this.npc, player, getSettings().getCannotSalvageArmorTrimMessage());
|
||||||
|
return new SalvageResult(SalvageMethod.ARMOR_TRIM, new ArrayList<>(), SalvageState.NO_SALVAGE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ItemStack> salvage = SalvageHelper.getArmorTrimSalvage(itemInHand, armorMeta);
|
||||||
|
if (salvage == null || salvage.isEmpty()) {
|
||||||
|
sendNPCMessage(this.npc, player, getSettings().getArmorTrimSalvageNotFoundMessage());
|
||||||
|
return new SalvageResult(SalvageMethod.ARMOR_TRIM, new ArrayList<>(), SalvageState.NO_SALVAGE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SalvageResult(SalvageMethod.ARMOR_TRIM, salvage, SalvageState.FOUND_SALVAGE, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,7 +290,7 @@ public class ScrapperTrait extends CustomTrait<ScrapperSetting> {
|
|||||||
* @return <p>The possible salvage, or null if not salvage-able</p>
|
* @return <p>The possible salvage, or null if not salvage-able</p>
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private List<ItemStack> getSalvage(@NotNull ItemStack item, boolean extended) {
|
private RecipeResult getSalvage(@NotNull ItemStack item, boolean extended) {
|
||||||
// Get the salvage, for the item, but ignore some materials if set, and the item isn't at full durability
|
// Get the salvage, for the item, but ignore some materials if set, and the item isn't at full durability
|
||||||
Set<Material> trashSalvage = BlacksmithPlugin.getInstance().getGlobalScrapperSettings().getTrashSalvage(
|
Set<Material> trashSalvage = BlacksmithPlugin.getInstance().getGlobalScrapperSettings().getTrashSalvage(
|
||||||
item.getType());
|
item.getType());
|
||||||
|
@ -2,14 +2,20 @@ package net.knarcraft.blacksmith.trait;
|
|||||||
|
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||||
|
import net.knarcraft.blacksmith.event.BlacksmithReforgeStartEvent;
|
||||||
|
import net.knarcraft.blacksmith.event.NPCSoundEvent;
|
||||||
|
import net.knarcraft.blacksmith.event.ScrapperSalvageStartEvent;
|
||||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.SoundCategory;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A runnable session for performing a reforging/salvage task
|
* A runnable session for performing a reforging/salvage task
|
||||||
@ -18,6 +24,7 @@ public abstract class Session implements Runnable {
|
|||||||
|
|
||||||
protected static final Random random = new Random();
|
protected static final Random random = new Random();
|
||||||
protected final Player player;
|
protected final Player player;
|
||||||
|
protected final NPC npc;
|
||||||
protected long finishTime;
|
protected long finishTime;
|
||||||
protected int taskId;
|
protected int taskId;
|
||||||
|
|
||||||
@ -25,9 +32,11 @@ public abstract class Session implements Runnable {
|
|||||||
* Instantiates a new session
|
* Instantiates a new session
|
||||||
*
|
*
|
||||||
* @param player <p>The player the session belongs to</p>
|
* @param player <p>The player the session belongs to</p>
|
||||||
|
* @param npc <p>The NPC involved in the session</p>
|
||||||
*/
|
*/
|
||||||
public Session(@NotNull Player player) {
|
public Session(@NotNull Player player, @NotNull NPC npc) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.npc = npc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +98,15 @@ public abstract class Session implements Runnable {
|
|||||||
BukkitScheduler scheduler = BlacksmithPlugin.getInstance().getServer().getScheduler();
|
BukkitScheduler scheduler = BlacksmithPlugin.getInstance().getServer().getScheduler();
|
||||||
int actionDelay = getActionDelay();
|
int actionDelay = getActionDelay();
|
||||||
this.finishTime = System.currentTimeMillis() + (actionDelay * 1000L);
|
this.finishTime = System.currentTimeMillis() + (actionDelay * 1000L);
|
||||||
taskId = scheduler.scheduleSyncDelayedTask(BlacksmithPlugin.getInstance(), this, actionDelay * 20L);
|
long actionDelayTicks = actionDelay * 20L;
|
||||||
|
|
||||||
|
if (this instanceof ReforgeSession) {
|
||||||
|
BlacksmithPlugin.getInstance().callEvent(new BlacksmithReforgeStartEvent(npc, player, actionDelayTicks));
|
||||||
|
} else if (this instanceof SalvageSession) {
|
||||||
|
BlacksmithPlugin.getInstance().callEvent(new ScrapperSalvageStartEvent(npc, player, actionDelayTicks));
|
||||||
|
}
|
||||||
|
|
||||||
|
taskId = scheduler.scheduleSyncDelayedTask(BlacksmithPlugin.getInstance(), this, actionDelayTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,7 +146,7 @@ public abstract class Session implements Runnable {
|
|||||||
newDurability = (short) (maxDurability - random.nextInt(maxDurability - 25));
|
newDurability = (short) (maxDurability - random.nextInt(maxDurability - 25));
|
||||||
}
|
}
|
||||||
if (ItemHelper.updateDamage(item, maxDurability - newDurability)) {
|
if (ItemHelper.updateDamage(item, maxDurability - newDurability)) {
|
||||||
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Unable to update damage for " + item);
|
BlacksmithPlugin.warn("Unable to update damage for " + item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,4 +157,35 @@ public abstract class Session implements Runnable {
|
|||||||
*/
|
*/
|
||||||
protected abstract int getActionDelay();
|
protected abstract int getActionDelay();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plays an NPC sound
|
||||||
|
*
|
||||||
|
* @param sound <p>The sound to play</p>
|
||||||
|
*/
|
||||||
|
protected void playSound(Sound sound) {
|
||||||
|
playSound(this.npc.getEntity(), sound);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plays a npc sound using a cancellable event
|
||||||
|
*
|
||||||
|
* @param entity <p>The entity that should play the sound</p>
|
||||||
|
* @param sound <p>The sound to play</p>
|
||||||
|
*/
|
||||||
|
private void playSound(@NotNull Entity entity, @NotNull Sound sound) {
|
||||||
|
World world = entity.getLocation().getWorld();
|
||||||
|
if (world == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NPCSoundEvent event = new NPCSoundEvent(this.npc, this.player, SoundCategory.AMBIENT, sound, 0.5f, 1.0f);
|
||||||
|
BlacksmithPlugin.getInstance().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
world.playSound(event.getNpc().getEntity(), event.getSound(), event.getSoundCategory(), event.getVolume(),
|
||||||
|
event.getPitch());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ import java.io.InputStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper class for getting an object value as the correct type
|
* A helper class for getting an object value as the correct type
|
||||||
@ -120,7 +119,7 @@ public final class ConfigHelper {
|
|||||||
try {
|
try {
|
||||||
currentConfiguration.save(new File(dataFolderPath, "config.yml.old"));
|
currentConfiguration.save(new File(dataFolderPath, "config.yml.old"));
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
instance.getLogger().log(Level.WARNING, "Unable to save old backup and do migration");
|
BlacksmithPlugin.warn("Unable to save old backup and do migration");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,8 +128,7 @@ public final class ConfigHelper {
|
|||||||
FileConfiguration oldConfiguration = instance.getConfig();
|
FileConfiguration oldConfiguration = instance.getConfig();
|
||||||
InputStream configStream = FileHelper.getInputStreamForInternalFile("/config.yml");
|
InputStream configStream = FileHelper.getInputStreamForInternalFile("/config.yml");
|
||||||
if (configStream == null) {
|
if (configStream == null) {
|
||||||
instance.getLogger().log(Level.SEVERE, "Could not migrate the configuration, as the internal " +
|
BlacksmithPlugin.error("Could not migrate the configuration, as the internal configuration could not be read!");
|
||||||
"configuration could not be read!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
YamlConfiguration newConfiguration = StargateYamlConfiguration.loadConfiguration(
|
YamlConfiguration newConfiguration = StargateYamlConfiguration.loadConfiguration(
|
||||||
@ -141,13 +139,13 @@ public final class ConfigHelper {
|
|||||||
try {
|
try {
|
||||||
InputStream migrationStream = FileHelper.getInputStreamForInternalFile("/config-migrations.txt");
|
InputStream migrationStream = FileHelper.getInputStreamForInternalFile("/config-migrations.txt");
|
||||||
if (migrationStream == null) {
|
if (migrationStream == null) {
|
||||||
instance.getLogger().log(Level.SEVERE, "Could not migrate the configuration, as the internal migration paths could not be read!");
|
BlacksmithPlugin.error("Could not migrate the configuration, as the internal migration paths could not be read!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
migrationFields = FileHelper.readKeyValuePairs(FileHelper.getBufferedReaderFromInputStream(migrationStream),
|
migrationFields = FileHelper.readKeyValuePairs(FileHelper.getBufferedReaderFromInputStream(migrationStream),
|
||||||
"=", ColorConversion.NORMAL);
|
"=", ColorConversion.NORMAL);
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
instance.getLogger().log(Level.WARNING, "Unable to load config migration file");
|
BlacksmithPlugin.warn("Unable to load config migration file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +167,7 @@ public final class ConfigHelper {
|
|||||||
try {
|
try {
|
||||||
newConfiguration.save(new File(dataFolderPath, "config.yml"));
|
newConfiguration.save(new File(dataFolderPath, "config.yml"));
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
instance.getLogger().log(Level.WARNING, "Unable to save migrated config");
|
BlacksmithPlugin.warn("Unable to save migrated config");
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.reloadConfig();
|
instance.reloadConfig();
|
||||||
|
@ -14,7 +14,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper class for getting information about items
|
* A helper class for getting information about items
|
||||||
@ -105,6 +104,9 @@ public final class ItemHelper {
|
|||||||
public static @NotNull Set<Material> getAllReforgeAbleMaterials() {
|
public static @NotNull Set<Material> getAllReforgeAbleMaterials() {
|
||||||
Set<Material> reforgeAbleMaterials = new HashSet<>();
|
Set<Material> reforgeAbleMaterials = new HashSet<>();
|
||||||
for (Material material : Material.values()) {
|
for (Material material : Material.values()) {
|
||||||
|
if (!material.isItem()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ItemStack item = new ItemStack(material);
|
ItemStack item = new ItemStack(material);
|
||||||
if (isRepairable(item)) {
|
if (isRepairable(item)) {
|
||||||
reforgeAbleMaterials.add(material);
|
reforgeAbleMaterials.add(material);
|
||||||
@ -227,8 +229,7 @@ public final class ItemHelper {
|
|||||||
blacklisted.add(material);
|
blacklisted.add(material);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Unable to verify " + item +
|
BlacksmithPlugin.warn("Unable to verify " + item + " as a valid repairable item");
|
||||||
" as a valid repairable item");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.knarcraft.blacksmith.util;
|
package net.knarcraft.blacksmith.util;
|
||||||
|
|
||||||
|
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||||
|
import net.knarcraft.blacksmith.container.RecipeResult;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@ -122,23 +124,6 @@ public final class SalvageHelper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the amount of an item that's required to salvage that item
|
|
||||||
*
|
|
||||||
* @param server <p>The server to get recipes from</p>
|
|
||||||
* @param item <p>The item to check</p>
|
|
||||||
* @return <p>The number of items required for salvage, or -1 if the recipe was not found</p>
|
|
||||||
*/
|
|
||||||
public static int getRequiredAmountForSalvage(@NotNull Server server, @NotNull ItemStack item) {
|
|
||||||
for (Recipe recipe : server.getRecipesFor(new ItemStack(item.getType(), item.getAmount()))) {
|
|
||||||
// Only crafting recipes are allowed.
|
|
||||||
if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) {
|
|
||||||
return recipe.getResult().getAmount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the sum of all enchantment levels for the given item
|
* Gets the sum of all enchantment levels for the given item
|
||||||
*
|
*
|
||||||
@ -164,19 +149,34 @@ public final class SalvageHelper {
|
|||||||
* @param extended <p>Whether to enable extended salvage, ignoring the repairable restriction</p>
|
* @param extended <p>Whether to enable extended salvage, ignoring the repairable restriction</p>
|
||||||
* @return <p>The items to return to the user, or null if not salvageable</p>
|
* @return <p>The items to return to the user, or null if not salvageable</p>
|
||||||
*/
|
*/
|
||||||
public static @Nullable List<ItemStack> getSalvage(@NotNull Server server, @Nullable ItemStack salvagedItem,
|
public static @Nullable RecipeResult getSalvage(@NotNull Server server, @Nullable ItemStack salvagedItem,
|
||||||
@NotNull Collection<Material> trashSalvage, boolean extended) {
|
@NotNull Collection<Material> trashSalvage, boolean extended) {
|
||||||
if (salvagedItem == null || salvagedItem.getAmount() < 1 ||
|
if (salvagedItem == null || salvagedItem.getAmount() < 1 ||
|
||||||
(!extended && !ItemHelper.isRepairable(salvagedItem))) {
|
(!extended && !ItemHelper.isRepairable(salvagedItem))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Recipe recipe : server.getRecipesFor(new ItemStack(salvagedItem.getType(), salvagedItem.getAmount()))) {
|
for (Recipe recipe : server.getRecipesFor(new ItemStack(salvagedItem.getType(), salvagedItem.getAmount()))) {
|
||||||
if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) {
|
BlacksmithPlugin.debug("Considering recipe: " + recipe.getResult() + " -> " + getRawRecipeSalvage(recipe));
|
||||||
List<ItemStack> salvage = getRecipeSalvage(recipe, salvagedItem, trashSalvage);
|
|
||||||
if (salvage != null && !salvage.isEmpty()) {
|
// Only consider crafting table recipes
|
||||||
return salvage;
|
if (!(recipe instanceof ShapedRecipe) && !(recipe instanceof ShapelessRecipe)) {
|
||||||
}
|
BlacksmithPlugin.debug("Recipe had invalid type");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the player has enough items
|
||||||
|
if (salvagedItem.getAmount() < recipe.getResult().getAmount()) {
|
||||||
|
BlacksmithPlugin.debug("Too few items for recipe");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get actual salvage, as long as any can be produced
|
||||||
|
List<ItemStack> salvage = getRecipeSalvage(recipe, salvagedItem, trashSalvage);
|
||||||
|
if (salvage != null && !salvage.isEmpty()) {
|
||||||
|
BlacksmithPlugin.debug("Valid recipe: " + recipe.getResult() + " -> " + getRawRecipeSalvage(recipe));
|
||||||
|
BlacksmithPlugin.debug("Actual salvage: " + salvage);
|
||||||
|
return new RecipeResult(recipe, salvage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,19 +193,17 @@ public final class SalvageHelper {
|
|||||||
*/
|
*/
|
||||||
private static @Nullable List<ItemStack> getRecipeSalvage(@NotNull Recipe recipe, @NotNull ItemStack salvagedItem,
|
private static @Nullable List<ItemStack> getRecipeSalvage(@NotNull Recipe recipe, @NotNull ItemStack salvagedItem,
|
||||||
@NotNull Collection<Material> trashSalvage) {
|
@NotNull Collection<Material> trashSalvage) {
|
||||||
List<ItemStack> ingredients;
|
List<ItemStack> ingredients = getRawRecipeSalvage(recipe);
|
||||||
if (recipe instanceof ShapedRecipe shapedRecipe) {
|
if (ingredients == null) {
|
||||||
ingredients = getIngredients(shapedRecipe);
|
|
||||||
} else if (recipe instanceof ShapelessRecipe shapelessRecipe) {
|
|
||||||
ingredients = shapelessRecipe.getIngredientList();
|
|
||||||
} else {
|
|
||||||
//Recipes other than crafting shouldn't be considered for salvaging
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//Make things easier by eliminating identical stacks
|
List<ItemStack> copy = copyItems(ingredients);
|
||||||
ingredients = combineStacks(ingredients);
|
BlacksmithPlugin.debug("Copied salvage: " + copy);
|
||||||
|
List<ItemStack> salvage = getSalvage(copy, salvagedItem, trashSalvage);
|
||||||
return combineStacks(getSalvage(copyItems(ingredients), salvagedItem, trashSalvage));
|
BlacksmithPlugin.debug("Combining salvage: " + salvage);
|
||||||
|
List<ItemStack> combined = combineStacks(salvage);
|
||||||
|
BlacksmithPlugin.debug("Combined : " + combined);
|
||||||
|
return combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -240,12 +238,15 @@ public final class SalvageHelper {
|
|||||||
int maxDurability = ItemHelper.getMaxDurability(salvagedItem);
|
int maxDurability = ItemHelper.getMaxDurability(salvagedItem);
|
||||||
|
|
||||||
// Prevent divide by zero for items that don't have a set max durability
|
// Prevent divide by zero for items that don't have a set max durability
|
||||||
if (maxDurability == 0) {
|
if (maxDurability <= 0) {
|
||||||
maxDurability = 1;
|
maxDurability = 1;
|
||||||
durability = 1;
|
durability = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BlacksmithPlugin.debug("Durability: " + durability + "/" + maxDurability);
|
||||||
|
|
||||||
double percentageRemaining = (double) durability / maxDurability;
|
double percentageRemaining = (double) durability / maxDurability;
|
||||||
|
BlacksmithPlugin.debug("Remaining: " + percentageRemaining);
|
||||||
return pickRandomSalvage(recipeItems, trashSalvage, percentageRemaining);
|
return pickRandomSalvage(recipeItems, trashSalvage, percentageRemaining);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,36 +267,47 @@ public final class SalvageHelper {
|
|||||||
percentageRemaining = 1;
|
percentageRemaining = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalItems = totalItemAmount(itemsToChooseFrom);
|
// If not damaged, just give everything
|
||||||
//Get the amount of recipe items to be returned
|
if (percentageRemaining == 1) {
|
||||||
int itemsToReturn = (int) Math.floor(percentageRemaining * totalItems);
|
BlacksmithPlugin.debug("100% Remaining. Copying " + itemsToChooseFrom);
|
||||||
int bound = itemsToChooseFrom.size();
|
return copyItems(itemsToChooseFrom);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split into good items and trash items
|
||||||
List<ItemStack> goodItems = copyItems(itemsToChooseFrom);
|
List<ItemStack> goodItems = copyItems(itemsToChooseFrom);
|
||||||
goodItems.removeIf((item) -> trashSalvage.contains(item.getType()));
|
goodItems.removeIf((item) -> trashSalvage.contains(item.getType()));
|
||||||
int goodSalvage = totalItemAmount(goodItems);
|
List<ItemStack> trashItems = copyItems(itemsToChooseFrom);
|
||||||
|
trashItems.removeIf((item) -> !trashSalvage.contains(item.getType()));
|
||||||
|
|
||||||
List<ItemStack> salvage = new ArrayList<>();
|
int itemsToReturn = (int) Math.floor(totalItemAmount(itemsToChooseFrom) * percentageRemaining);
|
||||||
for (int i = 0; i < itemsToReturn; i++) {
|
int goodItemAmount = totalItemAmount(goodItems);
|
||||||
// Pick random item
|
int pickedItems = 0;
|
||||||
int itemIndex = SalvageHelper.random.nextInt(bound);
|
List<ItemStack> salvage = new ArrayList<>(itemsToReturn);
|
||||||
ItemStack itemStack = itemsToChooseFrom.get(itemIndex);
|
|
||||||
|
|
||||||
// The selected item is trash, so skip it
|
while (pickedItems < itemsToReturn && pickedItems < goodItemAmount) {
|
||||||
if (trashSalvage.contains(itemStack.getType()) && i < goodSalvage) {
|
int index = SalvageHelper.random.nextInt(goodItems.size());
|
||||||
i--;
|
ItemStack itemStack = goodItems.get(index);
|
||||||
|
if (itemStack.getType().isAir() || itemStack.getAmount() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Make sure to never give more of one item than the amount which exists in the recipe
|
|
||||||
if (itemStack.getAmount() <= 0) {
|
|
||||||
i--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
|
||||||
salvage.add(new ItemStack(itemStack.getType(), 1));
|
salvage.add(new ItemStack(itemStack.getType(), 1));
|
||||||
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
|
pickedItems++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (pickedItems < itemsToReturn) {
|
||||||
|
int index = SalvageHelper.random.nextInt(trashItems.size());
|
||||||
|
ItemStack itemStack = trashItems.get(index);
|
||||||
|
if (itemStack.getType().isAir() || itemStack.getAmount() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
salvage.add(new ItemStack(itemStack.getType(), 1));
|
||||||
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
|
pickedItems++;
|
||||||
|
}
|
||||||
|
|
||||||
return salvage;
|
return salvage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +338,7 @@ public final class SalvageHelper {
|
|||||||
Map<Material, Integer> itemAmounts = new HashMap<>();
|
Map<Material, Integer> itemAmounts = new HashMap<>();
|
||||||
for (ItemStack item : items) {
|
for (ItemStack item : items) {
|
||||||
Material itemType = item.getType();
|
Material itemType = item.getType();
|
||||||
itemAmounts.put(itemType, itemAmounts.getOrDefault(itemType, 0) + 1);
|
itemAmounts.put(itemType, itemAmounts.getOrDefault(itemType, 0) + item.getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ItemStack> combined = new ArrayList<>();
|
List<ItemStack> combined = new ArrayList<>();
|
||||||
@ -336,6 +348,26 @@ public final class SalvageHelper {
|
|||||||
return combined;
|
return combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the raw salvage of a recipe, assuming full salvage would be possible
|
||||||
|
*
|
||||||
|
* @param recipe <p>The recipe to get salvage for</p>
|
||||||
|
* @return <p>The salvage resulting from the recipe</p>
|
||||||
|
*/
|
||||||
|
private static List<ItemStack> getRawRecipeSalvage(@NotNull Recipe recipe) {
|
||||||
|
List<ItemStack> ingredients;
|
||||||
|
if (recipe instanceof ShapedRecipe shapedRecipe) {
|
||||||
|
ingredients = getIngredients(shapedRecipe);
|
||||||
|
} else if (recipe instanceof ShapelessRecipe shapelessRecipe) {
|
||||||
|
ingredients = shapelessRecipe.getIngredientList();
|
||||||
|
} else {
|
||||||
|
//Recipes other than crafting shouldn't be considered for salvaging
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//Make things easier by eliminating identical stacks
|
||||||
|
return combineStacks(ingredients);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all ingredients contained in the given shaped recipe
|
* Gets all ingredients contained in the given shaped recipe
|
||||||
*
|
*
|
||||||
|
@ -3,6 +3,7 @@ authors: [ EpicKnarvik97, aPunch, jrbudda, HurricanKai ]
|
|||||||
version: '${project.version}'
|
version: '${project.version}'
|
||||||
main: net.knarcraft.blacksmith.BlacksmithPlugin
|
main: net.knarcraft.blacksmith.BlacksmithPlugin
|
||||||
depend: [ Citizens, Vault ]
|
depend: [ Citizens, Vault ]
|
||||||
|
softdepend: [ ProtocolLib ]
|
||||||
prefix: "Blacksmith"
|
prefix: "Blacksmith"
|
||||||
description: "A plugin that adds Blacksmith and Scrapper traits compatible with Citizens, allowing players to repair and salvage items"
|
description: "A plugin that adds Blacksmith and Scrapper traits compatible with Citizens, allowing players to repair and salvage items"
|
||||||
website: "https://www.spigotmc.org/resources/blacksmith.105938/"
|
website: "https://www.spigotmc.org/resources/blacksmith.105938/"
|
||||||
|
Reference in New Issue
Block a user