diff --git a/README.md b/README.md index 8efe67c..8d08a86 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ I wanted to create an armor stand for each kit in my mini-game that acts out its Compatibility ------------- -- Spigot/CraftBukkit 1.8 - 1.9.x +- Spigot/CraftBukkit 1.8.x, 1.9.x, 1.10 Features -------- diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java index 79a22f9..c0b5048 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java @@ -42,7 +42,7 @@ class ArmorStandGUI implements Listener { im.setDisplayName(" "); filler.setItemMeta(im); invSlots.add(10); - if(Main.oneNine) { + if(!Main.oneEight) { invSlots.add(12); } invSlots.add(2); @@ -68,11 +68,11 @@ class ArmorStandGUI implements Listener { i.setItem(tool.getSlot(), updateLore(tool)); } } - if(Main.oneNine) { + if(Main.oneEight) { + i.setItem(10, as.getItemInHand()); + } else { i.setItem(10, as.getEquipment().getItemInMainHand()); i.setItem(12, as.getEquipment().getItemInOffHand()); - } else { - i.setItem(10, as.getItemInHand()); } i.setItem(2, as.getHelmet()); i.setItem(11, as.getChestplate()); @@ -253,11 +253,11 @@ class ArmorStandGUI implements Listener { @Override public void run() { if(as == null || i == null) return; - if(Main.oneNine) { + if(Main.oneEight) { + as.setItemInHand(i.getItem(10)); + } else { as.getEquipment().setItemInMainHand(i.getItem(10)); as.getEquipment().setItemInOffHand(i.getItem(12)); - } else { - as.setItemInHand(i.getItem(10)); } as.setHelmet(i.getItem(2)); as.setChestplate(i.getItem(11)); diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java index a69db0e..635900f 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java @@ -125,7 +125,7 @@ public enum ArmorStandTool { @SuppressWarnings("deprecation") static ArmorStandTool get(Player p) { - return get(Main.oneNine ? p.getInventory().getItemInMainHand() : p.getItemInHand()); + return get(Main.oneEight ? p.getItemInHand() : p.getInventory().getItemInMainHand()); } static boolean isTool(ItemStack is) { @@ -134,6 +134,6 @@ public enum ArmorStandTool { @SuppressWarnings("deprecation") static boolean isHoldingTool(Player p) { - return isTool(Main.oneNine ? p.getInventory().getItemInMainHand() : p.getItemInHand()); + return isTool(Main.oneEight ? p.getItemInHand() : p.getInventory().getItemInMainHand()); } } \ No newline at end of file diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Main.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Main.java index 43e5346..c9b6b95 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Main.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Main.java @@ -26,13 +26,14 @@ public class Main extends JavaPlugin { public final HashMap savedInventories = new HashMap(); private final EulerAngle zero = new EulerAngle(0D, 0D, 0D); static String NMS_VERSION; - static boolean oneNine, oneNineFour; + static boolean oneEight, oneNineFour, oneTen; @Override public void onEnable() { NMS_VERSION = getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; - oneNine = NMS_VERSION.startsWith("v1_9"); + oneEight = NMS_VERSION.startsWith("v1_8"); oneNineFour = NMS_VERSION.startsWith("v1_9_R2"); + oneTen = NMS_VERSION.startsWith("v1_10"); getServer().getPluginManager().registerEvents(new MainListener(this), this); CommandExecutor ce = new Commands(this); getCommand("astools").setExecutor(ce); @@ -81,8 +82,15 @@ public class Main extends JavaPlugin { int dSlots = NBT.getDisabledSlots(as); String hand, boots, legs, chest, helm, offHand = "0"; int handDmg, offHandDmg = 0; + if(oneEight) { + hand = as.getItemInHand() == null ? "0" : String.valueOf(as.getItemInHand().getTypeId()); + boots = as.getBoots() == null ? "0" : String.valueOf(as.getBoots().getTypeId()); + legs = as.getLeggings() == null ? "0" : String.valueOf(as.getLeggings().getTypeId()); + chest = as.getChestplate() == null ? "0" : String.valueOf(as.getChestplate().getTypeId()); + helm = as.getHelmet() == null ? "0" : String.valueOf(as.getHelmet().getTypeId()); + handDmg = as.getItemInHand() == null ? 0 : as.getItemInHand().getDurability(); - if(oneNine) { + } else { hand = as.getEquipment().getItemInMainHand() == null ? "air" : Utils.getNmsName(as.getEquipment().getItemInMainHand().getType()); offHand = as.getEquipment().getItemInOffHand() == null ? "air" : Utils.getNmsName(as.getEquipment().getItemInOffHand().getType()); boots = as.getBoots() == null ? "air" : Utils.getNmsName(as.getBoots().getType()); @@ -91,13 +99,6 @@ public class Main extends JavaPlugin { helm = as.getHelmet() == null ? "air" : Utils.getNmsName(as.getHelmet().getType()); handDmg = as.getEquipment().getItemInMainHand() == null ? 0 : as.getEquipment().getItemInMainHand().getDurability(); offHandDmg = as.getEquipment().getItemInOffHand() == null ? 0 : as.getEquipment().getItemInOffHand().getDurability(); - } else { - hand = as.getItemInHand() == null ? "0" : String.valueOf(as.getItemInHand().getTypeId()); - boots = as.getBoots() == null ? "0" : String.valueOf(as.getBoots().getTypeId()); - legs = as.getLeggings() == null ? "0" : String.valueOf(as.getLeggings().getTypeId()); - chest = as.getChestplate() == null ? "0" : String.valueOf(as.getChestplate().getTypeId()); - helm = as.getHelmet() == null ? "0" : String.valueOf(as.getHelmet().getTypeId()); - handDmg = as.getItemInHand() == null ? 0 : as.getItemInHand().getDurability(); } int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability(); @@ -111,7 +112,7 @@ public class Main extends JavaPlugin { EulerAngle ra = as.getRightArmPose(); EulerAngle bo = as.getBodyPose(); String cmd; - if(oneNine) { + if(!oneEight) { cmd = "summon ArmorStand " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {" + (as.getMaxHealth() != 20 ? "Attributes:[{Name:\"generic.maxHealth\", Base:" + as.getMaxHealth() + "}]," : "") + (as.isVisible() ? "" : "Invisible:1,") @@ -184,11 +185,11 @@ public class Main extends JavaPlugin { clone.setChestplate(as.getChestplate()); clone.setLeggings(as.getLeggings()); clone.setBoots(as.getBoots()); - if(oneNine) { + if(oneEight) { + clone.setItemInHand(as.getItemInHand()); + } else { clone.getEquipment().setItemInMainHand(as.getEquipment().getItemInMainHand()); clone.getEquipment().setItemInOffHand(as.getEquipment().getItemInOffHand()); - } else { - clone.setItemInHand(as.getItemInHand()); } clone.setHeadPose(as.getHeadPose()); clone.setBodyPose(as.getBodyPose()); diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java index 86846d5..8b922c3 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java @@ -360,11 +360,11 @@ public class MainListener implements Listener { as.setChestplate(Config.chest); as.setLeggings(Config.pants); as.setBoots(Config.boots); - if(Main.oneNine) { + if(Main.oneEight) { + as.setItemInHand(Config.itemInHand); + } else { as.getEquipment().setItemInMainHand(Config.itemInHand); as.getEquipment().setItemInOffHand(Config.itemInOffHand); - } else { - as.setItemInHand(Config.itemInHand); } as.setVisible(Config.isVisible); as.setSmall(Config.isSmall); diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NBT.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NBT.java index 5a564cc..249ee90 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NBT.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NBT.java @@ -21,10 +21,14 @@ class NBT { static int getDisabledSlots(ArmorStand as) { Object nmsEntity = getNmsEntity(as); if(nmsEntity == null) return 0; - if(Main.oneNine) { + if(Main.oneEight) { + Object tag = getTag(nmsEntity); + if (tag == null) return 0; + return getInt(tag, "DisabledSlots"); + } else { Field f; try { - f = nmsEntity.getClass().getDeclaredField(Main.oneNineFour ? "bA" : "bz"); + f = nmsEntity.getClass().getDeclaredField(Main.oneNineFour ? "bA" : (Main.oneTen ? "bB" : "bz")); } catch (NoSuchFieldException e) { e.printStackTrace(); return 0; @@ -36,20 +40,21 @@ class NBT { e.printStackTrace(); return 0; } - } else { - Object tag = getTag(nmsEntity); - if (tag == null) return 0; - return getInt(tag, "DisabledSlots"); } } static void setSlotsDisabled(ArmorStand as, boolean slotsDisabled) { Object nmsEntity = getNmsEntity(as); if (nmsEntity == null) return; - if(Main.oneNine) { + if(Main.oneEight) { + Object tag = getTag(nmsEntity); + if (tag == null) return; + setInt(tag, "DisabledSlots", slotsDisabled ? 2039583 : 0); + saveTagA(nmsEntity, tag); + } else { Field f; try { - f = nmsEntity.getClass().getDeclaredField(Main.oneNineFour ? "bA" : "bz"); + f = nmsEntity.getClass().getDeclaredField(Main.oneNineFour ? "bA" : (Main.oneTen ? "bB" : "bz")); } catch (NoSuchFieldException e) { e.printStackTrace(); return; @@ -60,11 +65,6 @@ class NBT { } catch (IllegalAccessException e) { e.printStackTrace(); } - } else { - Object tag = getTag(nmsEntity); - if (tag == null) return; - setInt(tag, "DisabledSlots", slotsDisabled ? 2039583 : 0); - saveTagA(nmsEntity, tag); } } @@ -75,9 +75,15 @@ class NBT { } static boolean isInvulnerable(ArmorStand as) { + if(Main.oneNineFour || Main.oneTen) { + return as.isInvulnerable(); + } Object nmsEntity = getNmsEntity(as); if (nmsEntity == null) return false; - if(Main.oneNine) { + if(Main.oneEight) { + Object tag = getTag(nmsEntity); + return tag != null && getBoolean(tag, "Invulnerable"); + } else { Field f; try { f = Utils.getNMSClass("Entity").getDeclaredField("invulnerable"); @@ -92,16 +98,21 @@ class NBT { e.printStackTrace(); return false; } - } else { - Object tag = getTag(nmsEntity); - return tag != null && getBoolean(tag, "Invulnerable"); } } static void setInvulnerable(ArmorStand as, boolean invulnerable) { + if(Main.oneNineFour || Main.oneTen) { + as.setInvulnerable(invulnerable); + } Object nmsEntity = getNmsEntity(as); if (nmsEntity == null) return; - if(Main.oneNine) { + if(Main.oneEight) { + Object tag = getTag(nmsEntity); + if(tag == null) return; + setBoolean(tag, "Invulnerable", invulnerable); + saveTagF(nmsEntity, tag); + } else { Field f; try { f = Utils.getNMSClass("Entity").getDeclaredField("invulnerable"); @@ -115,11 +126,6 @@ class NBT { } catch (Exception e) { e.printStackTrace(); } - } else { - Object tag = getTag(nmsEntity); - if(tag == null) return; - setBoolean(tag, "Invulnerable", invulnerable); - saveTagF(nmsEntity, tag); } } diff --git a/src/config.yml b/src/config.yml index a846db7..415f066 100644 --- a/src/config.yml +++ b/src/config.yml @@ -4,7 +4,7 @@ # # Main Config # -# File generated by: v2.1.3 +# File generated by: v2.1.4 # (If this is not the version you are running, consider deleting this # config to allow it to be re-created. There may be new config options) # diff --git a/src/language.yml b/src/language.yml index 028a5ab..e0ca3c7 100644 --- a/src/language.yml +++ b/src/language.yml @@ -4,7 +4,7 @@ # # Language Config # -# File generated by: v2.1.3 +# File generated by: v2.1.4 # (If this is not the version you are running, consider deleting this # config to allow it to be re-created. There may be new config options) # diff --git a/src/plugin.yml b/src/plugin.yml index f30919f..11390de 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ main: com.gmail.St3venAU.plugins.ArmorStandTools.Main name: ArmorStandTools -version: 2.1.3 +version: 2.1.4 author: St3venAU description: Armor stand manipulation tools softdepend: [WorldGuard, PlotSquared]