From 090eda1d0d8be1443b93cf6f670203594ebc5c16 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 26 Jul 2017 15:46:52 +1000 Subject: [PATCH] Better //wand --- .../com/sk89q/worldedit/bukkit/BukkitPlayer.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 0347c790..ad5a2ed1 100644 --- a/bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -27,6 +27,7 @@ import com.sk89q.worldedit.LocalPlayer; import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.ServerInterface; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.blocks.BaseBlock; @@ -47,6 +48,7 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.material.Dye; public class BukkitPlayer extends LocalPlayer { @@ -122,7 +124,17 @@ public class BukkitPlayer extends LocalPlayer { @Override public void giveItem(int type, int amt) { - player.getInventory().addItem(new ItemStack(type, amt)); + final PlayerInventory inv = player.getInventory(); + final ItemStack newItem = new ItemStack(type, amt); + if (type == WorldEdit.getInstance().getConfiguration().wandItem) { + inv.remove(newItem); + } + final ItemStack item = player.getItemInHand(); + player.setItemInHand(newItem); + if (item != null) { + inv.addItem(item); + } + player.updateInventory(); } @Override