From f254027f4be8c6fac7b703db78adb0630492dcfc Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 16 Aug 2018 00:04:40 +1000 Subject: [PATCH] Fix //wand --- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index ef6e392e8..c6c5a9fde 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -19,8 +19,11 @@ package com.sk89q.worldedit.bukkit; +import com.boydti.fawe.object.RunnableVal; +import com.boydti.fawe.util.TaskManager; import com.sk89q.util.StringUtil; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -37,9 +40,15 @@ import com.sk89q.worldedit.world.gamemode.GameModes; import jdk.nashorn.internal.ir.Block; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Item; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import javax.annotation.Nullable; @@ -82,7 +91,34 @@ public class BukkitPlayer extends AbstractPlayerActor { @Override public void giveItem(BaseItemStack itemStack) { - player.getInventory().addItem(BukkitAdapter.adapt(itemStack)); + final PlayerInventory inv = player.getInventory(); + ItemStack newItem = BukkitAdapter.adapt(itemStack); + if (itemStack.getType() == WorldEdit.getInstance().getConfiguration().wandItem) { + inv.remove(newItem); + } + final ItemStack item = player.getItemInHand(); + player.setItemInHand(newItem); + if (item != null) { + HashMap overflow = inv.addItem(item); + if (overflow != null && !overflow.isEmpty()) { + TaskManager.IMP.sync(new RunnableVal() { + @Override + public void run(Object value) { + for (Map.Entry entry : overflow.entrySet()) { + ItemStack stack = entry.getValue(); + if (stack.getType() != Material.AIR && stack.getAmount() > 0) { + Item dropped = player.getWorld().dropItem(player.getLocation(), stack); + PlayerDropItemEvent event = new PlayerDropItemEvent(player, dropped); + if (event.isCancelled()) { + dropped.remove(); + } + } + } + } + }); + } + } + player.updateInventory(); } @Override