Rewrites a lot of scrapper code to fix actual and potential bugs
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good

This commit is contained in:
2024-07-29 17:53:07 +02:00
parent cf702c0e48
commit f3372a13a5
7 changed files with 158 additions and 86 deletions

View File

@ -7,7 +7,6 @@ import net.knarcraft.blacksmith.config.Settings;
import net.knarcraft.blacksmith.config.TraitSettings;
import net.knarcraft.blacksmith.formatting.TimeFormatter;
import net.knarcraft.blacksmith.manager.EconomyManager;
import net.knarcraft.blacksmith.util.SalvageHelper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import org.bukkit.entity.LivingEntity;
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);
}
//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
int amount = SalvageHelper.getRequiredAmountForSalvage(player.getServer(), heldItem);
int amount = salvageSession.getItemsConsumed();
if (amount != heldItem.getAmount()) {
heldItem.setAmount(heldItem.getAmount() - amount);
playerInventory.setItemInMainHand(heldItem);