summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/craftbukkit/inventory
diff options
context:
space:
mode:
authorfeildmaster <admin@feildmaster.com>2012-12-09 00:09:48 -0600
committerfeildmaster <admin@feildmaster.com>2012-12-10 19:01:50 -0600
commit430d352a5a3d1f8d83276f0af43065b49e3b9822 (patch)
tree6759e3d728c1c799a688eea7b3bffc772be4c1a1 /src/main/java/org/bukkit/craftbukkit/inventory
parent684ba31c39560bc43d475332cda2a183e0ffa63a (diff)
downloadcraftbukkit-430d352a5a3d1f8d83276f0af43065b49e3b9822.tar
craftbukkit-430d352a5a3d1f8d83276f0af43065b49e3b9822.tar.gz
craftbukkit-430d352a5a3d1f8d83276f0af43065b49e3b9822.tar.lz
craftbukkit-430d352a5a3d1f8d83276f0af43065b49e3b9822.tar.xz
craftbukkit-430d352a5a3d1f8d83276f0af43065b49e3b9822.zip
Add EntityEquipment API. Adds BUKKIT-3103
Adds: - Getting/Setting equipment - getting/setting drop rates - getting/setting ability to pick up items -- As an added feature, players with this flag start off with a canceled PlayerPickupItemEvent
Diffstat (limited to 'src/main/java/org/bukkit/craftbukkit/inventory')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java142
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java43
2 files changed, 184 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java
new file mode 100644
index 00000000..f4066ca7
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java
@@ -0,0 +1,142 @@
+package org.bukkit.craftbukkit.inventory;
+
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.Entity;
+import org.bukkit.inventory.EntityEquipment;
+import org.bukkit.inventory.ItemStack;
+
+public class CraftEntityEquipment implements EntityEquipment {
+ private static final int WEAPON_SLOT = 0;
+ private static final int HELMET_SLOT = 1;
+ private static final int CHEST_SLOT = 2;
+ private static final int LEG_SLOT = 3;
+ private static final int BOOT_SLOT = 4;
+ private static final int INVENTORY_SLOTS = 5;
+
+ private final CraftLivingEntity entity;
+
+ public CraftEntityEquipment(CraftLivingEntity entity) {
+ this.entity = entity;
+ }
+
+ public ItemStack getItemInHand() {
+ return getEquipment(WEAPON_SLOT);
+ }
+
+ public void setItemInHand(ItemStack stack) {
+ setEquipment(WEAPON_SLOT, stack);
+ }
+
+ public ItemStack getHelmet() {
+ return getEquipment(HELMET_SLOT);
+ }
+
+ public void setHelmet(ItemStack helmet) {
+ setEquipment(HELMET_SLOT, helmet);
+ }
+
+ public ItemStack getChestplate() {
+ return getEquipment(CHEST_SLOT);
+ }
+
+ public void setChestplate(ItemStack chestplate) {
+ setEquipment(CHEST_SLOT, chestplate);
+ }
+
+ public ItemStack getLeggings() {
+ return getEquipment(LEG_SLOT);
+ }
+
+ public void setLeggings(ItemStack leggings) {
+ setEquipment(LEG_SLOT, leggings);
+ }
+
+ public ItemStack getBoots() {
+ return getEquipment(BOOT_SLOT);
+ }
+
+ public void setBoots(ItemStack boots) {
+ setEquipment(BOOT_SLOT, boots);
+ }
+
+ public ItemStack[] getArmorContents() {
+ ItemStack[] armor = new ItemStack[INVENTORY_SLOTS - 1];
+ for(int slot = HELMET_SLOT; slot < INVENTORY_SLOTS; slot++) {
+ armor[slot - 1] = getEquipment(slot);
+ }
+ return armor;
+ }
+
+ public void setArmorContents(ItemStack[] items) {
+ for(int slot = HELMET_SLOT; slot < INVENTORY_SLOTS; slot++) {
+ ItemStack equipment = items != null && slot <= items.length ? items[slot - 1] : null;
+ setEquipment(slot, equipment);
+ }
+ }
+
+ private ItemStack getEquipment(int slot) {
+ return CraftItemStack.asBukkitStack(entity.getHandle().getEquipment(slot));
+ }
+
+ private void setEquipment(int slot, ItemStack stack) {
+ entity.getHandle().setEquipment(slot, CraftItemStack.createNMSItemStack(stack));
+ }
+
+ public void clear() {
+ for(int i = 0; i < INVENTORY_SLOTS; i++) {
+ setEquipment(i, null);
+ }
+ }
+
+ public Entity getHolder() {
+ return entity;
+ }
+
+ public float getItemInHandDropChance() {
+ return getDropChance(WEAPON_SLOT);
+ }
+
+ public void setItemInHandDropChance(float chance) {
+ setDropChance(WEAPON_SLOT, chance);
+ }
+
+ public float getHelmetDropChance() {
+ return getDropChance(HELMET_SLOT);
+ }
+
+ public void setHelmetDropChance(float chance) {
+ setDropChance(HELMET_SLOT, chance);
+ }
+
+ public float getChestPlateDropChance() {
+ return getDropChance(CHEST_SLOT);
+ }
+
+ public void setChestPlateDropChance(float chance) {
+ setDropChance(CHEST_SLOT, chance);
+ }
+
+ public float getLeggingsDropChance() {
+ return getDropChance(LEG_SLOT);
+ }
+
+ public void setLeggingsDropChance(float chance) {
+ setDropChance(LEG_SLOT, chance);
+ }
+
+ public float getBootsDropChance() {
+ return getDropChance(BOOT_SLOT);
+ }
+
+ public void setBootsDropChance(float chance) {
+ setDropChance(BOOT_SLOT, chance);
+ }
+
+ private void setDropChance(int slot, float chance) {
+ entity.getHandle().dropChances[slot] = chance - 0.1F;
+ }
+
+ private float getDropChance(int slot) {
+ return entity.getHandle().dropChances[slot] + 0.1F;
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
index 70ea942b..9b7172d3 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
@@ -3,9 +3,10 @@ package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.PlayerInventory;
import org.bukkit.entity.HumanEntity;
+import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
-public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.inventory.PlayerInventory {
+public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.inventory.PlayerInventory, EntityEquipment {
public CraftInventoryPlayer(net.minecraft.server.PlayerInventory inventory) {
super(inventory);
}
@@ -120,4 +121,44 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
public HumanEntity getHolder() {
return (HumanEntity) inventory.getOwner();
}
+
+ public float getItemInHandDropChance() {
+ return 1;
+ }
+
+ public void setItemInHandDropChance(float chance) {
+ throw new UnsupportedOperationException();
+ }
+
+ public float getHelmetDropChance() {
+ return 1;
+ }
+
+ public void setHelmetDropChance(float chance) {
+ throw new UnsupportedOperationException();
+ }
+
+ public float getChestPlateDropChance() {
+ return 1;
+ }
+
+ public void setChestPlateDropChance(float chance) {
+ throw new UnsupportedOperationException();
+ }
+
+ public float getLeggingsDropChance() {
+ return 1;
+ }
+
+ public void setLeggingsDropChance(float chance) {
+ throw new UnsupportedOperationException();
+ }
+
+ public float getBootsDropChance() {
+ return 1;
+ }
+
+ public void setBootsDropChance(float chance) {
+ throw new UnsupportedOperationException();
+ }
}