Adds increased scrapper cost when used excessively
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
This commit is contained in:
@@ -5,8 +5,10 @@ import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings;
|
||||
import net.knarcraft.blacksmith.config.scrapper.GlobalScrapperSettings;
|
||||
import net.knarcraft.blacksmith.property.SalvageMethod;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
import net.knarcraft.blacksmith.util.SalvageHelper;
|
||||
import net.knarcraft.knarlib.formatting.StringReplacer;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.objecthunter.exp4j.Expression;
|
||||
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -59,7 +61,8 @@ public class EconomyManager {
|
||||
* @return <p>Whether the player cannot pay for the salvage</p>
|
||||
*/
|
||||
public static boolean cannotPayForSalvage(@NotNull Player player, @NotNull SalvageMethod salvageMethod, @NotNull ItemStack item) {
|
||||
return economy.getBalance(player) - getSalvageCost(salvageMethod, item) < 0;
|
||||
// TODO: Account for advanced cost options
|
||||
return economy.getBalance(player) - getSalvageCost(salvageMethod, item, player) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,11 +82,13 @@ public class EconomyManager {
|
||||
*
|
||||
* @param salvageMethod <p>The salvage method to get the cost for</p>
|
||||
* @param item <p>The item to be salvaged</p>
|
||||
* @param player <p>The player to provide the cost to</p>
|
||||
* @return <p>The formatted cost</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String formatSalvageCost(@NotNull SalvageMethod salvageMethod, @NotNull ItemStack item) {
|
||||
return economy.format(getSalvageCost(salvageMethod, item));
|
||||
public static String formatSalvageCost(@NotNull SalvageMethod salvageMethod, @NotNull ItemStack item,
|
||||
@NotNull Player player) {
|
||||
return economy.format(getSalvageCost(salvageMethod, item, player));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,16 +117,25 @@ public class EconomyManager {
|
||||
* Gets the cost of salvaging using the specified method
|
||||
*
|
||||
* @param salvageMethod <p>The salvage method to get cost for</p>
|
||||
* @param item <p>The item to be salvaged</p>
|
||||
* @return <p>The salvage cost</p>
|
||||
*/
|
||||
private static double getSalvageCost(@NotNull SalvageMethod salvageMethod, @NotNull ItemStack item) {
|
||||
private static double getSalvageCost(@NotNull SalvageMethod salvageMethod, @NotNull ItemStack item,
|
||||
@NotNull Player player) {
|
||||
GlobalScrapperSettings settings = BlacksmithPlugin.getInstance().getGlobalScrapperSettings();
|
||||
return switch (salvageMethod) {
|
||||
double baseCost = switch (salvageMethod) {
|
||||
case SALVAGE, EXTENDED_SALVAGE -> settings.getSalvageCost();
|
||||
case NETHERITE -> settings.getNetheriteSalvageCost();
|
||||
case ARMOR_TRIM -> settings.getArmorTrimSalvageCost();
|
||||
case ENCHANTED_BOOK -> getEnchantedBookSalvageCost(item);
|
||||
};
|
||||
|
||||
StringReplacer replacer = new StringReplacer(settings.getSalvageCostIncrease());
|
||||
replacer.add("{cost}", String.valueOf(baseCost));
|
||||
replacer.add("{timesUsed}", String.valueOf(PlayerUsageManager.getUsages(player,
|
||||
System.currentTimeMillis() - 3600000)));
|
||||
Expression expression = new ExpressionBuilder(replacer.replace()).build();
|
||||
return Math.max(expression.evaluate(), baseCost);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +159,7 @@ public class EconomyManager {
|
||||
* @param salvageMethod <p>The salvage method to withdraw for</p>
|
||||
*/
|
||||
public static void withdrawScrapper(@NotNull Player player, @NotNull SalvageMethod salvageMethod) {
|
||||
double cost = getSalvageCost(salvageMethod, player.getInventory().getItemInMainHand());
|
||||
double cost = getSalvageCost(salvageMethod, player.getInventory().getItemInMainHand(), player);
|
||||
if (cost > 0) {
|
||||
economy.withdrawPlayer(player, cost);
|
||||
}
|
||||
@@ -230,12 +244,15 @@ public class EconomyManager {
|
||||
* @return <p>The cost of scrapping the enchanted book</p>
|
||||
*/
|
||||
private static double getEnchantedBookSalvageCost(@NotNull ItemStack item) {
|
||||
GlobalScrapperSettings settings = BlacksmithPlugin.getInstance().getGlobalScrapperSettings();
|
||||
// TODO: Properly implement this
|
||||
/*GlobalScrapperSettings settings = BlacksmithPlugin.getInstance().getGlobalScrapperSettings();
|
||||
|
||||
double cost = settings.getEnchantedBookSalvageCost();
|
||||
if (settings.multiplyEnchantedBookSalvageCost()) {
|
||||
cost *= SalvageHelper.getEnchantmentCount(item) - 1;
|
||||
}
|
||||
return SalvageHelper.getEnchantmentCount(item) * cost;
|
||||
return SalvageHelper.getEnchantmentCount(item) * cost;*/
|
||||
return 1000000;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user