From aa70240917c2b6698c20c60a101431ba73da29af Mon Sep 17 00:00:00 2001 From: Raphfrk Date: Fri, 29 Apr 2011 00:26:04 +0100 Subject: [PATCH] Added a setArmorContents method to PlayerInventory. It handles error checking. Null item stacks and air item stacks are both converted to clear slot calls to prevent crashing the client. --- .../inventory/CraftInventoryPlayer.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java index 68adab93a5..72c6a47890 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java @@ -71,4 +71,18 @@ public class CraftInventoryPlayer extends CraftInventory implements PlayerInvent } return ret; } + + public void setArmorContents(ItemStack[] items) { + int cnt = getSize(); + if (items == null) { + items = new ItemStack[4]; + } + for (ItemStack item : items) { + if (item == null || item.getTypeId() == 0) { + clear(cnt++); + } else { + setItem(cnt++, item); + } + } + } }