Broken commit implementing a lot of book-splitting code
Some checks failed
EpicKnarvik97/Blacksmith/pipeline/head There was a failure building this commit
Some checks failed
EpicKnarvik97/Blacksmith/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -5,6 +5,7 @@ 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.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@@ -54,10 +55,11 @@ public class EconomyManager {
|
||||
*
|
||||
* @param player <p>The player holding an item</p>
|
||||
* @param salvageMethod <p>The salvage method to check</p>
|
||||
* @param item <p>The item to be salvaged</p>
|
||||
* @return <p>Whether the player cannot pay for the salvage</p>
|
||||
*/
|
||||
public static boolean cannotPayForSalvage(@NotNull Player player, @NotNull SalvageMethod salvageMethod) {
|
||||
return economy.getBalance(player) - getSalvageCost(salvageMethod) < 0;
|
||||
public static boolean cannotPayForSalvage(@NotNull Player player, @NotNull SalvageMethod salvageMethod, @NotNull ItemStack item) {
|
||||
return economy.getBalance(player) - getSalvageCost(salvageMethod, item) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,11 +78,34 @@ public class EconomyManager {
|
||||
* Gets the human-readable cost of salvaging an item
|
||||
*
|
||||
* @param salvageMethod <p>The salvage method to get the cost for</p>
|
||||
* @param item <p>The item to be salvaged</p>
|
||||
* @return <p>The formatted cost</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String formatSalvageCost(@NotNull SalvageMethod salvageMethod) {
|
||||
return economy.format(getSalvageCost(salvageMethod));
|
||||
public static String formatSalvageCost(@NotNull SalvageMethod salvageMethod, @NotNull ItemStack item) {
|
||||
return economy.format(getSalvageCost(salvageMethod, item));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the given player has enough money to pay the given cost
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @param cost <p>The required cost</p>
|
||||
* @return <p>True if the player has enough money to cover the cost</p>
|
||||
*/
|
||||
public static boolean hasEnough(@NotNull Player player, double cost) {
|
||||
return economy.getBalance(player) >= cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a number as an economy cost
|
||||
*
|
||||
* @param cost <p>The cost to format</p>
|
||||
* @return <p>The formatted cost</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String format(double cost) {
|
||||
return economy.format(cost);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,12 +114,13 @@ public class EconomyManager {
|
||||
* @param salvageMethod <p>The salvage method to get cost for</p>
|
||||
* @return <p>The salvage cost</p>
|
||||
*/
|
||||
private static double getSalvageCost(@NotNull SalvageMethod salvageMethod) {
|
||||
private static double getSalvageCost(@NotNull SalvageMethod salvageMethod, @NotNull ItemStack item) {
|
||||
GlobalScrapperSettings settings = BlacksmithPlugin.getInstance().getGlobalScrapperSettings();
|
||||
return switch (salvageMethod) {
|
||||
case SALVAGE, EXTENDED_SALVAGE -> settings.getSalvageCost();
|
||||
case NETHERITE -> settings.getNetheriteSalvageCost();
|
||||
case ARMOR_TRIM -> settings.getArmorTrimSalvageCost();
|
||||
case ENCHANTED_BOOK -> getEnchantedBookSalvageCost(item);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -119,7 +145,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);
|
||||
double cost = getSalvageCost(salvageMethod, player.getInventory().getItemInMainHand());
|
||||
if (cost > 0) {
|
||||
economy.withdrawPlayer(player, cost);
|
||||
}
|
||||
@@ -183,6 +209,21 @@ public class EconomyManager {
|
||||
return price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cost of scrapping an enchanted book
|
||||
*
|
||||
* @param item <p>The enchanted book to calculate cost for</p>
|
||||
* @return <p>The cost of scrapping the enchanted book</p>
|
||||
*/
|
||||
private static double getEnchantedBookSalvageCost(@NotNull ItemStack item) {
|
||||
GlobalScrapperSettings settings = BlacksmithPlugin.getInstance().getGlobalScrapperSettings();
|
||||
double cost = settings.getEnchantedBookSalvageCost();
|
||||
if (settings.multiplyEnchantedBookSalvageCost()) {
|
||||
cost *= SalvageHelper.getEnchantmentCount(item) - 1;
|
||||
}
|
||||
return SalvageHelper.getEnchantmentCount(item) * cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up Vault for economy
|
||||
*
|
||||
|
Reference in New Issue
Block a user