diff --git a/README.md b/README.md index 8d08a86..fc577c4 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.x, 1.9.x, 1.10 +- Spigot/CraftBukkit 1.8.x, 1.9.x, 1.10.x, 1.11.x, 1.12.x Features -------- @@ -37,7 +37,9 @@ Permissions - astools.reload : Permission to reload the plugin with /astools reload - astools.use : Permission for using any of the tools - astools.clone: Permission to use the clone tool -- astools.cmdblock: Permission to use the save tool (Create a command block) +- astools.head: Permission to use the player head tool (Ability to specify a player head for an armor stand) +- astools.summon: Permission to use the summon tool (Summons an armor stand without requiring the materials) +- astools.cmdblock: Permission to use the save tool (Creates a command block) Config ------ diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java index 424292e..f4a1f61 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java @@ -42,7 +42,9 @@ class ArmorStandGUI implements Listener { im.setDisplayName(" "); filler.setItemMeta(im); invSlots.add(10); - invSlots.add(12); + if(Main.nms.hasOffHand()) { + invSlots.add(12); + } invSlots.add(2); invSlots.add(11); invSlots.add(20); @@ -67,8 +69,10 @@ class ArmorStandGUI implements Listener { } } - i.setItem(10, as.getEquipment().getItemInMainHand()); - i.setItem(12, as.getEquipment().getItemInOffHand()); + i.setItem(10, Main.nms.getItemInMainHand(as)); + if(Main.nms.hasOffHand()) { + i.setItem(12, Main.nms.getItemInOffHand(as)); + } i.setItem(2, as.getHelmet()); i.setItem(11, as.getChestplate()); i.setItem(20, as.getLeggings()); @@ -91,11 +95,9 @@ class ArmorStandGUI implements Listener { case ARMS: return Utils.setLore(item, ChatColor.AQUA + Config.arms + ": " + (as.hasArms() ? (ChatColor.GREEN + Config.isOn) : (ChatColor.RED + Config.isOff))); case INVUL: - return Utils.setLore(item, ChatColor.AQUA + Config.invul + ": " + (as.isInvulnerable() ? (ChatColor.GREEN + Config.isOn) : (ChatColor.RED + Config.isOff))); + return Utils.setLore(item, ChatColor.AQUA + Config.invul + ": " + (Main.nms.isInvulnerable(as) ? (ChatColor.GREEN + Config.isOn) : (ChatColor.RED + Config.isOff))); case SLOTS: - return Utils.setLore(item, ChatColor.AQUA + Config.equip + ": " + (NBT.getDisabledSlots(as) == 2039583 ? (ChatColor.GREEN + Config.locked) : (ChatColor.RED + Config.unLocked))); - case NODEL: - return Utils.setLore(item, ChatColor.AQUA + "Deletion Protection: " + (as.getMaxHealth() == 50 ? (ChatColor.GREEN + Config.enabled) : (ChatColor.RED + Config.disabled))); + return Utils.setLore(item, ChatColor.AQUA + Config.equip + ": " + (Main.nms.getDisabledSlots(as) == 2039583 ? (ChatColor.GREEN + Config.locked) : (ChatColor.RED + Config.unLocked))); case NAME: return Utils.setLore(item, ChatColor.AQUA + Config.currently + ": " + (as.getCustomName() == null ? (ChatColor.BLUE + Config.none) : (ChatColor.GREEN + as.getCustomName()))); case PHEAD: @@ -151,32 +153,32 @@ class ArmorStandGUI implements Listener { switch (t) { case INVIS: as.setVisible(!as.isVisible()); - Utils.actionBarMsg(p, Config.asVisible + ": " + (as.isVisible() ? Config.isTrue : Config.isFalse)); + Main.nms.actionBarMsg(p, Config.asVisible + ": " + (as.isVisible() ? Config.isTrue : Config.isFalse)); break; case CLONE: p.closeInventory(); - plugin.pickUpArmorStand(plugin.clone(as), p, true); - Utils.actionBarMsg(p, Config.carrying); + plugin.pickUpArmorStand(Main.nms.clone(as), p, true); + Main.nms.actionBarMsg(p, Config.carrying); break; case SAVE: - plugin.generateCmdBlock(p.getLocation(), as); - Utils.actionBarMsg(p, Config.cbCreated); + Main.nms.generateCmdBlock(p.getLocation(), as); + Main.nms.actionBarMsg(p, Config.cbCreated); break; case SIZE: as.setSmall(!as.isSmall()); - Utils.actionBarMsg(p, Config.size + ": " + (as.isSmall() ? Config.small : Config.normal)); + Main.nms.actionBarMsg(p, Config.size + ": " + (as.isSmall() ? Config.small : Config.normal)); break; case BASE: as.setBasePlate(!as.hasBasePlate()); - Utils.actionBarMsg(p, Config.basePlate + ": " + (as.hasBasePlate() ? Config.isOn : Config.isOff)); + Main.nms.actionBarMsg(p, Config.basePlate + ": " + (as.hasBasePlate() ? Config.isOn : Config.isOff)); break; case GRAV: as.setGravity(!as.hasGravity()); - Utils.actionBarMsg(p, Config.gravity + ": " + (as.hasGravity() ? Config.isOn : Config.isOff)); + Main.nms.actionBarMsg(p, Config.gravity + ": " + (as.hasGravity() ? Config.isOn : Config.isOff)); break; case ARMS: as.setArms(!as.hasArms()); - Utils.actionBarMsg(p, Config.arms + ": " + (as.hasArms() ? Config.isOn : Config.isOff)); + Main.nms.actionBarMsg(p, Config.arms + ": " + (as.hasArms() ? Config.isOn : Config.isOff)); break; case NAME: p.closeInventory(); @@ -187,29 +189,20 @@ class ArmorStandGUI implements Listener { plugin.setPlayerSkull(p, as); break; case INVUL: - Utils.actionBarMsg(p, Config.invul + ": " + (NBT.toggleInvulnerability(as) ? Config.isOn : Config.isOff)); + Main.nms.actionBarMsg(p, Config.invul + ": " + (Main.nms.toggleInvulnerability(as) ? Config.isOn : Config.isOff)); break; case SLOTS: - Utils.actionBarMsg(p, Config.equip + ": " + (NBT.toggleSlotsDisabled(as) ? Config.locked : Config.unLocked)); + Main.nms.actionBarMsg(p, Config.equip + ": " + (Main.nms.toggleSlotsDisabled(as) ? Config.locked : Config.unLocked)); break; case MOVE: p.closeInventory(); UUID uuid = p.getUniqueId(); if(plugin.carryingArmorStand.containsKey(uuid)) { plugin.carryingArmorStand.remove(uuid); - Utils.actionBarMsg(p, Config.asDropped); + Main.nms.actionBarMsg(p, Config.asDropped); } else { plugin.pickUpArmorStand(as, p, false); - Utils.actionBarMsg(p, Config.carrying); - } - break; - case NODEL: // Developer tool - do not use - if(as.getMaxHealth() == 50) { - as.setMaxHealth(20); - Utils.actionBarMsg(p, "Deletion Protection: Disabled"); - } else { - as.setMaxHealth(50); - Utils.actionBarMsg(p, "Deletion Protection: Enabled"); + Main.nms.actionBarMsg(p, Config.carrying); } break; default: @@ -248,8 +241,10 @@ class ArmorStandGUI implements Listener { @Override public void run() { if(as == null || i == null) return; - as.getEquipment().setItemInMainHand(i.getItem(10)); - as.getEquipment().setItemInOffHand(i.getItem(12)); + Main.nms.setItemInMainHand(as, i.getItem(10)); + if(Main.nms.hasOffHand()) { + Main.nms.setItemInOffHand(as, i.getItem(12)); + } as.setHelmet(i.getItem(2)); as.setChestplate(i.getItem(11)); as.setLeggings(i.getItem(20)); diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java index 5eff262..e110cf5 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java @@ -30,7 +30,7 @@ public enum ArmorStandTool { BODYX ("bodyX", Material.NETHER_BRICK_ITEM, (short) 0, 9, false, true, "astools.use"), BODYY ("bodyY", Material.NETHER_BRICK_ITEM, (short) 0, 10, false, true, "astools.use"), BODYZ ("bodyZ", Material.NETHER_BRICK_ITEM, (short) 0, 11, false, true, "astools.use"), - SUMMON ("summon", Material.ARMOR_STAND, (short) 0, 0, false, true, "astools.use"), + SUMMON ("summon", Material.ARMOR_STAND, (short) 0, 0, false, true, "astools.summon"), GUI ("gui", Material.NETHER_STAR, (short) 0, 1, false, true, "astools.use"), ROTAT ("rotat", Material.MAGMA_CREAM, (short) 0, 2, false, true, "astools.use"), CLONE ("gui_clone", Material.GLOWSTONE_DUST, (short) 0, 15, true, true, "astools.clone"), @@ -42,10 +42,9 @@ public enum ArmorStandTool { ARMS ("gui_arms", Material.ARROW, (short) 0, 23, true, true, "astools.use"), NAME ("gui_name", Material.NAME_TAG, (short) 0, 5, true, true, "astools.use"), SLOTS ("gui_slots", Material.IRON_HOE, (short) 0, 34, true, true, "astools.use"), - PHEAD ("gui_pHead", Material.SKULL_ITEM, (short) 3, 6, true, true, "astools.use"), + PHEAD ("gui_pHead", Material.SKULL_ITEM, (short) 3, 6, true, true, "astools.head"), INVUL ("gui_invul", Material.GOLDEN_CARROT, (short) 0, 33, true, true, "astools.use"), - MOVE ("gui_move", Material.FEATHER, (short) 0, 14, true, true, "astools.use"), - NODEL ("gui_noDel", Material.WOOD_SPADE, (short) 0, 35, true, false, "astools.use"); // Developer tool, disabled by default + MOVE ("gui_move", Material.FEATHER, (short) 0, 14, true, true, "astools.use"); private final ItemStack item; private final String id; @@ -78,7 +77,6 @@ public enum ArmorStandTool { } void setEnabled(FileConfiguration config) { - if(this == NODEL) return; enabled = config.getBoolean("enableTool." + id); } @@ -120,17 +118,15 @@ public enum ArmorStandTool { return null; } - @SuppressWarnings("deprecation") static ArmorStandTool get(Player p) { - return get(p.getInventory().getItemInMainHand()); + return get(Main.nms.getItemInMainHand(p)); } static boolean isTool(ItemStack is) { return get(is) != null; } - @SuppressWarnings("deprecation") static boolean isHoldingTool(Player p) { - return isTool(p.getInventory().getItemInMainHand()); + return isTool(Main.nms.getItemInMainHand(p)); } } \ No newline at end of file diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Commands.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Commands.java index eeef37f..f5ddb57 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Commands.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Commands.java @@ -13,13 +13,13 @@ class Commands implements CommandExecutor { private final Main plugin; Commands(Main main) { - plugin = main; + this.plugin = main; } @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player)) { - System.out.println(Config.notConsole); + plugin.getLogger().warning(Config.notConsole); return false; } Player p = (Player) sender; diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java index 984febf..ff58cbc 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java @@ -9,6 +9,8 @@ import org.bukkit.plugin.Plugin; import java.io.File; import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.logging.Level; class Config { @@ -20,16 +22,16 @@ class Config { public static WorldGuardPlugin worldGuardPlugin; public static ItemStack helmet, chest, pants, boots, itemInHand, itemInOffHand; - public static boolean isVisible = true; - public static boolean isSmall = false; - public static boolean hasArms = true; - public static boolean hasBasePlate = false; - public static boolean hasGravity = false; - public static String defaultName = ""; - public static boolean invulnerable = false; - public static boolean equipmentLock = false; - public static boolean allowMoveWorld = false; - public static boolean deactivateOnWorldChange = true; + public static boolean isVisible = true; + public static boolean isSmall = false; + public static boolean hasArms = true; + public static boolean hasBasePlate = false; + public static boolean hasGravity = false; + public static String defaultName = ""; + public static boolean invulnerable = false; + public static boolean equipmentLock = false; + public static boolean allowMoveWorld = false; + public static boolean deactivateOnWorldChange = true; public static String invReturned, asDropped, asVisible, isTrue, isFalse, @@ -39,7 +41,7 @@ class Config { noRelPerm, noAirError, pleaseWait, appliedHead, invalidName, wgNoPerm, currently, headFailed, noCommandPerm, generalNoPerm, armorStand, none, - enabled, disabled, guiInUse; + guiInUse; public static void reload(Main main) { plugin = main; @@ -86,8 +88,6 @@ class Config { generalNoPerm = languageConfig.getString("generalNoPerm"); armorStand = languageConfig.getString("armorStand"); none = languageConfig.getString("none"); - enabled = languageConfig.getString("enabled"); - disabled = languageConfig.getString("disabled"); guiInUse = languageConfig.getString("guiInUse"); } @@ -136,13 +136,12 @@ class Config { } } - @SuppressWarnings("deprecation") private static void reloadLanguageConfig() { languageConfigFile = new File(plugin.getDataFolder(), "language.yml"); languageConfig = YamlConfiguration.loadConfiguration(languageConfigFile); InputStream defConfigStream = plugin.getResource("language.yml"); if (defConfigStream != null) { - languageConfig.setDefaults(YamlConfiguration.loadConfiguration(defConfigStream)); + languageConfig.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, StandardCharsets.UTF_8))); } } @@ -159,7 +158,7 @@ class Config { } String[] split = s.split(" "); if(split.length > 2) { - System.out.println("[ArmorStandTools] Error in config.yml: Must use the format: MATERIAL_NAME dataValue. Continuing using AIR instead."); + plugin.getLogger().warning("Error in config.yml: Must use the format: MATERIAL_NAME dataValue. Continuing using AIR instead."); return new ItemStack(Material.AIR); } byte dataValue = (byte) 0; @@ -167,14 +166,14 @@ class Config { try { dataValue = Byte.parseByte(split[1]); } catch (NumberFormatException nfe) { - System.out.println("[ArmorStandTools] Error in config.yml: Invalid data value specifed. Continuing using data value 0 instead."); + plugin.getLogger().warning("Error in config.yml: Invalid data value specifed. Continuing using data value 0 instead."); } } Material m; try { m = Material.valueOf(split[0].toUpperCase()); } catch(IllegalArgumentException iae) { - System.out.println("[ArmorStandTools] Error in config.yml: Invalid material name specifed. Continuing using AIR instead."); + plugin.getLogger().warning("Error in config.yml: Invalid material name specifed. Continuing using AIR instead."); return new ItemStack(Material.AIR); } return new ItemStack(m, 1, dataValue); diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Main.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Main.java index 68256b6..a7ac666 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Main.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Main.java @@ -5,10 +5,8 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.CommandBlock; import org.bukkit.command.CommandExecutor; import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; @@ -16,21 +14,25 @@ import org.bukkit.inventory.PlayerInventory; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.EulerAngle; import java.util.HashMap; import java.util.UUID; public class Main extends JavaPlugin { + private static final String LATEST_VERSION = "v1_12_R1"; + + static NMS nms; + public final HashMap carryingArmorStand = new HashMap(); public final HashMap savedInventories = new HashMap(); - private final EulerAngle zero = new EulerAngle(0D, 0D, 0D); - static String NMS_VERSION; @Override public void onEnable() { - NMS_VERSION = getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; + if(!loadSpigotVersionSupport()) { + setEnabled(false); + return; + } getServer().getPluginManager().registerEvents(new MainListener(this), this); CommandExecutor ce = new Commands(this); getCommand("astools").setExecutor(ce); @@ -53,6 +55,35 @@ public class Main extends JavaPlugin { savedInventories.clear(); } + private boolean loadSpigotVersionSupport() { + String nmsVersion = getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; + String usingVersion; + if(nmsVersion.startsWith("v1_7") || nmsVersion.startsWith("v1_6") || nmsVersion.startsWith("v1_5") || nmsVersion.startsWith("v1_4")) { + getLogger().warning("This Craftbukkit/Spigot version is not supported. Craftbukkit/Spigot 1.8+ required. Loading plugin failed."); + return false; + } + try { + if(NMS.class.isAssignableFrom(Class.forName("com.gmail.St3venAU.plugins.ArmorStandTools.NMS_" + nmsVersion))) { + usingVersion = nmsVersion; + getLogger().info("Loading support for " + usingVersion); + } else { + usingVersion = LATEST_VERSION; + getLogger().warning("Support for " + nmsVersion + " not found, trying " + usingVersion + ". Please check for possible updates to the plugin."); + } + } catch (Exception e) { + usingVersion = LATEST_VERSION; + getLogger().warning("Support for " + nmsVersion + " not found, trying " + usingVersion + ". Please check for possible updates to the plugin."); + } + try { + nms = (NMS) Class.forName("com.gmail.St3venAU.plugins.ArmorStandTools.NMS_" + usingVersion).getConstructor().newInstance(); + } catch (Exception e) { + e.printStackTrace(); + getLogger().warning("A fatal error occurred while attempting to load support for this version of Craftbukkit/Spigot"); + return false; + } + return true; + } + void returnArmorStand(ArmorStand as) { if(as.hasMetadata("startLoc")) { for (MetadataValue value : as.getMetadata("startLoc")) { @@ -104,127 +135,30 @@ public class Main extends JavaPlugin { as.setMetadata("startLoc", new FixedMetadataValue(this, as.getLocation())); } - private String getSummonEntityName() { - if(NMS_VERSION.startsWith("v1_9_R2") || NMS_VERSION.startsWith("v1_10")) { - return "ArmorStand"; - } else { - return "minecraft:armor_stand"; - } - } - - @SuppressWarnings({"deprecation", "ConstantConditions"}) - void generateCmdBlock(Location l, ArmorStand as) { - Location loc = as.getLocation(); - int dSlots = NBT.getDisabledSlots(as); - String hand, boots, legs, chest, helm, offHand; - int handDmg, offHandDmg; - 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()); - legs = as.getLeggings() == null ? "air" : Utils.getNmsName(as.getLeggings().getType()); - chest = as.getChestplate() == null ? "air" : Utils.getNmsName(as.getChestplate().getType()); - 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(); - - int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability(); - int legsDmg = as.getLeggings() == null ? 0 : as.getLeggings().getDurability(); - int chestDmg = as.getChestplate() == null ? 0 : as.getChestplate().getDurability(); - int helmDmg = as.getHelmet() == null ? 0 : as.getHelmet().getDurability(); - EulerAngle he = as.getHeadPose(); - EulerAngle ll = as.getLeftLegPose(); - EulerAngle rl = as.getRightLegPose(); - EulerAngle la = as.getLeftArmPose(); - EulerAngle ra = as.getRightArmPose(); - EulerAngle bo = as.getBodyPose(); - String cmd = "summon " + getSummonEntityName() + " " + 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,") - + (as.hasBasePlate() ? "" : "NoBasePlate:1,") - + (as.hasGravity() ? "" : "NoGravity:1,") - + (as.hasArms() ? "ShowArms:1," : "") - + (as.isSmall() ? "Small:1," : "") - + (as.isInvulnerable() ? "Invulnerable:1," : "") - + (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ",")) - + (as.isCustomNameVisible() ? "CustomNameVisible:1," : "") - + (as.getCustomName() == null ? "" : ("CustomName:\"" + as.getCustomName() + "\",")) - + (loc.getYaw() == 0F ? "" : ("Rotation:[" + Utils.twoDec(loc.getYaw()) + "f],")) - + (as.getBoots() == null && as.getLeggings() == null && as.getChestplate() == null && as.getHelmet() == null ? "" : ( - "ArmorItems:[" - + "{id:" + boots + ",Count:" + as.getBoots().getAmount() + ",Damage:" + bootsDmg + NBT.getItemStackTags(as.getBoots()) + "}," - + "{id:" + legs + ",Count:" + as.getLeggings().getAmount() + ",Damage:" + legsDmg + NBT.getItemStackTags(as.getLeggings()) + "}," - + "{id:" + chest + ",Count:" + as.getChestplate().getAmount() + ",Damage:" + chestDmg + NBT.getItemStackTags(as.getChestplate()) + "}," - + "{id:" + helm + ",Count:" + as.getHelmet().getAmount() + ",Damage:" + helmDmg + NBT.getItemStackTags(as.getHelmet()) + NBT.skullOwner(as.getHelmet()) + "}],")) - + (as.getEquipment().getItemInMainHand() == null && as.getEquipment().getItemInOffHand() == null ? "" : ( - "HandItems:[" - + "{id:" + hand + ",Count:" + as.getEquipment().getItemInMainHand().getAmount() + ",Damage:" + handDmg + NBT.getItemStackTags(as.getEquipment().getItemInMainHand()) + "}," - + "{id:" + offHand + ",Count:" + as.getEquipment().getItemInOffHand().getAmount() + ",Damage:" + offHandDmg + NBT.getItemStackTags(as.getEquipment().getItemInOffHand()) + "}],")) - + "Pose:{" - + (bo.equals(zero) ? "" : ("Body:[" + Utils.angle(bo.getX()) + "f," + Utils.angle(bo.getY()) + "f," + Utils.angle(bo.getZ()) + "f],")) - + (he.equals(zero) ? "" : ("Head:[" + Utils.angle(he.getX()) + "f," + Utils.angle(he.getY()) + "f," + Utils.angle(he.getZ()) + "f],")) - + (ll.equals(zero) ? "" : ("LeftLeg:[" + Utils.angle(ll.getX()) + "f," + Utils.angle(ll.getY()) + "f," + Utils.angle(ll.getZ()) + "f],")) - + (rl.equals(zero) ? "" : ("RightLeg:[" + Utils.angle(rl.getX()) + "f," + Utils.angle(rl.getY()) + "f," + Utils.angle(rl.getZ()) + "f],")) - + (la.equals(zero) ? "" : ("LeftArm:[" + Utils.angle(la.getX()) + "f," + Utils.angle(la.getY()) + "f," + Utils.angle(la.getZ()) + "f],")) - + "RightArm:[" + Utils.angle(ra.getX()) + "f," + Utils.angle(ra.getY()) + "f," + Utils.angle(ra.getZ()) + "f]}}"; - Block b = l.getBlock(); - b.setType(Material.COMMAND); - b.setData((byte) 0); - CommandBlock cb = (CommandBlock) b.getState(); - cb.setCommand(cmd); - cb.update(); - } - - ArmorStand clone(ArmorStand as) { - ArmorStand clone = (ArmorStand) as.getWorld().spawnEntity(as.getLocation().add(1, 0, 0), EntityType.ARMOR_STAND); - clone.setGravity(as.hasGravity()); - clone.setHelmet(as.getHelmet()); - clone.setChestplate(as.getChestplate()); - clone.setLeggings(as.getLeggings()); - clone.setBoots(as.getBoots()); - clone.getEquipment().setItemInMainHand(as.getEquipment().getItemInMainHand()); - clone.getEquipment().setItemInOffHand(as.getEquipment().getItemInOffHand()); - clone.setHeadPose(as.getHeadPose()); - clone.setBodyPose(as.getBodyPose()); - clone.setLeftArmPose(as.getLeftArmPose()); - clone.setRightArmPose(as.getRightArmPose()); - clone.setLeftLegPose(as.getLeftLegPose()); - clone.setRightLegPose(as.getRightLegPose()); - clone.setVisible(as.isVisible()); - clone.setBasePlate(as.hasBasePlate()); - clone.setArms(as.hasArms()); - clone.setCustomName(as.getCustomName()); - clone.setCustomNameVisible(as.isCustomNameVisible()); - clone.setSmall(as.isSmall()); - clone.setMaxHealth(as.getMaxHealth()); - NBT.setSlotsDisabled(clone, NBT.getDisabledSlots(as) == 2039583); - clone.setInvulnerable(as.isInvulnerable()); - return clone; - } - - @SuppressWarnings("deprecation") void setName(Player p, ArmorStand as) { Block b = Utils.findAnAirBlock(p.getLocation()); if(b == null) { p.sendMessage(ChatColor.RED + Config.noAirError); return; } + //noinspection deprecation b.setData((byte) 0); b.setType(Material.SIGN_POST); - Utils.openSign(p, b); + nms.openSign(p, b); b.setMetadata("armorStand", new FixedMetadataValue(this, as.getUniqueId())); b.setMetadata("setName", new FixedMetadataValue(this, true)); } - @SuppressWarnings("deprecation") void setPlayerSkull(Player p, ArmorStand as) { Block b = Utils.findAnAirBlock(p.getLocation()); if(b == null) { p.sendMessage(ChatColor.RED + Config.noAirError); return; } + //noinspection deprecation b.setData((byte) 0); b.setType(Material.SIGN_POST); - Utils.openSign(p, b); + nms.openSign(p, b); b.setMetadata("armorStand", new FixedMetadataValue(this, as.getUniqueId())); b.setMetadata("setSkull", new FixedMetadataValue(this, true)); } @@ -246,6 +180,6 @@ public class Main extends JavaPlugin { } boolean playerHasPermission(Player p, Block b, ArmorStandTool tool) { - return (tool == null || tool.isEnabled() && Utils.hasPermissionNode(p, tool.getPermission())) && checkBlockPermission(p, b); + return (tool == null || (tool.isEnabled() && Utils.hasPermissionNode(p, tool.getPermission()))) && checkBlockPermission(p, b); } } \ No newline at end of file diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java index 0b69929..19de778 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java @@ -51,7 +51,6 @@ public class MainListener implements Listener { this.plugin = main; } - @SuppressWarnings("ConstantConditions") @EventHandler public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { if (event.getRightClicked() instanceof ArmorStand) { @@ -59,7 +58,7 @@ public class MainListener implements Listener { if(plugin.carryingArmorStand.containsKey(p.getUniqueId())) { if (plugin.playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) { plugin.carryingArmorStand.remove(p.getUniqueId()); - Utils.actionBarMsg(p, Config.asDropped); + Main.nms.actionBarMsg(p, Config.asDropped); event.setCancelled(true); return; } else { @@ -163,16 +162,15 @@ public class MainListener implements Listener { } } - @SuppressWarnings("deprecation") @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if (event.getRightClicked() instanceof ItemFrame && ArmorStandTool.isHoldingTool(event.getPlayer())) { event.setCancelled(true); + //noinspection deprecation event.getPlayer().updateInventory(); } } - @SuppressWarnings("deprecation") @EventHandler public void onBlockPlace(BlockPlaceEvent event) { if (ArmorStandTool.isHoldingTool(event.getPlayer())) { @@ -180,7 +178,6 @@ public class MainListener implements Listener { } } - @SuppressWarnings("deprecation") @EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player p = event.getPlayer(); @@ -188,11 +185,11 @@ public class MainListener implements Listener { ArmorStand as = plugin.carryingArmorStand.get(p.getUniqueId()); if (as == null || as.isDead()) { plugin.carryingArmorStand.remove(p.getUniqueId()); - Utils.actionBarMsg(p, Config.asDropped); + Main.nms.actionBarMsg(p, Config.asDropped); return; } as.teleport(Utils.getLocationFacing(event.getTo())); - Utils.actionBarMsg(p, Config.carrying); + Main.nms.actionBarMsg(p, Config.carrying); } } @@ -205,7 +202,7 @@ public class MainListener implements Listener { final ArmorStand as = plugin.carryingArmorStand.get(uuid); if (as == null || as.isDead()) { plugin.carryingArmorStand.remove(p.getUniqueId()); - Utils.actionBarMsg(p, Config.asDropped); + Main.nms.actionBarMsg(p, Config.asDropped); return; } if(sameWorld || Config.allowMoveWorld) { @@ -213,7 +210,7 @@ public class MainListener implements Listener { @Override public void run() { as.teleport(Utils.getLocationFacing(p.getLocation())); - Utils.actionBarMsg(p, Config.carrying); + Main.nms.actionBarMsg(p, Config.carrying); } }.runTaskLater(plugin, 1L); } else { @@ -242,7 +239,6 @@ public class MainListener implements Listener { } } - @SuppressWarnings("deprecation") @EventHandler public void onCraftItem(CraftItemEvent event) { if (event.isCancelled()) return; @@ -251,13 +247,13 @@ public class MainListener implements Listener { for(ItemStack is : inventory.getContents()) { if(ArmorStandTool.isTool(is)) { event.setCancelled(true); + //noinspection deprecation p.updateInventory(); return; } } } - @SuppressWarnings("deprecation") @EventHandler public void onInventoryClick(InventoryClickEvent event) { if (event.isCancelled() || !(event.getWhoClicked() instanceof Player)) return; @@ -265,24 +261,26 @@ public class MainListener implements Listener { ItemStack item = event.getCurrentItem(); if(event.getInventory().getHolder() != p && ArmorStandTool.isTool(item)) { event.setCancelled(true); + //noinspection deprecation p.updateInventory(); return; } if(event.getAction() == InventoryAction.HOTBAR_SWAP || event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD) { if(Utils.hasItems(p)) { event.setCancelled(true); + //noinspection deprecation p.updateInventory(); } } } - @SuppressWarnings("deprecation") @EventHandler public void onInventoryDrag(InventoryDragEvent event) { if (event.isCancelled() || !(event.getWhoClicked() instanceof Player)) return; final Player p = (Player) event.getWhoClicked(); if (event.getInventory().getHolder() != p && Utils.containsItems(event.getNewItems().values())) { event.setCancelled(true); + //noinspection deprecation p.updateInventory(); } } @@ -306,14 +304,13 @@ public class MainListener implements Listener { } } - @SuppressWarnings("deprecation") @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { final Player p = event.getPlayer(); if(plugin.carryingArmorStand.containsKey(p.getUniqueId())) { if (plugin.playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) { plugin.carryingArmorStand.remove(p.getUniqueId()); - Utils.actionBarMsg(p, Config.asDropped); + Main.nms.actionBarMsg(p, Config.asDropped); p.setMetadata("lastDrop", new FixedMetadataValue(plugin, System.currentTimeMillis())); event.setCancelled(true); } else { @@ -334,11 +331,12 @@ public class MainListener implements Listener { } Location l = Utils.getLocationFacing(p.getLocation()); plugin.pickUpArmorStand(spawnArmorStand(l), p, true); - Utils.actionBarMsg(p, Config.carrying); + Main.nms.actionBarMsg(p, Config.carrying); } new BukkitRunnable() { @Override public void run() { + //noinspection deprecation p.updateInventory(); } }.runTaskLater(plugin, 1L); @@ -347,7 +345,7 @@ public class MainListener implements Listener { @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if(event.getEntity() instanceof ArmorStand) { - if(event.getEntity().isInvulnerable()) { + if(Main.nms.isInvulnerable((ArmorStand) event.getEntity())) { event.setCancelled(true); } if(event.getDamager() instanceof Player && ArmorStandTool.isHoldingTool((Player) event.getDamager())) { @@ -374,8 +372,10 @@ public class MainListener implements Listener { as.setChestplate(Config.chest); as.setLeggings(Config.pants); as.setBoots(Config.boots); - as.getEquipment().setItemInMainHand(Config.itemInHand); - as.getEquipment().setItemInOffHand(Config.itemInOffHand); + Main.nms.setItemInMainHand(as, Config.itemInHand); + if(Main.nms.hasOffHand()) { + Main.nms.setItemInOffHand(as, Config.itemInOffHand); + } as.setVisible(Config.isVisible); as.setSmall(Config.isSmall); as.setArms(Config.hasArms); @@ -385,8 +385,8 @@ public class MainListener implements Listener { as.setCustomName(Config.defaultName); as.setCustomNameVisible(true); } - NBT.setSlotsDisabled(as, Config.equipmentLock); - as.setInvulnerable(Config.invulnerable); + Main.nms.setSlotsDisabled(as, Config.equipmentLock); + Main.nms.setInvulnerable(as, Config.invulnerable); return as; } @@ -398,7 +398,6 @@ public class MainListener implements Listener { } } - @SuppressWarnings("deprecation") @EventHandler public void onSignChange(final SignChangeEvent event) { if(event.getBlock().hasMetadata("armorStand")) { @@ -454,6 +453,7 @@ public class MainListener implements Listener { b.removeMetadata("setName", plugin); b.removeMetadata("setSkull", plugin); b.setType(Material.AIR); + //noinspection deprecation b.setData((byte) 0); } } diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NBT.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NBT.java deleted file mode 100644 index d375ff7..0000000 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NBT.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.gmail.St3venAU.plugins.ArmorStandTools; - -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.ArmorStand; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.bukkit.inventory.meta.SkullMeta; - -import java.lang.reflect.Field; -import java.util.Map; - -class NBT { - - private static String disabledSlotsFieldName; - private static String getDisabledSlotsFieldName() { - if(disabledSlotsFieldName != null) return disabledSlotsFieldName; - if(Main.NMS_VERSION.startsWith("v1_9_R2")) { - disabledSlotsFieldName = "bA"; - } else if(Main.NMS_VERSION.startsWith("v1_10")) { - disabledSlotsFieldName = "bB"; - } else if(Main.NMS_VERSION.startsWith("v1_11")) { - disabledSlotsFieldName = "bA"; - } else { - disabledSlotsFieldName = "bA"; // If ver greater than 1.11 then assume the same as 1.11 and hope that it didn't change :) - } - return disabledSlotsFieldName; - } - - static boolean toggleSlotsDisabled(ArmorStand as) { - boolean slotsDisabled = getDisabledSlots(as) == 0; - setSlotsDisabled(as, slotsDisabled); - return slotsDisabled; - } - - static int getDisabledSlots(ArmorStand as) { - Object nmsEntity = getNmsEntity(as); - if(nmsEntity == null) return 0; - Field f; - try { - f = nmsEntity.getClass().getDeclaredField(getDisabledSlotsFieldName()); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - return 0; - } - f.setAccessible(true); - try { - return (Integer) f.get(nmsEntity); - } catch (IllegalAccessException e) { - e.printStackTrace(); - return 0; - } - } - - static void setSlotsDisabled(ArmorStand as, boolean slotsDisabled) { - Object nmsEntity = getNmsEntity(as); - if (nmsEntity == null) return; - Field f; - try { - f = nmsEntity.getClass().getDeclaredField(getDisabledSlotsFieldName()); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - return; - } - f.setAccessible(true); - try { - f.set(nmsEntity, slotsDisabled ? 2039583 : 0); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - static boolean toggleInvulnerability(ArmorStand as) { - boolean isInvulnerable = !as.isInvulnerable(); - as.setInvulnerable(isInvulnerable); - return isInvulnerable; - } - - private static Object getNmsEntity(org.bukkit.entity.Entity entity) { - try { - return entity.getClass().getMethod("getHandle").invoke(entity); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - @SuppressWarnings("deprecation") - static String getItemStackTags(ItemStack is) { - if(is == null) { - return ""; - } - StringBuilder tags = new StringBuilder(""); - if(is.getItemMeta() != null && is.getItemMeta() instanceof LeatherArmorMeta) { - LeatherArmorMeta armorMeta = (LeatherArmorMeta) is.getItemMeta(); - tags.append("display:{color:"); - tags.append(armorMeta.getColor().asRGB()); - tags.append("}"); - } - Map enchants = is.getEnchantments(); - if(enchants.size() > 0) { - if(tags.length() > 0) { - tags.append(","); - } - tags.append("ench:["); - - for(Enchantment e : enchants.keySet()) { - tags.append("{id:"); - tags.append(e.getId()); - tags.append(",lvl:"); - tags.append(enchants.get(e)); - tags.append("},"); - } - - tags.setCharAt(tags.length() - 1, ']'); - } - return tags.length() == 0 ? "" : (",tag:{" + tags.toString() + "}"); - } - - static String skullOwner(ItemStack is) { - if(is == null || is.getItemMeta() == null || !(is.getItemMeta() instanceof SkullMeta)) { - return ""; - } - SkullMeta skull = (SkullMeta) is.getItemMeta(); - if(skull.hasOwner()) { - return ",tag:{SkullOwner:\"" + skull.getOwner() + "\"}"; - } else { - return ""; - } - } -} diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS.java new file mode 100644 index 0000000..191218f --- /dev/null +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS.java @@ -0,0 +1,464 @@ +package com.gmail.St3venAU.plugins.ArmorStandTools; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.CommandBlock; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.util.EulerAngle; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Map; +import java.util.Set; + +abstract class NMS { + + private final static EulerAngle zero = new EulerAngle(0D, 0D, 0D); + + private final boolean offHand; + + private final String + nmsVersion, + summonEntityName, + disabledSlotsFieldName, + keyFieldName, + chatSerializerFieldName; + + NMS(String nmsVersion, String summonEntityName, String disabledSlotsFieldName, String keyFieldName, String chatSerializerFieldName, boolean offHand) { + this.nmsVersion = nmsVersion; + this.summonEntityName = summonEntityName; + this.disabledSlotsFieldName = disabledSlotsFieldName; + this.keyFieldName = keyFieldName; + this.chatSerializerFieldName = chatSerializerFieldName; + this.offHand = offHand; + } + + public boolean hasOffHand() { + return offHand; + } + + boolean isInvulnerable(ArmorStand as) { + return as.isInvulnerable(); + } + + void setInvulnerable(ArmorStand as, boolean invulnerable) { + as.setInvulnerable(invulnerable); + } + + boolean toggleInvulnerability(ArmorStand as) { + boolean isInvulnerable = !isInvulnerable(as); + setInvulnerable(as, isInvulnerable); + return isInvulnerable; + } + + boolean toggleSlotsDisabled(ArmorStand as) { + boolean slotsDisabled = getDisabledSlots(as) == 0; + setSlotsDisabled(as, slotsDisabled); + return slotsDisabled; + } + + int getDisabledSlots(ArmorStand as) { + Object nmsEntity = getNmsEntity(as); + if(nmsEntity == null) return 0; + Field f; + try { + f = nmsEntity.getClass().getDeclaredField(disabledSlotsFieldName); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return 0; + } + f.setAccessible(true); + try { + return (Integer) f.get(nmsEntity); + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 0; + } + } + + void setSlotsDisabled(ArmorStand as, boolean slotsDisabled) { + Object nmsEntity = getNmsEntity(as); + if (nmsEntity == null) return; + Field f; + try { + f = nmsEntity.getClass().getDeclaredField(disabledSlotsFieldName); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + return; + } + f.setAccessible(true); + try { + f.set(nmsEntity, slotsDisabled ? 2039583 : 0); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + Object getNmsEntity(org.bukkit.entity.Entity entity) { + try { + return entity.getClass().getMethod("getHandle").invoke(entity); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + private String getItemStackTags(ItemStack is) { + if(is == null) { + return ""; + } + StringBuilder tags = new StringBuilder(""); + if(is.getItemMeta() != null && is.getItemMeta() instanceof LeatherArmorMeta) { + LeatherArmorMeta armorMeta = (LeatherArmorMeta) is.getItemMeta(); + tags.append("display:{color:"); + tags.append(armorMeta.getColor().asRGB()); + tags.append("}"); + } + Map enchants = is.getEnchantments(); + if(enchants.size() > 0) { + if(tags.length() > 0) { + tags.append(","); + } + tags.append("ench:["); + + for(Enchantment e : enchants.keySet()) { + tags.append("{id:"); + //noinspection deprecation + tags.append(e.getId()); + tags.append(",lvl:"); + tags.append(enchants.get(e)); + tags.append("},"); + } + + tags.setCharAt(tags.length() - 1, ']'); + } + return tags.length() == 0 ? "" : (",tag:{" + tags.toString() + "}"); + } + + private String skullOwner(ItemStack is) { + if(is == null || is.getItemMeta() == null || !(is.getItemMeta() instanceof SkullMeta)) { + return ""; + } + SkullMeta skull = (SkullMeta) is.getItemMeta(); + if(skull.hasOwner()) { + return ",tag:{SkullOwner:\"" + skull.getOwner() + "\"}"; + } else { + return ""; + } + } + + @SuppressWarnings("unchecked") + private String getNmsName(Material m) { + try { + Class block = getNMSClass("Block"); + Class item = getNMSClass("Item"); + Class registryBlocks = getNMSClass("RegistryBlocks"); + Class registryMaterials = getNMSClass("RegistryMaterials"); + Class regKey = getNMSClass("MinecraftKey"); + Object registry = block.getDeclaredField("REGISTRY").get(null); + Set set = (Set) registry.getClass().getMethod("keySet").invoke(registry); + for(Object key : set) { + Object b = registryBlocks.getMethod("get", Object.class).invoke(registry, key); + Integer id = (Integer) block.getMethod("getId", block).invoke(null, b); + //noinspection deprecation + if(id == m.getId()) { + return (String) regKey.getMethod(keyFieldName).invoke(key); + } + } + registry = item.getDeclaredField("REGISTRY").get(null); + set = (Set) registry.getClass().getMethod("keySet").invoke(registry); + for(Object key : set) { + Object i = registryMaterials.getMethod("get", Object.class).invoke(registry, key); + Integer id = (Integer) item.getMethod("getId", item).invoke(null, i); + //noinspection deprecation + if(id == m.getId()) { + return (String) regKey.getMethod(keyFieldName).invoke(key); + } + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } + return null; + } + + void openSign(Player p, Block b) { + try { + Object world = b.getWorld().getClass().getMethod("getHandle").invoke(b.getWorld()); + Object blockPos = getNMSClass("BlockPosition").getConstructor(int.class, int.class, int.class).newInstance(b.getX(), b.getY(), b.getZ()); + Object sign = world.getClass().getMethod("getTileEntity", getNMSClass("BlockPosition")).invoke(world, blockPos); + Object player = p.getClass().getMethod("getHandle").invoke(p); + player.getClass().getMethod("openSign", getNMSClass("TileEntitySign")).invoke(player, sign); + } catch (Exception e) { + e.printStackTrace(); + } + } + + Class getNMSClass(String nmsClassString) throws ClassNotFoundException { + if(nmsClassString.equals("ChatSerializer")) { + nmsClassString = chatSerializerFieldName; + } + return Class.forName("net.minecraft.server." + nmsVersion + "." + nmsClassString); + } + + void sendPacket(Player p, Object packet) { + try { + Object player = p.getClass().getMethod("getHandle").invoke(p); + Object connection = player.getClass().getField("playerConnection").get(player); + connection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(connection, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + + void actionBarMsg(Player p, String msg) { + try { + Object chat = getNMSClass("ChatSerializer").getMethod("a", String.class).invoke(null, "{\"text\":\"" + msg + "\",\"color\":\"green\"}"); + Object packet = getNMSClass("PacketPlayOutChat").getConstructor(getNMSClass("IChatBaseComponent"), byte.class).newInstance(chat, (byte) 2); + sendPacket(p, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + + void generateCmdBlock(Location l, ArmorStand as) { + if(offHand) { + generateCmdBlockWithOffHand(l, as); + } else { + generateCmdBlockWithoutOffHand(l, as); + } + } + + private void generateCmdBlockWithOffHand(Location l, ArmorStand as) { + Location loc = as.getLocation(); + int dSlots = getDisabledSlots(as); + String hand, boots, legs, chest, helm, offHand; + int handDmg, offHandDmg; + hand = as.getEquipment().getItemInMainHand() == null ? "air" : getNmsName(as.getEquipment().getItemInMainHand().getType()); + offHand = as.getEquipment().getItemInOffHand() == null ? "air" : getNmsName(as.getEquipment().getItemInOffHand().getType()); + boots = as.getBoots() == null ? "air" : getNmsName(as.getBoots().getType()); + legs = as.getLeggings() == null ? "air" : getNmsName(as.getLeggings().getType()); + chest = as.getChestplate() == null ? "air" : getNmsName(as.getChestplate().getType()); + helm = as.getHelmet() == null ? "air" : getNmsName(as.getHelmet().getType()); + handDmg = as.getEquipment().getItemInMainHand() == null ? 0 : as.getEquipment().getItemInMainHand().getDurability(); + offHandDmg = as.getEquipment().getItemInOffHand() == null ? 0 : as.getEquipment().getItemInOffHand().getDurability(); + + int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability(); + int legsDmg = as.getLeggings() == null ? 0 : as.getLeggings().getDurability(); + int chestDmg = as.getChestplate() == null ? 0 : as.getChestplate().getDurability(); + int helmDmg = as.getHelmet() == null ? 0 : as.getHelmet().getDurability(); + EulerAngle he = as.getHeadPose(); + EulerAngle ll = as.getLeftLegPose(); + EulerAngle rl = as.getRightLegPose(); + EulerAngle la = as.getLeftArmPose(); + EulerAngle ra = as.getRightArmPose(); + EulerAngle bo = as.getBodyPose(); + String cmd = "summon " + summonEntityName + " " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {" + + (as.isVisible() ? "" : "Invisible:1,") + + (as.hasBasePlate() ? "" : "NoBasePlate:1,") + + (as.hasGravity() ? "" : "NoGravity:1,") + + (as.hasArms() ? "ShowArms:1," : "") + + (as.isSmall() ? "Small:1," : "") + + (isInvulnerable(as) ? "Invulnerable:1," : "") + + (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ",")) + + (as.isCustomNameVisible() ? "CustomNameVisible:1," : "") + + (as.getCustomName() == null ? "" : ("CustomName:\"" + as.getCustomName() + "\",")) + + (loc.getYaw() == 0F ? "" : ("Rotation:[" + Utils.twoDec(loc.getYaw()) + "f],")) + + (as.getBoots() == null && as.getLeggings() == null && as.getChestplate() == null && as.getHelmet() == null ? "" : ( + "ArmorItems:[" + + "{id:" + boots + ",Count:" + as.getBoots().getAmount() + ",Damage:" + bootsDmg + getItemStackTags(as.getBoots()) + "}," + + "{id:" + legs + ",Count:" + as.getLeggings().getAmount() + ",Damage:" + legsDmg + getItemStackTags(as.getLeggings()) + "}," + + "{id:" + chest + ",Count:" + as.getChestplate().getAmount() + ",Damage:" + chestDmg + getItemStackTags(as.getChestplate()) + "}," + + "{id:" + helm + ",Count:" + as.getHelmet().getAmount() + ",Damage:" + helmDmg + getItemStackTags(as.getHelmet()) + skullOwner(as.getHelmet()) + "}],")) + + (as.getEquipment().getItemInMainHand() == null && as.getEquipment().getItemInOffHand() == null ? "" : ( + "HandItems:[" + + "{id:" + hand + ",Count:" + as.getEquipment().getItemInMainHand().getAmount() + ",Damage:" + handDmg + getItemStackTags(as.getEquipment().getItemInMainHand()) + "}," + + "{id:" + offHand + ",Count:" + as.getEquipment().getItemInOffHand().getAmount() + ",Damage:" + offHandDmg + getItemStackTags(as.getEquipment().getItemInOffHand()) + "}],")) + + "Pose:{" + + (bo.equals(zero) ? "" : ("Body:[" + Utils.angle(bo.getX()) + "f," + Utils.angle(bo.getY()) + "f," + Utils.angle(bo.getZ()) + "f],")) + + (he.equals(zero) ? "" : ("Head:[" + Utils.angle(he.getX()) + "f," + Utils.angle(he.getY()) + "f," + Utils.angle(he.getZ()) + "f],")) + + (ll.equals(zero) ? "" : ("LeftLeg:[" + Utils.angle(ll.getX()) + "f," + Utils.angle(ll.getY()) + "f," + Utils.angle(ll.getZ()) + "f],")) + + (rl.equals(zero) ? "" : ("RightLeg:[" + Utils.angle(rl.getX()) + "f," + Utils.angle(rl.getY()) + "f," + Utils.angle(rl.getZ()) + "f],")) + + (la.equals(zero) ? "" : ("LeftArm:[" + Utils.angle(la.getX()) + "f," + Utils.angle(la.getY()) + "f," + Utils.angle(la.getZ()) + "f],")) + + "RightArm:[" + Utils.angle(ra.getX()) + "f," + Utils.angle(ra.getY()) + "f," + Utils.angle(ra.getZ()) + "f]}}"; + Block b = l.getBlock(); + b.setType(Material.COMMAND); + //noinspection deprecation + b.setData((byte) 0); + CommandBlock cb = (CommandBlock) b.getState(); + cb.setCommand(cmd); + cb.update(); + } + + @SuppressWarnings("deprecation") + private void generateCmdBlockWithoutOffHand(Location l, ArmorStand as) { + Location loc = as.getLocation(); + int dSlots = Main.nms.getDisabledSlots(as); + String hand, boots, legs, chest, helm; + int handDmg; + + hand = getItemInMainHand(as) == null ? "0" : String.valueOf(getItemInMainHand(as).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 = getItemInMainHand(as) == null ? 0 : getItemInMainHand(as).getDurability(); + + int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability(); + int legsDmg = as.getLeggings() == null ? 0 : as.getLeggings().getDurability(); + int chestDmg = as.getChestplate() == null ? 0 : as.getChestplate().getDurability(); + int helmDmg = as.getHelmet() == null ? 0 : as.getHelmet().getDurability(); + EulerAngle he = as.getHeadPose(); + EulerAngle ll = as.getLeftLegPose(); + EulerAngle rl = as.getRightLegPose(); + EulerAngle la = as.getLeftArmPose(); + EulerAngle ra = as.getRightArmPose(); + EulerAngle bo = as.getBodyPose(); + String cmd = "summon ArmorStand " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {" + + (as.isVisible() ? "" : "Invisible:1,") + + (as.hasBasePlate() ? "" : "NoBasePlate:1,") + + (as.hasGravity() ? "" : "NoGravity:1,") + + (as.hasArms() ? "ShowArms:1," : "") + + (as.isSmall() ? "Small:1," : "") + + (Main.nms.isInvulnerable(as) ? "Invulnerable:1," : "") + + (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ",")) + + (as.isCustomNameVisible() ? "CustomNameVisible:1," : "") + + (as.getCustomName() == null ? "" : ("CustomName:\"" + as.getCustomName() + "\",")) + + (loc.getYaw() == 0F ? "" : ("Rotation:[" + Utils.twoDec(loc.getYaw()) + "f],")) + + (getItemInMainHand(as) == null && as.getBoots() == null && as.getLeggings() == null && as.getChestplate() == null && as.getHelmet() == null ? "" : ( + "Equipment:[" + + "{id:" + hand + ",Count:" + getItemInMainHand(as).getAmount() + ",Damage:" + handDmg + getItemStackTags(getItemInMainHand(as)) + "}," + + "{id:" + boots + ",Count:" + as.getBoots().getAmount() + ",Damage:" + bootsDmg + getItemStackTags(as.getBoots()) + "}," + + "{id:" + legs + ",Count:" + as.getLeggings().getAmount() + ",Damage:" + legsDmg + getItemStackTags(as.getLeggings()) + "}," + + "{id:" + chest + ",Count:" + as.getChestplate().getAmount() + ",Damage:" + chestDmg + getItemStackTags(as.getChestplate()) + "}," + + "{id:" + helm + ",Count:" + as.getHelmet().getAmount() + ",Damage:" + helmDmg + getItemStackTags(as.getHelmet()) + skullOwner(as.getHelmet()) + "}],")) + + "Pose:{" + + (bo.equals(zero) ? "" : ("Body:[" + Utils.angle(bo.getX()) + "f," + Utils.angle(bo.getY()) + "f," + Utils.angle(bo.getZ()) + "f],")) + + (he.equals(zero) ? "" : ("Head:[" + Utils.angle(he.getX()) + "f," + Utils.angle(he.getY()) + "f," + Utils.angle(he.getZ()) + "f],")) + + (ll.equals(zero) ? "" : ("LeftLeg:[" + Utils.angle(ll.getX()) + "f," + Utils.angle(ll.getY()) + "f," + Utils.angle(ll.getZ()) + "f],")) + + (rl.equals(zero) ? "" : ("RightLeg:[" + Utils.angle(rl.getX()) + "f," + Utils.angle(rl.getY()) + "f," + Utils.angle(rl.getZ()) + "f],")) + + (la.equals(zero) ? "" : ("LeftArm:[" + Utils.angle(la.getX()) + "f," + Utils.angle(la.getY()) + "f," + Utils.angle(la.getZ()) + "f],")) + + "RightArm:[" + Utils.angle(ra.getX()) + "f," + Utils.angle(ra.getY()) + "f," + Utils.angle(ra.getZ()) + "f]}}"; + Block b = l.getBlock(); + b.setType(Material.COMMAND); + b.setData((byte) 0); + CommandBlock cb = (CommandBlock) b.getState(); + cb.setCommand(cmd); + cb.update(); + } + + ArmorStand clone(ArmorStand as) { + ArmorStand clone = (ArmorStand) as.getWorld().spawnEntity(as.getLocation().add(1, 0, 0), EntityType.ARMOR_STAND); + clone.setGravity(as.hasGravity()); + clone.setHelmet(as.getHelmet()); + clone.setChestplate(as.getChestplate()); + clone.setLeggings(as.getLeggings()); + clone.setBoots(as.getBoots()); + setItemInMainHand(clone, getItemInMainHand(as)); + if(offHand) { + setItemInOffHand(clone, getItemInOffHand(as)); + } + clone.setHeadPose(as.getHeadPose()); + clone.setBodyPose(as.getBodyPose()); + clone.setLeftArmPose(as.getLeftArmPose()); + clone.setRightArmPose(as.getRightArmPose()); + clone.setLeftLegPose(as.getLeftLegPose()); + clone.setRightLegPose(as.getRightLegPose()); + clone.setVisible(as.isVisible()); + clone.setBasePlate(as.hasBasePlate()); + clone.setArms(as.hasArms()); + clone.setCustomName(as.getCustomName()); + clone.setCustomNameVisible(as.isCustomNameVisible()); + clone.setSmall(as.isSmall()); + setSlotsDisabled(clone, getDisabledSlots(as) == 2039583); + setInvulnerable(clone, isInvulnerable(as)); + return clone; + } + + ItemStack getItemInMainHand(Player p) { + if(offHand) { + return p.getInventory().getItemInMainHand(); + } else { + //noinspection deprecation + return p.getInventory().getItemInHand(); + } + } + + ItemStack getItemInMainHand(ArmorStand as) { + if(offHand) { + return as.getEquipment().getItemInMainHand(); + } else { + //noinspection deprecation + return as.getEquipment().getItemInHand(); + } + } + + void setItemInMainHand(ArmorStand as, ItemStack is) { + if(offHand) { + as.getEquipment().setItemInMainHand(is); + } else { + //noinspection deprecation + as.getEquipment().setItemInHand(is); + } + } + + ItemStack getItemInOffHand(ArmorStand as) { + if(!offHand) return null; + return as.getEquipment().getItemInOffHand(); + } + + void setItemInOffHand(ArmorStand as, ItemStack is) { + if(!offHand) return; + as.getEquipment().setItemInOffHand(is); + } + + Object getTag(Object nmsEntity) { + + try { + Method method = nmsEntity.getClass().getMethod("getNBTTag"); + Object tag = method.invoke(nmsEntity); + if(tag == null) { + tag = getNMSClass("NBTTagCompound").newInstance(); + } + method = nmsEntity.getClass().getMethod("c", getNMSClass("NBTTagCompound")); + method.invoke(nmsEntity, tag); + return tag; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + boolean getInvulnerableBoolean(Object tag) { + try { + return (Boolean) tag.getClass().getMethod("getBoolean", String.class).invoke(tag, "Invulnerable"); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + void setInvulnerableBoolean(Object tag, boolean value) { + try { + tag.getClass().getMethod("setBoolean", String.class, boolean.class).invoke(tag, "Invulnerable", value); + } catch (Exception e) { + e.printStackTrace(); + } + } + + void saveTagF(Object nmsEntity, Object tag) { + try { + nmsEntity.getClass().getMethod("f", getNMSClass("NBTTagCompound")).invoke(nmsEntity, tag); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_10_R1.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_10_R1.java new file mode 100644 index 0000000..ba3ba21 --- /dev/null +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_10_R1.java @@ -0,0 +1,17 @@ +package com.gmail.St3venAU.plugins.ArmorStandTools; + +@SuppressWarnings("unused") +class NMS_v1_10_R1 extends NMS { + + public NMS_v1_10_R1() { + super( + "v1_10_R1", // NMS Version + "ArmorStand", // Armor Stand summon name + "bB", // Disabled slots field name + "a", // getKey field name + "IChatBaseComponent$ChatSerializer", // ChatSerializer field name + true // Version has an off hand + ); + } + +} diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_11_R1.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_11_R1.java new file mode 100644 index 0000000..a208707 --- /dev/null +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_11_R1.java @@ -0,0 +1,17 @@ +package com.gmail.St3venAU.plugins.ArmorStandTools; + +@SuppressWarnings("unused") +class NMS_v1_11_R1 extends NMS { + + public NMS_v1_11_R1() { + super( + "v1_11_R1", // NMS Version + "minecraft:armor_stand", // Armor Stand summon name + "bA", // Disabled slots field name + "a", // getKey field name + "IChatBaseComponent$ChatSerializer", // ChatSerializer field name + true // Version has an off hand + ); + } + +} diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_12_R1.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_12_R1.java new file mode 100644 index 0000000..9bbd608 --- /dev/null +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_12_R1.java @@ -0,0 +1,34 @@ +package com.gmail.St3venAU.plugins.ArmorStandTools; + +import org.bukkit.entity.Player; + +import java.lang.reflect.Constructor; + +@SuppressWarnings("unused") +class NMS_v1_12_R1 extends NMS { + + public NMS_v1_12_R1() { + super( + "v1_12_R1", // NMS Version + "minecraft:armor_stand", // Armor Stand summon name + "bB", // Disabled slots field name + "getKey", // getKey field name + "IChatBaseComponent$ChatSerializer", // ChatSerializer field name + true // Version has an off hand + ); + } + + @Override + void actionBarMsg(Player p, String msg) { + try { + Object chat = getNMSClass("ChatSerializer").getMethod("a", String.class).invoke(null, "{\"text\":\"" + msg + "\",\"color\":\"green\"}"); + Object packet; + Constructor constructor = getNMSClass("PacketPlayOutChat").getConstructor(getNMSClass("IChatBaseComponent"), getNMSClass("ChatMessageType")); + packet = constructor.newInstance(chat, getNMSClass("ChatMessageType").getEnumConstants()[2]); + sendPacket(p, packet); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_8_R1.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_8_R1.java new file mode 100644 index 0000000..2d5086a --- /dev/null +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_8_R1.java @@ -0,0 +1,37 @@ +package com.gmail.St3venAU.plugins.ArmorStandTools; + +import org.bukkit.entity.ArmorStand; + +@SuppressWarnings("unused") +class NMS_v1_8_R1 extends NMS { + + public NMS_v1_8_R1() { + super( + "v1_8_R1", // NMS Version + "ArmorStand", // Armor Stand summon name + "bg", // Disabled slots field name + "a", // getKey field name + "ChatSerializer", // ChatSerializer field name + false // Version has an off hand + ); + } + + @Override + boolean isInvulnerable(ArmorStand as) { + Object nmsEntity = getNmsEntity(as); + if (nmsEntity == null) return false; + Object tag = getTag(nmsEntity); + return tag != null && getInvulnerableBoolean(tag); + } + + @Override + void setInvulnerable(ArmorStand as, boolean invulnerable) { + Object nmsEntity = getNmsEntity(as); + if (nmsEntity == null) return; + Object tag = getTag(nmsEntity); + if(tag == null) return; + setInvulnerableBoolean(tag, invulnerable); + saveTagF(nmsEntity, tag); + } + +} diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_8_R2.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_8_R2.java new file mode 100644 index 0000000..d21d337 --- /dev/null +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_8_R2.java @@ -0,0 +1,37 @@ +package com.gmail.St3venAU.plugins.ArmorStandTools; + +import org.bukkit.entity.ArmorStand; + +@SuppressWarnings("unused") +class NMS_v1_8_R2 extends NMS { + + public NMS_v1_8_R2() { + super( + "v1_8_R2", // NMS Version + "ArmorStand", // Armor Stand summon name + "bi", // Disabled slots field name + "a", // getKey field name + "IChatBaseComponent$ChatSerializer", // ChatSerializer field name + false // Version has an off hand + ); + } + + @Override + boolean isInvulnerable(ArmorStand as) { + Object nmsEntity = getNmsEntity(as); + if (nmsEntity == null) return false; + Object tag = getTag(nmsEntity); + return tag != null && getInvulnerableBoolean(tag); + } + + @Override + void setInvulnerable(ArmorStand as, boolean invulnerable) { + Object nmsEntity = getNmsEntity(as); + if (nmsEntity == null) return; + Object tag = getTag(nmsEntity); + if(tag == null) return; + setInvulnerableBoolean(tag, invulnerable); + saveTagF(nmsEntity, tag); + } + +} diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_8_R3.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_8_R3.java new file mode 100644 index 0000000..ffc1b37 --- /dev/null +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_8_R3.java @@ -0,0 +1,37 @@ +package com.gmail.St3venAU.plugins.ArmorStandTools; + +import org.bukkit.entity.ArmorStand; + +@SuppressWarnings("unused") +class NMS_v1_8_R3 extends NMS { + + public NMS_v1_8_R3() { + super( + "v1_8_R3", // NMS Version + "ArmorStand", // Armor Stand summon name + "bi", // Disabled slots field name + "a", // getKey field name + "IChatBaseComponent$ChatSerializer", // ChatSerializer field name + false // Version has an off hand + ); + } + + @Override + boolean isInvulnerable(ArmorStand as) { + Object nmsEntity = getNmsEntity(as); + if (nmsEntity == null) return false; + Object tag = getTag(nmsEntity); + return tag != null && getInvulnerableBoolean(tag); + } + + @Override + void setInvulnerable(ArmorStand as, boolean invulnerable) { + Object nmsEntity = getNmsEntity(as); + if (nmsEntity == null) return; + Object tag = getTag(nmsEntity); + if(tag == null) return; + setInvulnerableBoolean(tag, invulnerable); + saveTagF(nmsEntity, tag); + } + +} diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_9_R1.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_9_R1.java new file mode 100644 index 0000000..0b04dbe --- /dev/null +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_9_R1.java @@ -0,0 +1,17 @@ +package com.gmail.St3venAU.plugins.ArmorStandTools; + +@SuppressWarnings("unused") +class NMS_v1_9_R1 extends NMS { + + public NMS_v1_9_R1() { + super( + "v1_9_R1", // NMS Version + "ArmorStand", // Armor Stand summon name + "bz", // Disabled slots field name + "a", // getKey field name + "IChatBaseComponent$ChatSerializer", // ChatSerializer field name + true // Version has an off hand + ); + } + +} diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_9_R2.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_9_R2.java new file mode 100644 index 0000000..42fb5a4 --- /dev/null +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/NMS_v1_9_R2.java @@ -0,0 +1,17 @@ +package com.gmail.St3venAU.plugins.ArmorStandTools; + +@SuppressWarnings("unused") +class NMS_v1_9_R2 extends NMS { + + public NMS_v1_9_R2() { + super( + "v1_9_R2", // NMS Version + "ArmorStand", // Armor Stand summon name + "bA", // Disabled slots field name + "a", // getKey field name + "IChatBaseComponent$ChatSerializer", // ChatSerializer field name + true // Version has an off hand + ); + } + +} diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java index f337c61..5890183 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java @@ -13,7 +13,6 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Arrays; import java.util.Collection; -import java.util.Set; class Utils { @@ -78,7 +77,6 @@ class Utils { return l; } - @SuppressWarnings("deprecation") static void cycleInventory(Player p) { Inventory i = p.getInventory(); ItemStack temp; @@ -89,48 +87,10 @@ class Utils { i.setItem(18 + n, i.getItem(9 + n)); i.setItem(9 + n, temp); } + //noinspection deprecation p.updateInventory(); } - static void actionBarMsg(Player p, String msg) { - try { - Object chat = getNMSClass("ChatSerializer").getMethod("a", String.class).invoke(null, "{\"text\":\"" + msg + "\",\"color\":\"green\"}"); - Object packet = getNMSClass("PacketPlayOutChat").getConstructor(getNMSClass("IChatBaseComponent"), byte.class).newInstance(chat, (byte) 2); - sendPacket(p, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - - static void openSign(Player p, Block b) { - try { - Object world = b.getWorld().getClass().getMethod("getHandle").invoke(b.getWorld()); - Object blockPos = getNMSClass("BlockPosition").getConstructor(int.class, int.class, int.class).newInstance(b.getX(), b.getY(), b.getZ()); - Object sign = world.getClass().getMethod("getTileEntity", getNMSClass("BlockPosition")).invoke(world, blockPos); - Object player = p.getClass().getMethod("getHandle").invoke(p); - player.getClass().getMethod("openSign", getNMSClass("TileEntitySign")).invoke(player, sign); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static Class getNMSClass(String nmsClassString) throws ClassNotFoundException { - if(nmsClassString.equals("ChatSerializer") && !Main.NMS_VERSION.equals("v1_8_R1")) { - nmsClassString = "IChatBaseComponent$ChatSerializer"; - } - return Class.forName("net.minecraft.server." + Main.NMS_VERSION + "." + nmsClassString); - } - - private static void sendPacket(Player p, Object packet) { - try { - Object player = p.getClass().getMethod("getHandle").invoke(p); - Object connection = player.getClass().getField("playerConnection").get(player); - connection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - static String angle(double d) { return twoDec(d * 180.0 / Math.PI); } @@ -159,37 +119,4 @@ class Utils { return is; } - @SuppressWarnings({"deprecation", "unchecked"}) - static String getNmsName(Material m) { - try { - Class block = getNMSClass("Block"); - Class item = getNMSClass("Item"); - Class registryBlocks = getNMSClass("RegistryBlocks"); - Class registryMaterials = getNMSClass("RegistryMaterials"); - Class regKey = getNMSClass("MinecraftKey"); - Object registry = block.getDeclaredField("REGISTRY").get(null); - Set set = (Set) registry.getClass().getMethod("keySet").invoke(registry); - for(Object key : set) { - Object b = registryBlocks.getMethod("get", Object.class).invoke(registry, key); - Integer id = (Integer) block.getMethod("getId", block).invoke(null, b); - if(id == m.getId()) { - return (String) regKey.getMethod("a").invoke(key); - } - } - registry = item.getDeclaredField("REGISTRY").get(null); - set = (Set) registry.getClass().getMethod("keySet").invoke(registry); - for(Object key : set) { - Object i = registryMaterials.getMethod("get", Object.class).invoke(registry, key); - Integer id = (Integer) item.getMethod("getId", item).invoke(null, i); - if(id == m.getId()) { - return (String) regKey.getMethod("a").invoke(key); - } - } - } catch (Exception e) { - e.printStackTrace(); - return null; - } - return null; - } - } diff --git a/src/config.yml b/src/config.yml index f809a1b..6b66a71 100644 --- a/src/config.yml +++ b/src/config.yml @@ -4,7 +4,7 @@ # # Main Config # -# File generated by: v2.2.1 +# File generated by: v2.3.0 # (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) # @@ -30,7 +30,9 @@ # astools.command Permission for the /astools command # astools.reload Permission to reload the plugin with /astools reload # astools.use Permission for using any of the tools (except the ones below) -# astools.clone Permission to use the clone tool +# astools.clone Permission to use the clone tool (Clones an armor stand without requiring the materials) +# astools.summon Permission to use the summon tool (Summons an armor stand without requiring the materials) +# astools.head Permission to use the player head tool (Ability to specify a player head for an armor stand) # astools.cmdblock Permission to use the save tool (Creates a command block) # # These are the defaults for spawning new armor stands with the /astools (or /ast) armor stand diff --git a/src/language.yml b/src/language.yml index f9828a5..167f156 100644 --- a/src/language.yml +++ b/src/language.yml @@ -4,7 +4,7 @@ # # Language Config # -# File generated by: v2.2.1 +# File generated by: v2.3.0 # (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) # @@ -59,8 +59,6 @@ headFailed: 'Failed to apply the player head. Try again.' noCommandPerm: 'You do not have permission to use this command' armorStand: 'Armor Stand' none: 'None' -enabled: 'Enabled' -disabled: 'Disabled' guiInUse: 'This armor stands GUI is in use' # ############################# @@ -176,12 +174,12 @@ tool: bodyX: name: 'Body X' lore: - - 'R-Click armor stand to change Body Z' + - 'R-Click armor stand to change Body X' - 'Value depends on how high up the body you click' bodyY: name: 'Body Y' lore: - - 'R-Click armor stand to change Body Z' + - 'R-Click armor stand to change Body Y' - 'Value depends on how high up the body you click' bodyZ: name: 'Body Z' diff --git a/src/plugin.yml b/src/plugin.yml index d8163bb..851d298 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ main: com.gmail.St3venAU.plugins.ArmorStandTools.Main name: ArmorStandTools -version: 2.2.1 +version: 2.3.0 author: St3venAU description: Armor stand manipulation tools softdepend: [WorldGuard, PlotSquared]