Implements netherite salvaging #24
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:
@ -1,7 +1,9 @@
|
||||
package net.knarcraft.blacksmith.manager;
|
||||
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.SalvageMethod;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings;
|
||||
import net.knarcraft.blacksmith.config.scrapper.GlobalScrapperSettings;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Material;
|
||||
@ -54,11 +56,12 @@ public class EconomyManager {
|
||||
/**
|
||||
* Gets whether the given player cannot pay for salvaging an item
|
||||
*
|
||||
* @param player <p>The player holding an item</p>
|
||||
* @param player <p>The player holding an item</p>
|
||||
* @param salvageMethod <p>The salvage method to check</p>
|
||||
* @return <p>Whether the player cannot pay for the salvage</p>
|
||||
*/
|
||||
public static boolean cannotPayForSalvage(@NotNull Player player) {
|
||||
return economy.getBalance(player) - BlacksmithPlugin.getInstance().getGlobalScrapperSettings().getCost() < 0;
|
||||
public static boolean cannotPayForSalvage(@NotNull Player player, @NotNull SalvageMethod salvageMethod) {
|
||||
return economy.getBalance(player) - getSalvageCost(salvageMethod) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,12 +79,27 @@ public class EconomyManager {
|
||||
/**
|
||||
* Gets the human-readable cost of salvaging an item
|
||||
*
|
||||
* @param salvageMethod <p>The salvage method to get the cost for</p>
|
||||
* @return <p>The formatted cost</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String formatScrapperCost() {
|
||||
double cost = BlacksmithPlugin.getInstance().getGlobalScrapperSettings().getCost();
|
||||
return economy.format(cost);
|
||||
public static String formatSalvageCost(@NotNull SalvageMethod salvageMethod) {
|
||||
return economy.format(getSalvageCost(salvageMethod));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cost of salvaging using the specified method
|
||||
*
|
||||
* @param salvageMethod <p>The salvage method to get cost for</p>
|
||||
* @return <p>The salvage cost</p>
|
||||
*/
|
||||
private static double getSalvageCost(@NotNull SalvageMethod salvageMethod) {
|
||||
GlobalScrapperSettings settings = BlacksmithPlugin.getInstance().getGlobalScrapperSettings();
|
||||
return switch (salvageMethod) {
|
||||
case SALVAGE -> settings.getSalvageCost();
|
||||
case NETHERITE -> settings.getNetheriteSalvageCost();
|
||||
case ARMOR_TRIM -> settings.getArmorTrimSalvageCost();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,10 +119,11 @@ public class EconomyManager {
|
||||
/**
|
||||
* Withdraws the salvaging cost from the given player
|
||||
*
|
||||
* @param player <p>The player to withdraw from</p>
|
||||
* @param player <p>The player to withdraw from</p>
|
||||
* @param salvageMethod <p>The salvage method to withdraw for</p>
|
||||
*/
|
||||
public static void withdrawScrapper(Player player) {
|
||||
double cost = BlacksmithPlugin.getInstance().getGlobalScrapperSettings().getCost();
|
||||
public static void withdrawScrapper(@NotNull Player player, @NotNull SalvageMethod salvageMethod) {
|
||||
double cost = getSalvageCost(salvageMethod);
|
||||
if (cost > 0) {
|
||||
economy.withdrawPlayer(player, cost);
|
||||
}
|
||||
|
Reference in New Issue
Block a user