Merge pull request #38 from ShadowRanger/master

Added 1.9 shield slot support
This commit is contained in:
ShadowRanger 2016-03-09 14:15:40 +11:00
commit 62f5d54676
3 changed files with 18 additions and 17 deletions

View file

@ -4,7 +4,7 @@
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinv</artifactId> <artifactId>openinv</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>2.3.5</version> <version>2.3.6</version>
<name>OpenInv</name> <name>OpenInv</name>
<url>http://dev.bukkit.org/bukkit-plugins/openinv/</url> <url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>

View file

@ -32,7 +32,7 @@ import com.lishid.openinv.OpenInv;
public class SpecialPlayerInventory extends PlayerInventory { public class SpecialPlayerInventory extends PlayerInventory {
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private final ItemStack[] extra = new ItemStack[5]; private final ItemStack[] extra = new ItemStack[4];
private final ItemStack[][] arrays; private final ItemStack[][] arrays;
private final CraftPlayer owner; private final CraftPlayer owner;
private boolean playerOnline; private boolean playerOnline;
@ -41,32 +41,24 @@ public class SpecialPlayerInventory extends PlayerInventory {
super(((CraftPlayer) p).getHandle()); super(((CraftPlayer) p).getHandle());
this.owner = (CraftPlayer) p; this.owner = (CraftPlayer) p;
reflectContents(getClass().getSuperclass(), player.inventory, this); reflectContents(getClass().getSuperclass(), player.inventory, this);
this.arrays = new ItemStack[][] { this.items, this.armor, this.extra }; this.arrays = new ItemStack[][] { this.items, this.armor, this.extraSlots, this.extra };
this.playerOnline = online; this.playerOnline = online;
OpenInv.inventories.put(owner.getUniqueId(), this); OpenInv.inventories.put(owner.getUniqueId(), this);
} }
private void reflectContents(Class clazz, PlayerInventory src, PlayerInventory dest) { private void reflectContents(Class clazz, PlayerInventory src, PlayerInventory dest) {
// Items
try { try {
Field itemsField = clazz.getDeclaredField("items"); Field itemsField = clazz.getDeclaredField("items");
itemsField.setAccessible(true); itemsField.setAccessible(true);
itemsField.set(dest, src.items); itemsField.set(dest, src.items);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
// Armor
try {
Field armorField = clazz.getDeclaredField("armor"); Field armorField = clazz.getDeclaredField("armor");
armorField.setAccessible(true); armorField.setAccessible(true);
armorField.set(dest, src.armor); armorField.set(dest, src.armor);
Field extraSlotsField = clazz.getDeclaredField("extraSlots");
extraSlotsField.setAccessible(true);
extraSlotsField.set(dest, src.extraSlots);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
e.printStackTrace(); e.printStackTrace();
} catch (SecurityException e) { } catch (SecurityException e) {
@ -120,12 +112,13 @@ public class SpecialPlayerInventory extends PlayerInventory {
ItemStack[] contents = new ItemStack[getSize()]; ItemStack[] contents = new ItemStack[getSize()];
System.arraycopy(this.items, 0, contents, 0, this.items.length); System.arraycopy(this.items, 0, contents, 0, this.items.length);
System.arraycopy(this.armor, 0, contents, this.items.length, this.armor.length); System.arraycopy(this.armor, 0, contents, this.items.length, this.armor.length);
System.arraycopy(this.extraSlots, 0, contents, this.items.length + this.armor.length, this.extraSlots.length);
return contents; return contents;
} }
@Override @Override
public int getSize() { public int getSize() {
return super.getSize() - this.extraSlots.length + 5; return super.getSize() + 4;
} }
@Override @Override
@ -149,6 +142,8 @@ public class SpecialPlayerInventory extends PlayerInventory {
i = getReversedItemSlotNum(i); i = getReversedItemSlotNum(i);
} else if (is == this.armor) { } else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} else if (is == this.extraSlots) {
// Do nothing
} else if (is == this.extra) { } else if (is == this.extra) {
// Do nothing // Do nothing
} }
@ -177,6 +172,8 @@ public class SpecialPlayerInventory extends PlayerInventory {
i = getReversedItemSlotNum(i); i = getReversedItemSlotNum(i);
} else if (is == this.armor) { } else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} else if (is == this.extraSlots) {
// Do nothing
} else if (is == this.extra) { } else if (is == this.extra) {
// Do nothing // Do nothing
} }
@ -206,6 +203,8 @@ public class SpecialPlayerInventory extends PlayerInventory {
i = getReversedItemSlotNum(i); i = getReversedItemSlotNum(i);
} else if (is == this.armor) { } else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} else if (is == this.extraSlots) {
// Do nothing
} else if (is == this.extra) { } else if (is == this.extra) {
// Do nothing // Do nothing
} }
@ -240,6 +239,8 @@ public class SpecialPlayerInventory extends PlayerInventory {
i = getReversedItemSlotNum(i); i = getReversedItemSlotNum(i);
} else if (is == this.armor) { } else if (is == this.armor) {
i = getReversedArmorSlotNum(i); i = getReversedArmorSlotNum(i);
} else if (is == this.extraSlots) {
// Do nothing
} else if (is == this.extra) { } else if (is == this.extra) {
owner.getHandle().drop(itemStack, true); owner.getHandle().drop(itemStack, true);
itemStack = null; itemStack = null;

View file

@ -1,6 +1,6 @@
name: OpenInv name: OpenInv
main: com.lishid.openinv.OpenInv main: com.lishid.openinv.OpenInv
version: 2.3.5 version: 2.3.6
author: lishid author: lishid
description: > description: >
This plugin allows you to open a player's inventory as a chest and interact with it in real time. This plugin allows you to open a player's inventory as a chest and interact with it in real time.