Finishes the scrapper implementation
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:
@ -7,10 +7,12 @@ 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.ItemHelper;
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -174,9 +176,17 @@ public abstract class CustomTrait<K extends Setting> extends Trait {
|
||||
*/
|
||||
private void startMainAction(@NotNull NPC npc, @NotNull Player player) {
|
||||
sendNPCMessage(this.npc, player, config.getStartWorkingMessage());
|
||||
// TODO: Differentiate between blacksmiths and scrappers when withdrawing money
|
||||
EconomyManager.withdraw(player);
|
||||
|
||||
boolean isBlacksmith = this instanceof BlacksmithTrait;
|
||||
|
||||
if (isBlacksmith) {
|
||||
EconomyManager.withdrawBlacksmith(player);
|
||||
} else {
|
||||
EconomyManager.withdrawScrapper(player);
|
||||
}
|
||||
|
||||
session.scheduleAction();
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||
|
||||
//Display the item in the NPC's hand
|
||||
@ -186,9 +196,16 @@ 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
|
||||
// TODO: For a scrapper with extended salvaging enabled, the item needs to be reduced with the amount specified
|
||||
// in the recipe, or removed as normal in the case where the player has exactly enough items to run the salvage.
|
||||
player.getInventory().setItemInMainHand(null);
|
||||
if (!isBlacksmith) {
|
||||
// For scrappers, just reduce the amounts of items, unless the remaining stack is salvaged
|
||||
int amount = ItemHelper.getRequiredAmountForSalvage(player.getServer(), heldItem);
|
||||
if (amount != heldItem.getAmount()) {
|
||||
heldItem.setAmount(heldItem.getAmount() - amount);
|
||||
playerInventory.setItemInMainHand(heldItem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
playerInventory.setItemInMainHand(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user