From f0a4f87f80e33a5f3ab14a688980427c50830528 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Thu, 27 Dec 2012 16:30:08 -0500 Subject: [PATCH] Add ability to change player item in hand. Adds BUKKIT-3318 By: Patrick Seidel --- .../craftbukkit/inventory/CraftInventoryPlayer.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java index 9c9594942e..50ae773a84 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java @@ -1,7 +1,10 @@ package org.bukkit.craftbukkit.inventory; +import net.minecraft.server.Packet16BlockItemSwitch; import net.minecraft.server.PlayerInventory; +import org.apache.commons.lang.Validate; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; @@ -33,6 +36,12 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i return getInventory().itemInHandIndex; } + public void setHeldItemSlot(int slot) { + Validate.isTrue(slot >= 0 && slot < PlayerInventory.getHotbarSize(), "Slot is not between 0 and 8 inclusive"); + this.getInventory().itemInHandIndex = slot; + ((CraftPlayer) this.getHolder()).getHandle().playerConnection.sendPacket(new Packet16BlockItemSwitch(slot)); + } + public ItemStack getHelmet() { return getItem(getSize() + 3); }