From 1fcefbcdcc90f742dcf52eda48da14d2935b9126 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 13 Feb 2020 19:47:02 +1300 Subject: [PATCH] Added 1.13.2 support, made backwards premium --- pom.xml | 25 ++- .../disguise/DisguiseConfig.java | 12 +- .../libraryaddict/disguise/LibsDisguises.java | 12 +- .../disguise/disguisetypes/AnimalColor.java | 10 +- .../disguise/disguisetypes/DisguiseType.java | 21 +- .../disguise/disguisetypes/FlagWatcher.java | 170 ++++++++-------- .../disguise/disguisetypes/MetaIndex.java | 130 ++++++++---- .../watchers/AbstractVillagerWatcher.java | 15 +- .../disguisetypes/watchers/ArrowWatcher.java | 12 +- .../disguisetypes/watchers/BeeWatcher.java | 3 + .../disguisetypes/watchers/CatWatcher.java | 19 +- .../watchers/EnderSignalWatcher.java | 16 +- .../watchers/FireballWatcher.java | 8 +- .../watchers/FireworkWatcher.java | 52 +++-- .../disguisetypes/watchers/FoxWatcher.java | 31 +-- .../disguisetypes/watchers/HorseWatcher.java | 37 +++- .../watchers/IllagerWizardWatcher.java | 22 +- .../disguisetypes/watchers/LivingWatcher.java | 98 ++++----- .../watchers/MushroomCowWatcher.java | 4 + .../disguisetypes/watchers/OcelotWatcher.java | 22 +- .../disguisetypes/watchers/PandaWatcher.java | 41 ++-- .../watchers/PillagerWatcher.java | 11 +- .../watchers/RavagerWatcher.java | 3 + .../watchers/SkeletonWatcher.java | 15 ++ .../watchers/ThrowableWatcher.java | 8 +- .../watchers/TraderLlamaWatcher.java | 3 + .../watchers/TridentWatcher.java | 6 +- .../watchers/VillagerWatcher.java | 55 +++-- .../watchers/VindicatorWatcher.java | 15 ++ .../disguisetypes/watchers/WolfWatcher.java | 8 +- .../watchers/ZombieVillagerWatcher.java | 49 +++-- .../disguisetypes/watchers/ZombieWatcher.java | 25 ++- .../disguise/utilities/DisguiseUtilities.java | 75 +++---- .../disguise/utilities/LibsPremium.java | 14 +- .../disguise/utilities/UpdateChecker.java | 11 +- .../utilities/mineskin/MineSkinAPI.java | 13 +- .../utilities/packets/PacketsHandler.java | 1 - .../packethandlers/PacketHandlerBed.java | 28 --- .../packethandlers/PacketHandlerSpawn.java | 28 ++- .../utilities/parser/DisguiseParser.java | 20 +- .../parser/params/ParamInfoManager.java | 24 +-- .../parser/params/ParamInfoTypes.java | 24 ++- .../utilities/reflection/ClassGetter.java | 39 ++-- .../utilities/reflection/CompileMethods.java | 79 ++++++++ .../utilities/reflection/DisguiseMethods.java | 133 +++++++++++++ .../{NmsAdded.java => NmsAddedIn.java} | 4 +- .../{NmsRemoved.java => NmsRemovedIn.java} | 4 +- .../utilities/reflection/NmsVersion.java | 10 +- .../reflection/ReflectionManager.java | 188 ++++++++++++------ 49 files changed, 1114 insertions(+), 539 deletions(-) delete mode 100644 src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerBed.java create mode 100644 src/main/java/me/libraryaddict/disguise/utilities/reflection/CompileMethods.java create mode 100644 src/main/java/me/libraryaddict/disguise/utilities/reflection/DisguiseMethods.java rename src/main/java/me/libraryaddict/disguise/utilities/reflection/{NmsAdded.java => NmsAddedIn.java} (81%) rename src/main/java/me/libraryaddict/disguise/utilities/reflection/{NmsRemoved.java => NmsRemovedIn.java} (80%) diff --git a/pom.xml b/pom.xml index 012eb4f0..445d6299 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ 9.9.3-SNAPSHOT - clean install + exec:java clean install LibsDisguises @@ -31,6 +31,25 @@ maven-surefire-plugin 3.0.0-M1 + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + + my-execution + compile + + java + + + + + true + me.libraryaddict.disguise.utilities.reflection.CompileMethods + + @@ -60,12 +79,12 @@ org.spigotmc spigot-api - 1.15-R0.1-SNAPSHOT + 1.15.2-R0.1-SNAPSHOT org.spigotmc spigot - 1.15-R0.1-SNAPSHOT + 1.15.2-R0.1-SNAPSHOT diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index 2f4ab0b5..cfa521ad 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -16,11 +16,11 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; import org.bukkit.entity.Entity; import java.io.File; import java.io.IOException; +import java.io.PrintWriter; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Iterator; @@ -308,9 +308,13 @@ public class DisguiseConfig { try { explain.createNewFile(); - FileUtils.write(explain, - "This folder is used to store .png files for uploading with the /savedisguise or /grabskin " + - "commands"); + + try (PrintWriter out = new PrintWriter(explain)) { + out.println( + "This folder is used to store .png files for uploading with the /savedisguise or " + + "/grabskin " + + "commands"); + } } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index 99b853d6..78e7c66a 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -20,6 +20,8 @@ import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; import java.io.File; +import java.util.Arrays; +import java.util.stream.Collectors; public class LibsDisguises extends JavaPlugin { private static LibsDisguises instance; @@ -71,7 +73,15 @@ public class LibsDisguises extends JavaPlugin { if (ReflectionManager.getVersion() == null) { getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " + - "intended for 1.14 & 1.15!"); + "intended for " + StringUtils + .join(Arrays.stream(NmsVersion.values()).map(v -> v.name().replace("_", ".")) + .collect(Collectors.toList()), " & ") + "!"); + getPluginLoader().disablePlugin(this); + return; + } + + if (!LibsPremium.isPremium() && ReflectionManager.getVersion().ordinal() < NmsVersion.values().length - 1) { + getLogger().severe("Backwards compatibility is premium only! Use older builds or purchase the plugin!"); getPluginLoader().disablePlugin(this); return; } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java index 454c2458..32571d7e 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java @@ -1,5 +1,6 @@ package me.libraryaddict.disguise.disguisetypes; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.DyeColor; import org.bukkit.Material; @@ -9,17 +10,20 @@ public enum AnimalColor { BROWN(DyeColor.BROWN, Material.COCOA_BEANS), CYAN(DyeColor.CYAN, Material.CYAN_DYE), GRAY(DyeColor.GRAY, Material.GRAY_DYE), - GREEN(DyeColor.GREEN, Material.GREEN_DYE), + GREEN(DyeColor.GREEN, + NmsVersion.v1_14.isSupported() ? Material.getMaterial("GREEN_DYE") : Material.getMaterial("CATCUS_GREEN")), LIGHT_BLUE(DyeColor.LIGHT_BLUE, Material.LIGHT_BLUE_DYE), LIME(DyeColor.LIME, Material.LIME_DYE), MAGENTA(DyeColor.MAGENTA, Material.MAGENTA_DYE), ORANGE(DyeColor.ORANGE, Material.ORANGE_DYE), PINK(DyeColor.PINK, Material.PINK_DYE), PURPLE(DyeColor.PURPLE, Material.PURPLE_DYE), - RED(DyeColor.RED, Material.RED_DYE), + RED(DyeColor.RED, + NmsVersion.v1_14.isSupported() ? Material.getMaterial("RED_DYE") : Material.getMaterial("ROSE_RED")), LIGHT_GRAY(DyeColor.LIGHT_GRAY, Material.LIGHT_GRAY_DYE), WHITE(DyeColor.WHITE, Material.BONE_MEAL), - YELLOW(DyeColor.YELLOW, Material.YELLOW_DYE); + YELLOW(DyeColor.YELLOW, NmsVersion.v1_14.isSupported() ? Material.getMaterial("YELLOW_DYE") : + Material.getMaterial("DANDELION_YELLOW")); public static AnimalColor getColorByWool(int woolId) { for (AnimalColor color : values()) { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 6d24da8e..2df8bb40 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.disguisetypes; -import me.libraryaddict.disguise.utilities.reflection.NmsAdded; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.translations.TranslateType; import org.apache.commons.lang.StringUtils; @@ -16,13 +17,13 @@ public enum DisguiseType { BAT, - @NmsAdded(added = NmsVersion.v1_15) BEE, + @NmsAddedIn(val = NmsVersion.v1_15) BEE, BLAZE, BOAT(1), - CAT, + @NmsAddedIn(val = NmsVersion.v1_14) CAT, CAVE_SPIDER, @@ -74,7 +75,7 @@ public enum DisguiseType { FISHING_HOOK(90), - FOX, + @NmsAddedIn(val = NmsVersion.v1_14) FOX, GHAST, @@ -122,7 +123,7 @@ public enum DisguiseType { PAINTING, - PANDA, + @NmsAddedIn(val = NmsVersion.v1_14) PANDA, PARROT, @@ -132,7 +133,7 @@ public enum DisguiseType { PIG_ZOMBIE, - PILLAGER, + @NmsAddedIn(val = NmsVersion.v1_14) PILLAGER, PLAYER, @@ -144,7 +145,7 @@ public enum DisguiseType { RABBIT, - RAVAGER, + @NmsAddedIn(val = NmsVersion.v1_14) RAVAGER, SALMON, @@ -180,9 +181,11 @@ public enum DisguiseType { THROWN_EXP_BOTTLE(75), + @NmsRemovedIn(val = NmsVersion.v1_14) TIPPED_ARROW(60), + TRIDENT(94, 0), - TRADER_LLAMA, + @NmsAddedIn(val = NmsVersion.v1_14) TRADER_LLAMA, TROPICAL_FISH, @@ -198,7 +201,7 @@ public enum DisguiseType { VINDICATOR, - WANDERING_TRADER, + @NmsAddedIn(val = NmsVersion.v1_14) WANDERING_TRADER, WITCH, diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 59c40718..0258ce90 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -13,6 +13,8 @@ import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; @@ -195,10 +197,12 @@ public class FlagWatcher { return newList; } + @NmsAddedIn(val = NmsVersion.v1_14) public EntityPose getEntityPose() { return getData(MetaIndex.ENTITY_POSE); } + @NmsAddedIn(val = NmsVersion.v1_14) public void setEntityPose(EntityPose entityPose) { setData(MetaIndex.ENTITY_POSE, entityPose); sendData(MetaIndex.ENTITY_POSE); @@ -208,6 +212,10 @@ public class FlagWatcher { return getEquipment().getArmorContents(); } + public void setArmor(ItemStack[] items) { + getEquipment().setArmorContents(items); + } + public String getCustomName() { Optional optional = getData(MetaIndex.ENTITY_CUSTOM_NAME); @@ -220,10 +228,29 @@ public class FlagWatcher { return null; } + public void setCustomName(String name) { + if (Strings.isNullOrEmpty(name)) { + setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty()); + } else { + if (name.length() > 64) { + name = name.substring(0, 64); + } + + setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.of(WrappedChatComponent.fromText(name))); + } + + sendData(MetaIndex.ENTITY_CUSTOM_NAME); + } + protected TargetedDisguise getDisguise() { return disguise; } + protected void setDisguise(TargetedDisguise disguise) { + this.disguise = disguise; + equipment.setFlagWatcher(this); + } + private boolean getEntityFlag(int byteValue) { return (getData(MetaIndex.ENTITY_META) & 1 << byteValue) != 0; } @@ -236,10 +263,18 @@ public class FlagWatcher { return equipment.getItemInMainHand(); } + public void setItemInMainHand(ItemStack itemstack) { + setItemStack(EquipmentSlot.HAND, itemstack); + } + public ItemStack getItemInOffHand() { return equipment.getItemInOffHand(); } + public void setItemInOffHand(ItemStack itemstack) { + setItemStack(EquipmentSlot.OFF_HAND, itemstack); + } + public ItemStack getItemStack(EquipmentSlot slot) { return equipment.getItem(slot); } @@ -278,10 +313,21 @@ public class FlagWatcher { return getEntityFlag(0); } + public void setBurning(boolean setBurning) { + setEntityFlag(0, setBurning); + + sendData(MetaIndex.ENTITY_META); + } + public boolean isCustomNameVisible() { return getData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE); } + public void setCustomNameVisible(boolean display) { + setData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE, display); + sendData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE); + } + @Deprecated public boolean isEntityAnimationsAdded() { return addEntityAnimations; @@ -291,30 +337,67 @@ public class FlagWatcher { return getEntityFlag(7); } + public void setFlyingWithElytra(boolean flying) { + setEntityFlag(7, flying); + sendData(MetaIndex.ENTITY_META); + } + public boolean isGlowing() { return getEntityFlag(6); } + public void setGlowing(boolean glowing) { + setEntityFlag(6, glowing); + sendData(MetaIndex.ENTITY_META); + } + public boolean isInvisible() { return getEntityFlag(5); } + public void setInvisible(boolean setInvis) { + setEntityFlag(5, setInvis); + sendData(MetaIndex.ENTITY_META); + } + public boolean isNoGravity() { return getData(MetaIndex.ENTITY_NO_GRAVITY); } + public void setNoGravity(boolean noGravity) { + setData(MetaIndex.ENTITY_NO_GRAVITY, noGravity); + sendData(MetaIndex.ENTITY_NO_GRAVITY); + } + public boolean isRightClicking() { return getEntityFlag(4); } + public void setRightClicking(boolean setRightClicking) { + setEntityFlag(4, setRightClicking); + sendData(MetaIndex.ENTITY_META); + } + public boolean isSneaking() { return getEntityFlag(1); } + public void setSneaking(boolean setSneaking) { + setEntityFlag(1, setSneaking); + sendData(MetaIndex.ENTITY_META); + + updatePose(); + } + public boolean isSprinting() { return getEntityFlag(3); } + public void setSprinting(boolean setSprinting) { + setEntityFlag(3, setSprinting); + sendData(MetaIndex.ENTITY_META); + } + public void rebuildWatchableObjects() { watchableObjects = new ArrayList<>(); @@ -355,8 +438,7 @@ public class FlagWatcher { Object value = entityValues.get(data.getIndex()); - if (isEntityAnimationsAdded() && DisguiseConfig.isMetaPacketsEnabled() && - data == MetaIndex.ENTITY_META) { + if (isEntityAnimationsAdded() && DisguiseConfig.isMetaPacketsEnabled() && data == MetaIndex.ENTITY_META) { value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); } @@ -403,10 +485,6 @@ public class FlagWatcher { addEntityAnimations = isEntityAnimationsAdded; } - public void setArmor(ItemStack[] items) { - getEquipment().setArmorContents(items); - } - protected void setBackupValue(MetaIndex no, Object value) { if (no == null) return; @@ -414,31 +492,6 @@ public class FlagWatcher { backupEntityValues.put(no.getIndex(), value); } - public void setBurning(boolean setBurning) { - setEntityFlag(0, setBurning); - - sendData(MetaIndex.ENTITY_META); - } - - public void setCustomName(String name) { - if (Strings.isNullOrEmpty(name)) { - setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty()); - } else { - if (name.length() > 64) { - name = name.substring(0, 64); - } - - setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.of(WrappedChatComponent.fromText(name))); - } - - sendData(MetaIndex.ENTITY_CUSTOM_NAME); - } - - public void setCustomNameVisible(boolean display) { - setData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE, display); - sendData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE); - } - private void setEntityFlag(int byteValue, boolean flag) { modifiedEntityAnimations[byteValue] = true; @@ -451,21 +504,6 @@ public class FlagWatcher { } } - public void setFlyingWithElytra(boolean flying) { - setEntityFlag(7, flying); - sendData(MetaIndex.ENTITY_META); - } - - public void setGlowing(boolean glowing) { - setEntityFlag(6, glowing); - sendData(MetaIndex.ENTITY_META); - } - - public void setInvisible(boolean setInvis) { - setEntityFlag(5, setInvis); - sendData(MetaIndex.ENTITY_META); - } - /** * Don't use this, use setItemInMainHand instead * @@ -476,14 +514,6 @@ public class FlagWatcher { setItemInMainHand(itemstack); } - public void setItemInMainHand(ItemStack itemstack) { - setItemStack(EquipmentSlot.HAND, itemstack); - } - - public void setItemInOffHand(ItemStack itemstack) { - setItemStack(EquipmentSlot.OFF_HAND, itemstack); - } - public void setItemStack(EquipmentSlot slot, ItemStack itemStack) { equipment.setItem(slot, itemStack); } @@ -540,23 +570,6 @@ public class FlagWatcher { } } - public void setNoGravity(boolean noGravity) { - setData(MetaIndex.ENTITY_NO_GRAVITY, noGravity); - sendData(MetaIndex.ENTITY_NO_GRAVITY); - } - - public void setRightClicking(boolean setRightClicking) { - setEntityFlag(4, setRightClicking); - sendData(MetaIndex.ENTITY_META); - } - - public void setSneaking(boolean setSneaking) { - setEntityFlag(1, setSneaking); - sendData(MetaIndex.ENTITY_META); - - updatePose(); - } - public boolean isSleeping() { return sleeping; } @@ -597,15 +610,15 @@ public class FlagWatcher { } } - public void setSprinting(boolean setSprinting) { - setEntityFlag(3, setSprinting); - sendData(MetaIndex.ENTITY_META); - } - protected void setData(MetaIndex id, Y value) { if (id == null) return; + if (id.getIndex() == -1) { + throw new IllegalArgumentException( + "You can't do that in this version of Minecraft! I can't use " + MetaIndex.getName(id) + "!"); + } + if (value == null && id.getDefault() instanceof ItemStack) throw new IllegalArgumentException("Cannot use null ItemStacks"); @@ -615,9 +628,4 @@ public class FlagWatcher { rebuildWatchableObjects(); } } - - protected void setDisguise(TargetedDisguise disguise) { - this.disguise = disguise; - equipment.setFlagWatcher(this); - } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java index 7bc02f28..f6c345ad 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/MetaIndex.java @@ -7,15 +7,14 @@ import com.comphenix.protocol.wrappers.nbt.NbtFactory; import com.comphenix.protocol.wrappers.nbt.NbtType; import me.libraryaddict.disguise.disguisetypes.watchers.*; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.reflection.NmsAdded; -import me.libraryaddict.disguise.utilities.reflection.NmsRemoved; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.Particle; -import org.bukkit.entity.MushroomCow; import org.bukkit.entity.Villager; import org.bukkit.inventory.ItemStack; @@ -105,6 +104,7 @@ public class MetaIndex { */ public static MetaIndex> ARROW_UUID = new MetaIndex<>(ArrowWatcher.class, 1, Optional.empty()); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex ARROW_PIERCE_LEVEL = new MetaIndex<>(ArrowWatcher.class, 2, (byte) 0); /** @@ -112,10 +112,10 @@ public class MetaIndex { */ public static MetaIndex BAT_HANGING = new MetaIndex<>(BatWatcher.class, 0, (byte) 1); - @NmsAdded(added = NmsVersion.v1_15) + @NmsAddedIn(val = NmsVersion.v1_15) public static MetaIndex BEE_META = new MetaIndex<>(BeeWatcher.class, 0, (byte) 0); - @NmsAdded(added = NmsVersion.v1_15) + @NmsAddedIn(val = NmsVersion.v1_15) public static MetaIndex BEE_ANGER = new MetaIndex<>(BeeWatcher.class, 1, 0); /** @@ -143,12 +143,16 @@ public class MetaIndex { public static MetaIndex BOAT_SHAKE = new MetaIndex<>(BoatWatcher.class, 6, 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex CAT_TYPE = new MetaIndex<>(CatWatcher.class, 0, 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex CAT_LYING_DOWN = new MetaIndex<>(CatWatcher.class, 1, false); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex CAT_LOOKING_UP = new MetaIndex<>(CatWatcher.class, 2, false); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex CAT_COLLAR = new MetaIndex<>(CatWatcher.class, 3, AnimalColor.RED.ordinal()); /** @@ -197,6 +201,7 @@ public class MetaIndex { public static MetaIndex ENDER_DRAGON_PHASE = new MetaIndex<>(EnderDragonWatcher.class, 0, 10); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex ENDER_SIGNAL_ITEM = new MetaIndex<>(EnderSignalWatcher.class, 0, new ItemStack(Material.AIR)); @@ -205,7 +210,7 @@ public class MetaIndex { */ public static MetaIndex ENDERMAN_AGRESSIVE = new MetaIndex<>(EndermanWatcher.class, 1, false); - @NmsAdded(added = NmsVersion.v1_15) + @NmsAddedIn(val = NmsVersion.v1_15) public static MetaIndex ENDERMAN_UNKNOWN = new MetaIndex<>(EndermanWatcher.class, 2, false); /** @@ -245,11 +250,14 @@ public class MetaIndex { /** * If entity can make sounds, no noticable effects */ + + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex ENTITY_POSE = new MetaIndex<>(FlagWatcher.class, 6, EntityPose.STANDING); public static MetaIndex FALLING_BLOCK_POSITION = new MetaIndex<>(FallingBlockWatcher.class, 0, BlockPosition.ORIGIN); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex FIREBALL_ITEM = new MetaIndex<>(FireballWatcher.class, 0, new ItemStack(Material.AIR)); @@ -258,9 +266,14 @@ public class MetaIndex { public static MetaIndex FISH_FROM_BUCKET = new MetaIndex<>(FishWatcher.class, 0, false); + @NmsRemovedIn(val = NmsVersion.v1_14) + public static MetaIndex FIREWORK_ATTACHED_ENTITY_OLD = new MetaIndex<>(FireworkWatcher.class, 1, 0); + + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex FIREWORK_ATTACHED_ENTITY = new MetaIndex<>(FireworkWatcher.class, 1, OptionalInt.empty()); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex FIREWORK_SHOT_AT_ANGLE = new MetaIndex<>(FireworkWatcher.class, 2, false); public static MetaIndex FISHING_HOOK_HOOKED = new MetaIndex<>(FishingHookWatcher.class, 0, 0); @@ -268,12 +281,16 @@ public class MetaIndex { /** * The type of fox, its coloring */ + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex FOX_TYPE = new MetaIndex<>(FoxWatcher.class, 0, 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex FOX_META = new MetaIndex<>(FoxWatcher.class, 1, (byte) 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex> FOX_TRUSTED_1 = new MetaIndex<>(FoxWatcher.class, 2, Optional.empty()); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex> FOX_TRUSTED_2 = new MetaIndex<>(FoxWatcher.class, 3, Optional.empty()); /** @@ -297,6 +314,8 @@ public class MetaIndex { public static MetaIndex HORSE_CHESTED_CARRYING_CHEST = new MetaIndex<>(ChestedHorseWatcher.class, 0, false); + @NmsRemovedIn(val = NmsVersion.v1_14) + public static MetaIndex HORSE_ARMOR = new MetaIndex<>(HorseWatcher.class, 1, 0); /** * Color of the horse, uses enum not RGB */ @@ -313,8 +332,15 @@ public class MetaIndex { public static MetaIndex> HORSE_OWNER = new MetaIndex<>(AbstractHorseWatcher.class, 1, Optional.empty()); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex ILLAGER_SPELL = new MetaIndex<>(IllagerWizardWatcher.class, 0, (byte) 0); + @NmsRemovedIn(val = NmsVersion.v1_14) + public static MetaIndex ILLAGER_META = new MetaIndex<>(IllagerWatcher.class, 0, (byte) 0); + + @NmsRemovedIn(val = NmsVersion.v1_14) + public static MetaIndex ILLAGER_SPELL_TICKS = new MetaIndex<>(IllagerWizardWatcher.class, 0, (byte) 0); + public static MetaIndex INSENTIENT_META = new MetaIndex<>(InsentientWatcher.class, 0, (byte) 0); public static MetaIndex IRON_GOLEM_PLAYER_CREATED = new MetaIndex<>(IronGolemWatcher.class, 0, (byte) 0); @@ -358,9 +384,10 @@ public class MetaIndex { /** * How many bee stings does the entity have */ - @NmsAdded(added = NmsVersion.v1_15) + @NmsAddedIn(val = NmsVersion.v1_15) public static MetaIndex LIVING_STINGS = new MetaIndex<>(LivingWatcher.class, 5, 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex> LIVING_BED_POSITION = new MetaIndex<>(LivingWatcher.class, 6, Optional.empty()); @@ -410,21 +437,31 @@ public class MetaIndex { */ public static MetaIndex MINECART_FURANCE_FUELED = new MetaIndex<>(MinecartFurnaceWatcher.class, 0, false); - public static MetaIndex MUSHROOM_COW_TYPE = new MetaIndex<>(MushroomCowWatcher.class, 0, - MushroomCow.Variant.RED.name().toLowerCase()); + @NmsAddedIn(val = NmsVersion.v1_14) + public static MetaIndex MUSHROOM_COW_TYPE = new MetaIndex<>(MushroomCowWatcher.class, 0, "RED"); + @NmsRemovedIn(val = NmsVersion.v1_14) + public static MetaIndex OCELOT_TYPE = new MetaIndex<>(OcelotWatcher.class, 0, 0); + + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex OCELOT_TRUST = new MetaIndex<>(OcelotWatcher.class, 0, false); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex PANDA_HEAD_SHAKING = new MetaIndex<>(PandaWatcher.class, 0, 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex PANDA_UNKNOWN_1 = new MetaIndex<>(PandaWatcher.class, 1, 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex PANDA_UNKNOWN_2 = new MetaIndex<>(PandaWatcher.class, 2, 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex PANDA_MAIN_GENE = new MetaIndex<>(PandaWatcher.class, 3, (byte) 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex PANDA_HIDDEN_GENE = new MetaIndex<>(PandaWatcher.class, 4, (byte) 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex PANDA_META = new MetaIndex<>(PandaWatcher.class, 5, (byte) 0); public static MetaIndex PARROT_VARIANT = new MetaIndex<>(ParrotWatcher.class, 0, 0); @@ -438,6 +475,7 @@ public class MetaIndex { */ public static MetaIndex PIG_BOOST = new MetaIndex<>(PigWatcher.class, 1, 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex PILLAGER_AIMING_BOW = new MetaIndex<>(PillagerWatcher.class, 0, false); public static MetaIndex PLAYER_ABSORPTION = new MetaIndex<>(PlayerWatcher.class, 0, 0F); @@ -460,6 +498,7 @@ public class MetaIndex { public static MetaIndex RABBIT_TYPE = new MetaIndex<>(RabbitWatcher.class, 0, 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex RAIDER_CASTING_SPELL = new MetaIndex<>(RaiderWatcher.class, 0, false); public static MetaIndex SHEEP_WOOL = new MetaIndex<>(SheepWatcher.class, 0, (byte) 0); @@ -473,6 +512,9 @@ public class MetaIndex { public static MetaIndex SHULKER_PEEKING = new MetaIndex<>(ShulkerWatcher.class, 2, (byte) 0); + @NmsRemovedIn(val = NmsVersion.v1_14) + public static MetaIndex SKELETON_SWING_ARMS = new MetaIndex<>(SkeletonWatcher.class, 0, false); + public static MetaIndex SLIME_SIZE = new MetaIndex<>(SlimeWatcher.class, 0, 1); public static MetaIndex SNOWMAN_DERP = new MetaIndex<>(SnowmanWatcher.class, 0, (byte) 16); @@ -487,6 +529,7 @@ public class MetaIndex { public static MetaIndex> TAMEABLE_OWNER = new MetaIndex<>(TameableWatcher.class, 1, Optional.empty()); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex THROWABLE_ITEM = new MetaIndex<>(ThrowableWatcher.class, 0, new ItemStack(Material.AIR)); @@ -496,7 +539,7 @@ public class MetaIndex { public static MetaIndex TRIDENT_ENCHANTS = new MetaIndex<>(TridentWatcher.class, 0, (byte) 0); - @NmsAdded(added = NmsVersion.v1_15) + @NmsAddedIn(val = NmsVersion.v1_15) public static MetaIndex TRIDENT_ENCHANTED = new MetaIndex<>(TridentWatcher.class, 1, false); public static MetaIndex TROPICAL_FISH_VARIANT = new MetaIndex<>(TropicalFishWatcher.class, 0, 0); @@ -517,10 +560,16 @@ public class MetaIndex { public static MetaIndex VEX_ANGRY = new MetaIndex<>(VexWatcher.class, 0, (byte) 0); + @NmsRemovedIn(val = NmsVersion.v1_14) + public static MetaIndex VILLAGER_PROFESSION = new MetaIndex<>(VillagerWatcher.class, 0, 0); + + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex ABSTRACT_VILLAGER_ANGRY = new MetaIndex<>(AbstractVillagerWatcher.class, 0, 0); + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex VILLAGER_DATA = new MetaIndex<>(VillagerWatcher.class, 0, - new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1)); + NmsVersion.v1_14.isSupported() ? new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1) : + null); public static MetaIndex WITCH_AGGRESSIVE = new MetaIndex<>(WitchWatcher.class, 0, false); @@ -536,19 +585,28 @@ public class MetaIndex { public static MetaIndex WOLF_BEGGING = new MetaIndex<>(WolfWatcher.class, 1, false); - @NmsRemoved(removed = NmsVersion.v1_15) + @NmsRemovedIn(val = NmsVersion.v1_15) public static MetaIndex WOLF_DAMAGE = new MetaIndex<>(WolfWatcher.class, 0, 1F); public static MetaIndex WOLF_COLLAR = new MetaIndex<>(WolfWatcher.class, 2, 14); + @NmsRemovedIn(val = NmsVersion.v1_14) + public static MetaIndex ZOMBIE_AGGRESSIVE = new MetaIndex<>(ZombieWatcher.class, 2, false); + public static MetaIndex ZOMBIE_BABY = new MetaIndex<>(ZombieWatcher.class, 0, false); public static MetaIndex ZOMBIE_CONVERTING_DROWNED = new MetaIndex<>(ZombieWatcher.class, 2, false); public static MetaIndex ZOMBIE_PLACEHOLDER = new MetaIndex<>(ZombieWatcher.class, 1, 0); + @NmsRemovedIn(val = NmsVersion.v1_14) + public static MetaIndex ZOMBIE_VILLAGER_PROFESSION_OLD = new MetaIndex<>(ZombieVillagerWatcher.class, 1, + 0); + + @NmsAddedIn(val = NmsVersion.v1_14) public static MetaIndex ZOMBIE_VILLAGER_PROFESSION = new MetaIndex<>(ZombieVillagerWatcher.class, 1, - new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1)); + NmsVersion.v1_14.isSupported() ? new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1) : + null); /** * Shown for villager conversion @@ -561,35 +619,20 @@ public class MetaIndex { orderMetaIndexes(); } - @Deprecated private static void eliminateBlankIndexes() { - ArrayList>> list = new ArrayList<>(); + HashMap> metas = new HashMap<>(); for (MetaIndex index : values()) { - Entry> entry = null; - - for (Entry e : list) { - if (e.getKey() != index.getFlagWatcher()) - continue; - - entry = e; - break; - } - - if (entry == null) { - entry = new AbstractMap.SimpleEntry(index.getFlagWatcher(), new ArrayList()); - - list.add(entry); - } - - entry.getValue().add(index); + metas.computeIfAbsent(index.getFlagWatcher(), (a) -> new ArrayList<>()).add(index); } - for (Entry> entry : list) { - entry.getValue().sort(Comparator.comparingInt(MetaIndex::getIndex)); + for (ArrayList list : metas.values()) { + list.sort(Comparator.comparingInt(MetaIndex::getIndex)); - for (MetaIndex ind : entry.getValue()) { - ind._index = entry.getValue().indexOf(ind); + int i = 0; + + for (MetaIndex ind : list) { + ind._index = i++; } } } @@ -599,7 +642,7 @@ public class MetaIndex { if (flagType.getFlagWatcher() == FlagWatcher.class) continue; - flagType._index += getNoIndexes(flagType.getFlagWatcher().getSuperclass()); + flagType._index += getNoIndexes(ReflectionManager.getSuperClass(flagType.getFlagWatcher())); } } @@ -628,7 +671,7 @@ public class MetaIndex { if (type.getIndex() != i) continue; - if (!type.getFlagWatcher().isAssignableFrom(entry.getKey())) + if (!ReflectionManager.isAssignableFrom(entry.getKey(), type.getFlagWatcher())) continue; if (found != null) { @@ -702,7 +745,7 @@ public class MetaIndex { if (type.getIndex() != flagNo) continue; - if (!type.getFlagWatcher().isAssignableFrom(watcherClass)) + if (!ReflectionManager.isAssignableFrom(watcherClass, type.getFlagWatcher())) continue; return type; @@ -719,7 +762,7 @@ public class MetaIndex { ArrayList list = new ArrayList<>(); for (MetaIndex type : values()) { - if (type == null || !type.getFlagWatcher().isAssignableFrom(watcherClass)) + if (type == null || !ReflectionManager.isAssignableFrom(watcherClass, type.getFlagWatcher())) continue; list.add(type); @@ -741,7 +784,7 @@ public class MetaIndex { } if (c != FlagWatcher.class) { - found += getNoIndexes(c.getSuperclass()); + found += getNoIndexes(ReflectionManager.getSuperClass(c)); } return found; @@ -839,12 +882,13 @@ public class MetaIndex { if (field.getType() != MetaIndex.class) continue; + MetaIndex index = (MetaIndex) field.get(null); + if (!ReflectionManager.isSupported(field)) { + index._index = -1; continue; } - MetaIndex index = (MetaIndex) field.get(null); - if (index == null) continue; diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractVillagerWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractVillagerWatcher.java index dc73bbac..2c3fdb96 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractVillagerWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AbstractVillagerWatcher.java @@ -2,6 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** * Created by libraryaddict on 18/05/2019. @@ -11,16 +13,19 @@ public class AbstractVillagerWatcher extends AgeableWatcher { super(disguise); } - public void setAngry(int ticks) { - setData(MetaIndex.ABSTRACT_VILLAGER_ANGRY, ticks); - sendData(MetaIndex.ABSTRACT_VILLAGER_ANGRY); - } - + @NmsAddedIn(val = NmsVersion.v1_14) public int getAngry() { return getData(MetaIndex.ABSTRACT_VILLAGER_ANGRY); } + @NmsAddedIn(val = NmsVersion.v1_14) public boolean isAngry() { return getAngry() > 0; } + + @NmsAddedIn(val = NmsVersion.v1_14) + public void setAngry(int ticks) { + setData(MetaIndex.ABSTRACT_VILLAGER_ANGRY, ticks); + sendData(MetaIndex.ABSTRACT_VILLAGER_ANGRY); + } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java index 521b56eb..6d7853f7 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java @@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; public class ArrowWatcher extends FlagWatcher { public ArrowWatcher(Disguise disguise) { @@ -18,12 +20,14 @@ public class ArrowWatcher extends FlagWatcher { sendData(MetaIndex.ARROW_CRITICAL); } + @NmsAddedIn(val = NmsVersion.v1_14) + public int getPierceLevel() { + return getData(MetaIndex.ARROW_PIERCE_LEVEL); + } + + @NmsAddedIn(val = NmsVersion.v1_14) public void setPierceLevel(int pierceLevel) { setData(MetaIndex.ARROW_PIERCE_LEVEL, (byte) pierceLevel); sendData(MetaIndex.ARROW_PIERCE_LEVEL); } - - public int getPierceLevel() { - return getData(MetaIndex.ARROW_PIERCE_LEVEL); - } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java index 148ddbff..248de427 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BeeWatcher.java @@ -2,10 +2,13 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** * Created by libraryaddict on 14/12/2019. */ +@NmsAddedIn(val = NmsVersion.v1_15) public class BeeWatcher extends AgeableWatcher { public BeeWatcher(Disguise disguise) { super(disguise); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java index f9ca8359..3492be16 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java @@ -4,6 +4,8 @@ import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.DyeColor; import org.bukkit.entity.Cat; @@ -12,6 +14,7 @@ import java.util.Random; /** * Created by libraryaddict on 6/05/2019. */ +@NmsAddedIn(val = NmsVersion.v1_14) public class CatWatcher extends TameableWatcher { public CatWatcher(Disguise disguise) { super(disguise); @@ -29,6 +32,10 @@ public class CatWatcher extends TameableWatcher { sendData(MetaIndex.CAT_TYPE); } + public DyeColor getCollarColor() { + return AnimalColor.getColorByWool(getData(MetaIndex.CAT_COLLAR)).getDyeColor(); + } + @Deprecated public void setCollarColor(AnimalColor color) { setCollarColor(color.getDyeColor()); @@ -47,8 +54,8 @@ public class CatWatcher extends TameableWatcher { sendData(MetaIndex.CAT_COLLAR); } - public DyeColor getCollarColor() { - return AnimalColor.getColorByWool(getData(MetaIndex.CAT_COLLAR)).getDyeColor(); + public boolean isLyingDown() { + return getData(MetaIndex.CAT_LYING_DOWN); } public void setLyingDown(boolean value) { @@ -56,16 +63,12 @@ public class CatWatcher extends TameableWatcher { sendData(MetaIndex.CAT_LYING_DOWN); } - public boolean isLyingDown() { - return getData(MetaIndex.CAT_LYING_DOWN); + public boolean isLookingUp() { + return getData(MetaIndex.CAT_LOOKING_UP); } public void setLookingUp(boolean value) { setData(MetaIndex.CAT_LOOKING_UP, value); sendData(MetaIndex.CAT_LOOKING_UP); } - - public boolean isLookingUp() { - return getData(MetaIndex.CAT_LOOKING_UP); - } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EnderSignalWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EnderSignalWatcher.java index 592d40fd..81dde603 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EnderSignalWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EnderSignalWatcher.java @@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -13,15 +15,19 @@ public class EnderSignalWatcher extends FlagWatcher { public EnderSignalWatcher(Disguise disguise) { super(disguise); - setItemStack(new ItemStack(Material.ENDER_EYE)); + if (NmsVersion.v1_14.isSupported()) { + setItemStack(new ItemStack(Material.ENDER_EYE)); + } } + @NmsAddedIn(val = NmsVersion.v1_14) + public ItemStack getItemStack() { + return getData(MetaIndex.ENDER_SIGNAL_ITEM); + } + + @NmsAddedIn(val = NmsVersion.v1_14) public void setItemStack(ItemStack item) { setData(MetaIndex.ENDER_SIGNAL_ITEM, item); sendData(MetaIndex.ENDER_SIGNAL_ITEM); } - - public ItemStack getItemStack() { - return getData(MetaIndex.ENDER_SIGNAL_ITEM); - } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireballWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireballWatcher.java index 6dd3e89e..1d2734d7 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireballWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireballWatcher.java @@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -13,13 +15,17 @@ public class FireballWatcher extends FlagWatcher { public FireballWatcher(Disguise disguise) { super(disguise); - setData(MetaIndex.FIREBALL_ITEM, new ItemStack(Material.FIRE_CHARGE)); + if (NmsVersion.v1_14.isSupported()) { + setData(MetaIndex.FIREBALL_ITEM, new ItemStack(Material.FIRE_CHARGE)); + } } + @NmsAddedIn(val = NmsVersion.v1_14) public ItemStack getItemStack() { return getData(MetaIndex.FIREBALL_ITEM); } + @NmsAddedIn(val = NmsVersion.v1_14) public void setItemStack(ItemStack item) { setData(MetaIndex.FIREBALL_ITEM, item); sendData(MetaIndex.FIREBALL_ITEM); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java index 671ded22..6d0ca486 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java @@ -1,12 +1,13 @@ package me.libraryaddict.disguise.disguisetypes.watchers; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.disguisetypes.FlagWatcher; - import java.util.OptionalInt; public class FireworkWatcher extends FlagWatcher { @@ -22,15 +23,6 @@ public class FireworkWatcher extends FlagWatcher { return getData(MetaIndex.FIREWORK_ITEM); } - public boolean isShotAtAngle() { - return getData(MetaIndex.FIREWORK_SHOT_AT_ANGLE); - } - - public void setShotAtAngle(boolean shotAtAngle) { - setData(MetaIndex.FIREWORK_SHOT_AT_ANGLE, shotAtAngle); - sendData(MetaIndex.FIREWORK_SHOT_AT_ANGLE); - } - public void setFirework(ItemStack newItem) { if (newItem == null) { newItem = new ItemStack(Material.AIR); @@ -43,12 +35,38 @@ public class FireworkWatcher extends FlagWatcher { sendData(MetaIndex.FIREWORK_ITEM); } - public void setAttachedEntity(OptionalInt entityId) { - setData(MetaIndex.FIREWORK_ATTACHED_ENTITY, entityId); - sendData(MetaIndex.FIREWORK_ATTACHED_ENTITY); + @NmsAddedIn(val = NmsVersion.v1_14) + public boolean isShotAtAngle() { + return getData(MetaIndex.FIREWORK_SHOT_AT_ANGLE); } - public OptionalInt getAttachedEntity() { + @NmsAddedIn(val = NmsVersion.v1_14) + public void setShotAtAngle(boolean shotAtAngle) { + setData(MetaIndex.FIREWORK_SHOT_AT_ANGLE, shotAtAngle); + sendData(MetaIndex.FIREWORK_SHOT_AT_ANGLE); + } + + @NmsAddedIn(val = NmsVersion.v1_14) + public OptionalInt getAttachedEntityOpt() { return getData(MetaIndex.FIREWORK_ATTACHED_ENTITY); } + + public int getAttachedEntity() { + return getData(MetaIndex.FIREWORK_ATTACHED_ENTITY).orElse(0); + } + + public void setAttachedEntity(int entityId) { + setAttachedEntity(entityId == 0 ? OptionalInt.empty() : OptionalInt.of(entityId)); + } + + @NmsAddedIn(val = NmsVersion.v1_14) + public void setAttachedEntity(OptionalInt entityId) { + if (NmsVersion.v1_14.isSupported()) { + setData(MetaIndex.FIREWORK_ATTACHED_ENTITY, entityId); + sendData(MetaIndex.FIREWORK_ATTACHED_ENTITY); + } else { + setData(MetaIndex.FIREWORK_ATTACHED_ENTITY_OLD, entityId.orElse(0)); + sendData(MetaIndex.FIREWORK_ATTACHED_ENTITY_OLD); + } + } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FoxWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FoxWatcher.java index a5ef8bed..06a1e01e 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FoxWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FoxWatcher.java @@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Fox; import java.util.Random; @@ -10,6 +12,7 @@ import java.util.Random; /** * Created by libraryaddict on 6/05/2019. */ +@NmsAddedIn(val = NmsVersion.v1_14) public class FoxWatcher extends AgeableWatcher { public FoxWatcher(Disguise disguise) { super(disguise); @@ -21,6 +24,10 @@ public class FoxWatcher extends AgeableWatcher { return getFoxFlag(1); } + public void setSitting(boolean value) { + setFoxFlag(1, value); + } + public boolean isCrouching() { return getFoxFlag(4); } @@ -29,10 +36,6 @@ public class FoxWatcher extends AgeableWatcher { setFoxFlag(4, value); } - public void setSitting(boolean value) { - setFoxFlag(1, value); - } - public boolean isSleeping() { return getFoxFlag(32); } @@ -51,38 +54,38 @@ public class FoxWatcher extends AgeableWatcher { sendData(MetaIndex.FOX_TYPE); } - public void setHeadTilted(boolean value) { - setFoxFlag(8, value); - } - public boolean isHeadTilted() { return getFoxFlag(8); } - public void setSpringing(boolean value) { - setFoxFlag(16, value); + public void setHeadTilted(boolean value) { + setFoxFlag(8, value); } public boolean isSpringing() { return getFoxFlag(16); } - public void setTipToeing(boolean value) { - setFoxFlag(64, value); + public void setSpringing(boolean value) { + setFoxFlag(16, value); } public boolean isTipToeing() { return getFoxFlag(64); } - public void setAngry(boolean value) { - setFoxFlag(128, value); + public void setTipToeing(boolean value) { + setFoxFlag(64, value); } public boolean isAngry() { return getFoxFlag(128); } + public void setAngry(boolean value) { + setFoxFlag(128, value); + } + private boolean getFoxFlag(int value) { return (getData(MetaIndex.FOX_META) & value) != 0; } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java index 3dc00f07..6a0bd25f 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java @@ -4,6 +4,8 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; +import org.bukkit.Material; import org.bukkit.entity.Horse.Color; import org.bukkit.entity.Horse.Style; import org.bukkit.inventory.ItemStack; @@ -20,27 +22,46 @@ public class HorseWatcher extends AbstractHorseWatcher { return Color.values()[(getData(MetaIndex.HORSE_COLOR) & 0xFF)]; } - public Style getStyle() { - return Style.values()[(getData(MetaIndex.HORSE_COLOR) >>> 8)]; - } - @RandomDefaultValue public void setColor(Color color) { setData(MetaIndex.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8); sendData(MetaIndex.HORSE_COLOR); } + public Style getStyle() { + return Style.values()[(getData(MetaIndex.HORSE_COLOR) >>> 8)]; + } + @RandomDefaultValue public void setStyle(Style style) { setData(MetaIndex.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8); sendData(MetaIndex.HORSE_COLOR); } - public void setHorseArmor(ItemStack item) { - getEquipment().setChestplate(item); - } - public ItemStack getHorseArmor() { return getEquipment().getChestplate(); } + + public void setHorseArmor(ItemStack item) { + getEquipment().setChestplate(item); + + if (!NmsVersion.v1_14.isSupported()) { + int value = 0; + + if (item != null) { + Material mat = item.getType(); + + if (mat == Material.IRON_HORSE_ARMOR) { + value = 1; + } else if (mat == Material.GOLDEN_HORSE_ARMOR) { + value = 2; + } else if (mat == Material.DIAMOND_HORSE_ARMOR) { + value = 3; + } + } + + setData(MetaIndex.HORSE_ARMOR, value); + sendData(MetaIndex.HORSE_ARMOR); + } + } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWizardWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWizardWatcher.java index a49579db..70488b02 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWizardWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/IllagerWizardWatcher.java @@ -2,6 +2,9 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Spellcaster; public class IllagerWizardWatcher extends IllagerWatcher { @@ -9,12 +12,27 @@ public class IllagerWizardWatcher extends IllagerWatcher { super(disguise); } + @NmsAddedIn(val = NmsVersion.v1_14) + public Spellcaster.Spell getSpell() { + return Spellcaster.Spell.values()[getData(MetaIndex.ILLAGER_SPELL)]; + } + + @NmsAddedIn(val = NmsVersion.v1_14) public void setSpell(Spellcaster.Spell spell) { setData(MetaIndex.ILLAGER_SPELL, (byte) spell.ordinal()); sendData(MetaIndex.ILLAGER_SPELL); } - public Spellcaster.Spell getSpell() { - return Spellcaster.Spell.values()[getData(MetaIndex.ILLAGER_SPELL)]; + @Deprecated + @NmsRemovedIn(val = NmsVersion.v1_14) + public int getSpellTicks() { + return getData(MetaIndex.ILLAGER_SPELL_TICKS); + } + + @Deprecated + @NmsRemovedIn(val = NmsVersion.v1_14) + public void setSpellTicks(int spellTicks) { + setData(MetaIndex.ILLAGER_SPELL_TICKS, (byte) spellTicks); + sendData(MetaIndex.ILLAGER_SPELL_TICKS); } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java index 6de51820..b040dc99 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java @@ -11,6 +11,8 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.Color; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -38,6 +40,12 @@ public class LivingWatcher extends FlagWatcher { return clone; } + @NmsAddedIn(val = NmsVersion.v1_14) + public BlockPosition getBedPosition() { + return getData(MetaIndex.LIVING_BED_POSITION).orElse(null); + } + + @NmsAddedIn(val = NmsVersion.v1_14) public void setBedPosition(BlockPosition blockPosition) { Optional optional; @@ -51,22 +59,61 @@ public class LivingWatcher extends FlagWatcher { sendData(MetaIndex.LIVING_BED_POSITION); } - public BlockPosition getBedPosition() { - return getData(MetaIndex.LIVING_BED_POSITION).orElse(null); - } - public float getHealth() { return getData(MetaIndex.LIVING_HEALTH); } + public void setHealth(float health) { + setData(MetaIndex.LIVING_HEALTH, health); + sendData(MetaIndex.LIVING_HEALTH); + } + public double getMaxHealth() { return maxHealth; } + public void setMaxHealth(double newHealth) { + this.maxHealth = newHealth; + this.maxHealthSet = true; + + if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) { + PacketContainer packet = new PacketContainer(Server.UPDATE_ATTRIBUTES); + + List attributes = new ArrayList<>(); + + Builder builder; + builder = WrappedAttribute.newBuilder(); + builder.attributeKey("generic.maxHealth"); + builder.baseValue(getMaxHealth()); + builder.packet(packet); + + attributes.add(builder.build()); + + Entity entity = getDisguise().getEntity(); + + packet.getIntegers().write(0, entity.getEntityId()); + packet.getAttributeCollectionModifier().write(0, attributes); + + for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); + } + catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + } + } + public boolean isPotionParticlesAmbient() { return getData(MetaIndex.LIVING_POTION_AMBIENT); } + public void setPotionParticlesAmbient(boolean particles) { + setData(MetaIndex.LIVING_POTION_AMBIENT, particles); + sendData(MetaIndex.LIVING_POTION_AMBIENT); + } + public Color getParticlesColor() { int color = getData(MetaIndex.LIVING_POTIONS); return Color.fromRGB(color); @@ -151,21 +198,11 @@ public class LivingWatcher extends FlagWatcher { sendPotionEffects(); } - public void setPotionParticlesAmbient(boolean particles) { - setData(MetaIndex.LIVING_POTION_AMBIENT, particles); - sendData(MetaIndex.LIVING_POTION_AMBIENT); - } - private void sendPotionEffects() { setData(MetaIndex.LIVING_POTIONS, getPotions()); sendData(MetaIndex.LIVING_POTIONS); } - public void setHealth(float health) { - setData(MetaIndex.LIVING_HEALTH, health); - sendData(MetaIndex.LIVING_HEALTH); - } - public int getArrowsSticking() { return getData(MetaIndex.LIVING_ARROWS); } @@ -174,37 +211,4 @@ public class LivingWatcher extends FlagWatcher { setData(MetaIndex.LIVING_ARROWS, Math.max(0, Math.min(127, arrowsNo))); sendData(MetaIndex.LIVING_ARROWS); } - - public void setMaxHealth(double newHealth) { - this.maxHealth = newHealth; - this.maxHealthSet = true; - - if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) { - PacketContainer packet = new PacketContainer(Server.UPDATE_ATTRIBUTES); - - List attributes = new ArrayList<>(); - - Builder builder; - builder = WrappedAttribute.newBuilder(); - builder.attributeKey("generic.maxHealth"); - builder.baseValue(getMaxHealth()); - builder.packet(packet); - - attributes.add(builder.build()); - - Entity entity = getDisguise().getEntity(); - - packet.getIntegers().write(0, entity.getEntityId()); - packet.getAttributeCollectionModifier().write(0, attributes); - - for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); - } - catch (InvocationTargetException e) { - e.printStackTrace(); - } - } - } - } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MushroomCowWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MushroomCowWatcher.java index 8ddcaf57..9e3690ea 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MushroomCowWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MushroomCowWatcher.java @@ -2,6 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.MushroomCow; /** @@ -12,10 +14,12 @@ public class MushroomCowWatcher extends AgeableWatcher { super(disguise); } + @NmsAddedIn(val = NmsVersion.v1_14) public MushroomCow.Variant getVariant() { return MushroomCow.Variant.valueOf(getData(MetaIndex.MUSHROOM_COW_TYPE).toUpperCase()); } + @NmsAddedIn(val = NmsVersion.v1_14) public void setVariant(MushroomCow.Variant variant) { setData(MetaIndex.MUSHROOM_COW_TYPE, variant.name().toLowerCase()); sendData(MetaIndex.MUSHROOM_COW_TYPE); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java index 2ccd72e5..9cd7ac9b 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java @@ -1,10 +1,11 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import org.bukkit.entity.Ocelot; -import org.bukkit.entity.Ocelot.Type; - import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; +import org.bukkit.entity.Ocelot; public class OcelotWatcher extends AgeableWatcher { @@ -12,12 +13,27 @@ public class OcelotWatcher extends AgeableWatcher { super(disguise); } + @NmsAddedIn(val = NmsVersion.v1_14) public boolean isTrusting() { return getData(MetaIndex.OCELOT_TRUST); } + @NmsAddedIn(val = NmsVersion.v1_14) public void setTrusting(boolean trusting) { setData(MetaIndex.OCELOT_TRUST, trusting); sendData(MetaIndex.OCELOT_TRUST); } + + @NmsRemovedIn(val = NmsVersion.v1_14) + @Deprecated + public Ocelot.Type getType() { + return Ocelot.Type.getType(getData(MetaIndex.OCELOT_TYPE)); + } + + @NmsRemovedIn(val = NmsVersion.v1_14) + @Deprecated + public void setType(Ocelot.Type newType) { + setData(MetaIndex.OCELOT_TYPE, newType.getId()); + sendData(MetaIndex.OCELOT_TYPE); + } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PandaWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PandaWatcher.java index 404177ef..b19debe3 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PandaWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PandaWatcher.java @@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Panda; import java.util.Random; @@ -10,6 +12,7 @@ import java.util.Random; /** * Created by libraryaddict on 6/05/2019. */ +@NmsAddedIn(val = NmsVersion.v1_14) public class PandaWatcher extends AgeableWatcher { public PandaWatcher(Disguise disguise) { super(disguise); @@ -32,6 +35,12 @@ public class PandaWatcher extends AgeableWatcher { return Panda.Gene.NORMAL; } + @RandomDefaultValue + public void setMainGene(Panda.Gene gene) { + setData(MetaIndex.PANDA_MAIN_GENE, (byte) gene.ordinal()); + sendData(MetaIndex.PANDA_MAIN_GENE); + } + public Panda.Gene getHiddenGene() { int id = getData(MetaIndex.PANDA_HIDDEN_GENE); @@ -46,59 +55,53 @@ public class PandaWatcher extends AgeableWatcher { return Panda.Gene.NORMAL; } - @RandomDefaultValue - public void setMainGene(Panda.Gene gene) { - setData(MetaIndex.PANDA_MAIN_GENE, (byte) gene.ordinal()); - sendData(MetaIndex.PANDA_MAIN_GENE); - } - @RandomDefaultValue public void setHiddenGene(Panda.Gene gene) { setData(MetaIndex.PANDA_HIDDEN_GENE, (byte) gene.ordinal()); sendData(MetaIndex.PANDA_HIDDEN_GENE); } - public void setSneeze(boolean value) { - setPandaFlag(2, value); - } - public boolean isSneeze() { return getPandaFlag(2); } - public void setTumble(boolean value) { - setPandaFlag(4, value); + public void setSneeze(boolean value) { + setPandaFlag(2, value); } public boolean isTumble() { return getPandaFlag(4); } - public void setSitting(boolean value) { - setPandaFlag(8, value); + public void setTumble(boolean value) { + setPandaFlag(4, value); } public boolean isSitting() { return getPandaFlag(8); } - public void setUpsideDown(boolean value) { - setPandaFlag(16, value); + public void setSitting(boolean value) { + setPandaFlag(8, value); } public boolean isUpsideDown() { return getPandaFlag(16); } - public void setHeadShaking(int timeInTicks) { - setData(MetaIndex.PANDA_HEAD_SHAKING, timeInTicks); - sendData(MetaIndex.PANDA_HEAD_SHAKING); + public void setUpsideDown(boolean value) { + setPandaFlag(16, value); } public int getHeadShaking() { return getHeadShakingTicks(); } + public void setHeadShaking(int timeInTicks) { + setData(MetaIndex.PANDA_HEAD_SHAKING, timeInTicks); + sendData(MetaIndex.PANDA_HEAD_SHAKING); + } + @Deprecated public int getHeadShakingTicks() { return getData(MetaIndex.PANDA_HEAD_SHAKING); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PillagerWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PillagerWatcher.java index 39578a7a..066c54c1 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PillagerWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PillagerWatcher.java @@ -2,21 +2,24 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** * Created by libraryaddict on 6/05/2019. */ +@NmsAddedIn(val = NmsVersion.v1_14) public class PillagerWatcher extends IllagerWatcher { public PillagerWatcher(Disguise disguise) { super(disguise); } + public boolean isAimingBow() { + return getData(MetaIndex.PILLAGER_AIMING_BOW); + } + public void setAimingBow(boolean value) { setData(MetaIndex.PILLAGER_AIMING_BOW, value); sendData(MetaIndex.PILLAGER_AIMING_BOW); } - - public boolean isAimingBow() { - return getData(MetaIndex.PILLAGER_AIMING_BOW); - } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/RavagerWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/RavagerWatcher.java index d453fbe9..9d7b03ae 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/RavagerWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/RavagerWatcher.java @@ -1,10 +1,13 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** * Created by libraryaddict on 6/05/2019. */ +@NmsAddedIn(val = NmsVersion.v1_14) public class RavagerWatcher extends RaiderWatcher { public RavagerWatcher(Disguise disguise) { super(disguise); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java index e3ee938f..1223ed0c 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java @@ -2,6 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** * @author Navid @@ -10,4 +12,17 @@ public class SkeletonWatcher extends InsentientWatcher { public SkeletonWatcher(Disguise disguise) { super(disguise); } + + @Deprecated + @NmsRemovedIn(val = NmsVersion.v1_14) + public boolean isSwingArms() { + return getData(MetaIndex.SKELETON_SWING_ARMS); + } + + @Deprecated + @NmsRemovedIn(val = NmsVersion.v1_14) + public void setSwingArms(boolean swingingArms) { + setData(MetaIndex.SKELETON_SWING_ARMS, swingingArms); + sendData(MetaIndex.SKELETON_SWING_ARMS); + } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ThrowableWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ThrowableWatcher.java index bc593fd3..287292f1 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ThrowableWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ThrowableWatcher.java @@ -4,6 +4,8 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.inventory.ItemStack; /** @@ -13,16 +15,20 @@ public abstract class ThrowableWatcher extends FlagWatcher { public ThrowableWatcher(Disguise disguise) { super(disguise); - setItemStack(getDefaultItemStack()); + if (NmsVersion.v1_14.isSupported()) { + setItemStack(getDefaultItemStack()); + } } protected abstract ItemStack getDefaultItemStack(); + @NmsAddedIn(val = NmsVersion.v1_14) public ItemStack getItemStack() { return getData(MetaIndex.THROWABLE_ITEM); } @RandomDefaultValue + @NmsAddedIn(val = NmsVersion.v1_14) public void setItemStack(ItemStack item) { setData(MetaIndex.THROWABLE_ITEM, item); sendData(MetaIndex.THROWABLE_ITEM); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TraderLlamaWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TraderLlamaWatcher.java index d66f668d..e5aca0cb 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TraderLlamaWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TraderLlamaWatcher.java @@ -1,10 +1,13 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** * Created by libraryaddict on 6/05/2019. */ +@NmsAddedIn(val = NmsVersion.v1_14) public class TraderLlamaWatcher extends LlamaWatcher { public TraderLlamaWatcher(Disguise disguise) { super(disguise); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java index 8d233f06..1be1f9bd 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TridentWatcher.java @@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsAdded; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; /** @@ -13,12 +13,12 @@ public class TridentWatcher extends ArrowWatcher { super(disguise); } - @NmsAdded(added = NmsVersion.v1_15) + @NmsAddedIn(val = NmsVersion.v1_15) public boolean isEnchanted() { return getData(MetaIndex.TRIDENT_ENCHANTED); } - @NmsAdded(added = NmsVersion.v1_15) + @NmsAddedIn(val = NmsVersion.v1_15) public void setEnchanted(boolean enchanted) { setData(MetaIndex.TRIDENT_ENCHANTED, enchanted); sendData(MetaIndex.TRIDENT_ENCHANTED); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java index af8bd766..20c1f5b2 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java @@ -5,6 +5,8 @@ import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.VillagerData; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Villager; import org.bukkit.entity.Villager.Profession; @@ -16,46 +18,63 @@ public class VillagerWatcher extends AbstractVillagerWatcher { setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]); } + @NmsAddedIn(val = NmsVersion.v1_14) public VillagerData getVillagerData() { return getData(MetaIndex.VILLAGER_DATA); } + @NmsAddedIn(val = NmsVersion.v1_14) public void setVillagerData(VillagerData villagerData) { setData(MetaIndex.VILLAGER_DATA, villagerData); sendData(MetaIndex.VILLAGER_DATA); } public Profession getProfession() { - return getVillagerData().getProfession(); - } + if (NmsVersion.v1_14.isSupported()) { + return getVillagerData().getProfession(); + } - @Deprecated - public Villager.Type getType() { - return getVillagerData().getType(); - } - - public Villager.Type getBiome() { - return getType(); - } - - public void setBiome(Villager.Type type) { - setType(type); - } - - public int getLevel() { - return getVillagerData().getLevel(); + return Profession.values()[getData(MetaIndex.VILLAGER_PROFESSION) + 1]; } @RandomDefaultValue public void setProfession(Profession profession) { - setVillagerData(new VillagerData(getType(), profession, getLevel())); + if (NmsVersion.v1_14.isSupported()) { + setVillagerData(new VillagerData(getType(), profession, getLevel())); + } else { + setData(MetaIndex.VILLAGER_PROFESSION, profession.ordinal() - 1); + sendData(MetaIndex.VILLAGER_PROFESSION); + } } @Deprecated + @NmsAddedIn(val = NmsVersion.v1_14) + public Villager.Type getType() { + return getVillagerData().getType(); + } + + @Deprecated + @NmsAddedIn(val = NmsVersion.v1_14) public void setType(Villager.Type type) { setVillagerData(new VillagerData(type, getProfession(), getLevel())); } + @NmsAddedIn(val = NmsVersion.v1_14) + public Villager.Type getBiome() { + return getType(); + } + + @NmsAddedIn(val = NmsVersion.v1_14) + public void setBiome(Villager.Type type) { + setType(type); + } + + @NmsAddedIn(val = NmsVersion.v1_14) + public int getLevel() { + return getVillagerData().getLevel(); + } + + @NmsAddedIn(val = NmsVersion.v1_14) public void setLevel(int level) { setVillagerData(new VillagerData(getType(), getProfession(), getLevel())); } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java index 6985be1c..b2bd3162 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VindicatorWatcher.java @@ -2,10 +2,25 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; public class VindicatorWatcher extends IllagerWatcher { public VindicatorWatcher(Disguise disguise) { super(disguise); } + + @Deprecated + @NmsRemovedIn(val = NmsVersion.v1_14) + public boolean isJohnny() { + return getData(MetaIndex.ILLAGER_META) == 1; + } + + @Deprecated + @NmsRemovedIn(val = NmsVersion.v1_14) + public void setJohnny(boolean isJohnny) { + setData(MetaIndex.ILLAGER_META, (byte) (isJohnny ? 1 : 0)); + sendData(MetaIndex.ILLAGER_META); + } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java index af6e3efc..ad63765f 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java @@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; -import me.libraryaddict.disguise.utilities.reflection.NmsRemoved; +import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.DyeColor; @@ -57,7 +57,8 @@ public class WolfWatcher extends TameableWatcher { * * @return */ - @NmsRemoved(removed = NmsVersion.v1_15) + @NmsRemovedIn(val = NmsVersion.v1_15) + @Deprecated public float getDamageTaken() { return getData(MetaIndex.WOLF_DAMAGE); } @@ -67,7 +68,8 @@ public class WolfWatcher extends TameableWatcher { * * @param damage */ - @NmsRemoved(removed = NmsVersion.v1_15) + @Deprecated + @NmsRemovedIn(val = NmsVersion.v1_15) public void setDamageTaken(float damage) { setData(MetaIndex.WOLF_DAMAGE, damage); sendData(MetaIndex.WOLF_DAMAGE); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java index c3a0bead..578ea5f5 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java @@ -4,6 +4,8 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.VillagerData; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; +import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.bukkit.entity.Villager; import org.bukkit.entity.Villager.Profession; @@ -21,24 +23,30 @@ public class ZombieVillagerWatcher extends ZombieWatcher { return getData(MetaIndex.ZOMBIE_VILLAGER_SHAKING); } + public void setShaking(boolean shaking) { + setData(MetaIndex.ZOMBIE_VILLAGER_SHAKING, shaking); + sendData(MetaIndex.ZOMBIE_VILLAGER_SHAKING); + } + /** * Is this zombie a villager? * * @return */ public boolean isVillager() { - return getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION).getProfession() != Profession.NONE; - } - - public void setShaking(boolean shaking) { - setData(MetaIndex.ZOMBIE_VILLAGER_SHAKING, shaking); - sendData(MetaIndex.ZOMBIE_VILLAGER_SHAKING); + if (NmsVersion.v1_14.isSupported()) { + return getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION).getProfession() != Profession.NONE; + } else { + return getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION_OLD) != 0; + } } + @NmsAddedIn(val = NmsVersion.v1_14) public VillagerData getVillagerData() { return getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION); } + @NmsAddedIn(val = NmsVersion.v1_14) public void setVillagerData(VillagerData villagerData) { setData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION, villagerData); sendData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION); @@ -48,33 +56,44 @@ public class ZombieVillagerWatcher extends ZombieWatcher { return getVillagerData().getProfession(); } + @RandomDefaultValue + public void setProfession(Profession profession) { + if (NmsVersion.v1_14.isSupported()) { + setVillagerData(new VillagerData(getType(), profession, getLevel())); + } else { + setData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION_OLD, profession.ordinal() - 1); + sendData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION_OLD); + } + } + + @NmsAddedIn(val = NmsVersion.v1_14) public Villager.Type getType() { return getVillagerData().getType(); } - public int getLevel() { - return getVillagerData().getLevel(); - } - - @RandomDefaultValue - public void setProfession(Profession profession) { - setVillagerData(new VillagerData(getType(), profession, getLevel())); - } - @Deprecated + @NmsAddedIn(val = NmsVersion.v1_14) public void setType(Villager.Type type) { setVillagerData(new VillagerData(type, getProfession(), getLevel())); } + @NmsAddedIn(val = NmsVersion.v1_14) + public int getLevel() { + return getVillagerData().getLevel(); + } + @Deprecated + @NmsAddedIn(val = NmsVersion.v1_14) public void setLevel(int level) { setVillagerData(new VillagerData(getType(), getProfession(), getLevel())); } + @NmsAddedIn(val = NmsVersion.v1_14) public Villager.Type getBiome() { return getType(); } + @NmsAddedIn(val = NmsVersion.v1_14) public void setBiome(Villager.Type type) { setType(type); } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java index 4434d809..1079c04c 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java @@ -2,6 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; public class ZombieWatcher extends InsentientWatcher { @@ -17,6 +19,11 @@ public class ZombieWatcher extends InsentientWatcher { return getData(MetaIndex.ZOMBIE_BABY); } + public void setBaby(boolean baby) { + setData(MetaIndex.ZOMBIE_BABY, baby); + sendData(MetaIndex.ZOMBIE_BABY); + } + public void setAdult() { setBaby(false); } @@ -25,11 +32,6 @@ public class ZombieWatcher extends InsentientWatcher { setBaby(true); } - public void setBaby(boolean baby) { - setData(MetaIndex.ZOMBIE_BABY, baby); - sendData(MetaIndex.ZOMBIE_BABY); - } - public boolean isConverting() { return getData(MetaIndex.ZOMBIE_CONVERTING_DROWNED); } @@ -38,4 +40,17 @@ public class ZombieWatcher extends InsentientWatcher { setData(MetaIndex.ZOMBIE_CONVERTING_DROWNED, converting); sendData(MetaIndex.ZOMBIE_CONVERTING_DROWNED); } + + @Deprecated + @NmsRemovedIn(val = NmsVersion.v1_14) + public boolean isAggressive() { + return (boolean) getData(MetaIndex.ZOMBIE_AGGRESSIVE); + } + + @Deprecated + @NmsRemovedIn(val = NmsVersion.v1_14) + public void setAggressive(boolean handsup) { + setData(MetaIndex.ZOMBIE_AGGRESSIVE, handsup); + sendData(MetaIndex.ZOMBIE_AGGRESSIVE); + } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 851b0ab9..6aefecd9 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -22,14 +22,10 @@ import me.libraryaddict.disguise.utilities.json.*; import me.libraryaddict.disguise.utilities.mineskin.MineSkinAPI; import me.libraryaddict.disguise.utilities.packets.LibsPackets; import me.libraryaddict.disguise.utilities.packets.PacketsManager; -import me.libraryaddict.disguise.utilities.reflection.DisguiseValues; -import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox; -import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup; -import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; +import me.libraryaddict.disguise.utilities.reflection.*; import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.apache.logging.log4j.util.Strings; import org.bukkit.*; -import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; import org.bukkit.entity.*; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -41,17 +37,16 @@ import org.bukkit.scoreboard.Team.Option; import org.bukkit.scoreboard.Team.OptionStatus; import org.bukkit.util.Vector; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.PrintWriter; +import java.io.*; import java.lang.reflect.*; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; public class DisguiseUtilities { public static class ExtendedName { @@ -111,7 +106,6 @@ public class DisguiseUtilities { private static final HashMap> runnables = new HashMap<>(); @Getter private static HashSet selfDisguised = new HashSet<>(); - private static Thread mainThread; private static HashMap preDisguiseTeam = new HashMap<>(); private static HashMap disguiseTeam = new HashMap<>(); private static File profileCache = new File("plugins/LibsDisguises/GameProfiles"), savedDisguises = new File( @@ -321,7 +315,13 @@ public class DisguiseUtilities { } try { - String cached = FileUtils.readFileToString(disguiseFile, "UTF-8"); + String cached = null; + + try (FileInputStream input = new FileInputStream( + disguiseFile); InputStreamReader inputReader = new InputStreamReader(input, + StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(inputReader)) { + cached = reader.lines().collect(Collectors.joining("\n")); + } if (remove) { removeSavedDisguise(entityUUID); @@ -515,7 +515,7 @@ public class DisguiseUtilities { * Sends entity removal packets, as this disguise was removed */ public static void destroyEntity(TargetedDisguise disguise) { - if (mainThread != Thread.currentThread()) + if (!Bukkit.isPrimaryThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); try { @@ -696,7 +696,7 @@ public class DisguiseUtilities { * @return */ public static List getPerverts(Disguise disguise) { - if (mainThread != Thread.currentThread()) + if (!Bukkit.isPrimaryThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); if (disguise.getEntity() == null) @@ -895,16 +895,6 @@ public class DisguiseUtilities { gson = gsonBuilder.create(); - try { - Field threadField = ReflectionManager.getNmsField("MinecraftServer", "serverThread"); - threadField.setAccessible(true); - - mainThread = (Thread) threadField.get(ReflectionManager.getMinecraftServer()); - } - catch (Exception ex) { - ex.printStackTrace(); - } - if (!profileCache.exists()) profileCache.mkdirs(); @@ -953,7 +943,7 @@ public class DisguiseUtilities { * Resends the entity to this specific player */ public static void refreshTracker(final TargetedDisguise disguise, String player) { - if (mainThread != Thread.currentThread()) + if (!Bukkit.isPrimaryThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); if (disguise.getEntity() == null || !disguise.getEntity().isValid()) @@ -990,10 +980,12 @@ public class DisguiseUtilities { .get(entityTrackerEntry); Method clear = ReflectionManager - .getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer")); + .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", + ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager - .getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer")); + .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer", + ReflectionManager.getNmsClass("EntityPlayer")); trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent // ConcurrentModificationException @@ -1030,7 +1022,7 @@ public class DisguiseUtilities { * A convenience method for me to refresh trackers in other plugins */ public static void refreshTrackers(Entity entity) { - if (mainThread != Thread.currentThread()) + if (!Bukkit.isPrimaryThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); if (entity.isValid()) { @@ -1044,10 +1036,12 @@ public class DisguiseUtilities { .get(entityTrackerEntry); Method clear = ReflectionManager - .getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer")); + .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", + ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager - .getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer")); + .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer", + ReflectionManager.getNmsClass("EntityPlayer")); trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent // ConcurrentModificationException @@ -1081,7 +1075,7 @@ public class DisguiseUtilities { * Resends the entity to all the watching players, which is where the magic begins */ public static void refreshTrackers(final TargetedDisguise disguise) { - if (mainThread != Thread.currentThread()) + if (!Bukkit.isPrimaryThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); if (!disguise.getEntity().isValid()) { @@ -1115,10 +1109,12 @@ public class DisguiseUtilities { .get(entityTrackerEntry); final Method clear = ReflectionManager - .getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer")); + .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", + ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager - .getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer")); + .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer", + ReflectionManager.getNmsClass("EntityPlayer")); trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); @@ -1179,7 +1175,7 @@ public class DisguiseUtilities { } public static void removeSelfDisguise(Player player) { - if (mainThread != Thread.currentThread()) + if (!Bukkit.isPrimaryThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); if (!selfDisguised.contains(player.getUniqueId())) { @@ -1700,7 +1696,7 @@ public class DisguiseUtilities { * Sends the self disguise to the player */ public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) { - if (mainThread != Thread.currentThread()) + if (!Bukkit.isPrimaryThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); try { @@ -1755,7 +1751,8 @@ public class DisguiseUtilities { boolean isMoving = false; try { - Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("q"); + Field field = ReflectionManager.getNmsClass("EntityTrackerEntry") + .getDeclaredField(NmsVersion.v1_14.isSupported() ? "q" : "isMoving"); field.setAccessible(true); isMoving = field.getBoolean(entityTrackerEntry); } @@ -1816,14 +1813,6 @@ public class DisguiseUtilities { Location loc = player.getLocation(); - // If the disguised is sleeping for w/e reason - if (player.isSleeping()) { - /* sendSelfPacket(player, - manager.createPacketConstructor(Server.BED, player, ReflectionManager.getBlockPosition(0, 0, 0)) - .createPacket(player, ReflectionManager - .getBlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));*/ - } - // Resend any active potion effects for (PotionEffect potionEffect : player.getActivePotionEffects()) { Object mobEffect = ReflectionManager.createMobEffect(potionEffect); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java index 195c72b3..38b60f7d 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java @@ -5,14 +5,12 @@ import me.libraryaddict.disguise.utilities.plugin.PluginInformation; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.net.URL; import java.net.URLClassLoader; -import java.util.Date; -import java.util.concurrent.TimeUnit; +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; /** * Created by libraryaddict on 2/06/2017. @@ -265,7 +263,11 @@ public class LibsPremium { YamlConfiguration config = new YamlConfiguration(); try { - config.loadFromString(IOUtils.toString(LibsDisguises.getInstance().getResource("plugin.yml"), "UTF-8")); + try (InputStream stream = LibsDisguises.getInstance().getResource("plugin.yml")) { + config.loadFromString( + new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines() + .collect(Collectors.joining("\n"))); + } // If plugin.yml contains a build-date if (config.contains("build-date")) { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/UpdateChecker.java b/src/main/java/me/libraryaddict/disguise/utilities/UpdateChecker.java index c7c69add..f4c66625 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/UpdateChecker.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/UpdateChecker.java @@ -2,15 +2,16 @@ package me.libraryaddict.disguise.utilities; import com.google.gson.Gson; import lombok.Getter; -import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils; +import java.io.BufferedReader; import java.io.InputStream; -import java.io.OutputStream; +import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.Map; +import java.util.stream.Collectors; public class UpdateChecker { private final String resourceID; @@ -75,7 +76,8 @@ public class UpdateChecker { // Get the input stream, what we receive try (InputStream input = con.getInputStream()) { // Read it to string - String version = IOUtils.toString(input); + String version = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)) + .lines().collect(Collectors.joining("\n")); // If the version is not empty, return it if (!version.isEmpty()) { @@ -149,7 +151,8 @@ public class UpdateChecker { // Get the input stream, what we receive try (InputStream input = con.getInputStream()) { // Read it to string - String json = IOUtils.toString(input); + String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)) + .lines().collect(Collectors.joining("\n")); jsonObject = new Gson().fromJson(json, Map.class); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/mineskin/MineSkinAPI.java b/src/main/java/me/libraryaddict/disguise/utilities/mineskin/MineSkinAPI.java index 29a6e12b..86b9e13c 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/mineskin/MineSkinAPI.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/mineskin/MineSkinAPI.java @@ -3,18 +3,18 @@ package me.libraryaddict.disguise.utilities.mineskin; import com.google.gson.Gson; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.SkinUtils; -import me.libraryaddict.disguise.utilities.parser.DisguiseParseException; import me.libraryaddict.disguise.utilities.translations.LibsMsg; -import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils; import java.io.*; import java.net.HttpURLConnection; import java.net.SocketTimeoutException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; /** * Created by libraryaddict on 28/12/2019. @@ -107,7 +107,8 @@ public class MineSkinAPI { } if (connection.getResponseCode() == 500) { - APIError error = new Gson().fromJson(IOUtils.toString(connection.getErrorStream()), APIError.class); + APIError error = new Gson().fromJson(new BufferedReader(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8)) + .lines().collect(Collectors.joining("\n")), APIError.class); if (error.code == 403) { callback.onError(LibsMsg.SKIN_API_FAIL_CODE, "" + error.code, LibsMsg.SKIN_API_403.get()); @@ -136,7 +137,8 @@ public class MineSkinAPI { // Get the input stream, what we receive try (InputStream input = connection.getInputStream()) { // Read it to string - String response = IOUtils.toString(input); + String response = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)) + .lines().collect(Collectors.joining("\n")); MineSkinResponse skinResponse = new Gson().fromJson(response, MineSkinResponse.class); @@ -188,7 +190,8 @@ public class MineSkinAPI { // Get the input stream, what we receive try (InputStream input = con.getInputStream()) { // Read it to string - String response = IOUtils.toString(input); + String response = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)) + .lines().collect(Collectors.joining("\n")); MineSkinResponse skinResponse = new Gson().fromJson(response, MineSkinResponse.class); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsHandler.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsHandler.java index 0c68c740..c2618b68 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsHandler.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsHandler.java @@ -29,7 +29,6 @@ public class PacketsHandler { packetHandlers.add(new PacketHandlerAnimation()); packetHandlers.add(new PacketHandlerAttributes()); - packetHandlers.add(new PacketHandlerBed()); packetHandlers.add(new PacketHandlerCollect()); packetHandlers.add(new PacketHandlerEntityStatus()); packetHandlers.add(new PacketHandlerEquipment(this)); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerBed.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerBed.java deleted file mode 100644 index a009dd6c..00000000 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerBed.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.libraryaddict.disguise.utilities.packets.packethandlers; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketContainer; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.utilities.packets.IPacketHandler; -import me.libraryaddict.disguise.utilities.packets.LibsPackets; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -/** - * Created by libraryaddict on 3/01/2019. - */ -public class PacketHandlerBed implements IPacketHandler { - @Override - public PacketType[] getHandledPackets() { - return new PacketType[]{}; - } - - @Override - public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, - Entity entity) { - // If the entity is going into a bed, stop everything but players from doing this - if (!disguise.getType().isPlayer()) { - packets.clear(); - } - } -} diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java index 3a37041e..babe5c7f 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java @@ -225,7 +225,7 @@ public class PacketHandlerSpawn implements IPacketHandler { packets.addPacket(spawnPlayer); - if (ReflectionManager.isSupported(NmsVersion.v1_15)) { + if (NmsVersion.v1_15.isSupported()) { PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, newWatcher, true) .createPacket(entityId, newWatcher, true); @@ -314,7 +314,7 @@ public class PacketHandlerSpawn implements IPacketHandler { .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()); - if (ReflectionManager.isSupported(NmsVersion.v1_15)) { + if (NmsVersion.v1_15.isSupported()) { PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(), newWatcher, true).createPacket(disguisedEntity.getEntityId(), newWatcher, true); @@ -348,14 +348,26 @@ public class PacketHandlerSpawn implements IPacketHandler { data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4; } - Object entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType()); + PacketContainer spawnEntity; - Object[] params = new Object[]{disguisedEntity.getEntityId(), disguisedEntity.getUniqueId(), x, y, z, - loc.getPitch(), loc.getYaw(), entityType, data, - ReflectionManager.getVec3D(disguisedEntity.getVelocity())}; + if (NmsVersion.v1_14.isSupported()) { + Object entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType()); + + Object[] params = new Object[]{disguisedEntity.getEntityId(), disguisedEntity.getUniqueId(), x, y, z, + loc.getPitch(), loc.getYaw(), entityType, data, + ReflectionManager.getVec3D(disguisedEntity.getVelocity())}; + + spawnEntity = ProtocolLibrary.getProtocolManager() + .createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, params).createPacket(params); + } else { + int objectId = disguise.getType().getObjectId(); + Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); + + spawnEntity = ProtocolLibrary.getProtocolManager() + .createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data) + .createPacket(nmsEntity, objectId, data); + } - PacketContainer spawnEntity = ProtocolLibrary.getProtocolManager() - .createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, params).createPacket(params); packets.addPacket(spawnEntity); // If it's not the same type, then highly likely they have different velocity settings which we'd want to diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java index 6a9f4ee0..e7dca9d0 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java @@ -78,26 +78,18 @@ public class DisguiseParser { getName = "get" + getName; } - Method getMethod = null; - - for (Method m : setMethod.getDeclaringClass().getDeclaredMethods()) { - if (!m.getName().equals(getName)) { - continue; - } - - if (m.getParameterTypes().length > 0 || m.getReturnType() != setMethod.getParameterTypes()[0]) { - continue; - } - - getMethod = m; - break; - } + Method getMethod = setMethod.getDeclaringClass().getMethod(getName); if (getMethod == null) { DisguiseUtilities.getLogger().severe(String .format("No such method '%s' when looking for the companion of '%s' in '%s'", getName, setMethod.getName(), setMethod.getDeclaringClass().getSimpleName())); continue; + }else if (getMethod.getReturnType() != setMethod.getParameterTypes()[0]){ + DisguiseUtilities.getLogger().severe(String + .format("Invalid return type of '%s' when looking for the companion of '%s' in '%s'", getName, + setMethod.getName(), setMethod.getDeclaringClass().getSimpleName())); + continue; } Object defaultValue = null; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoManager.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoManager.java index 2c475dc9..3c780295 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoManager.java @@ -9,6 +9,8 @@ import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import me.libraryaddict.disguise.utilities.parser.params.ParamInfoTypes; +import me.libraryaddict.disguise.utilities.reflection.DisguiseMethods; +import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.bukkit.ChatColor; @@ -21,6 +23,7 @@ import java.util.List; public class ParamInfoManager { private static List paramList; + private static DisguiseMethods disguiseMethods; public static List getParamInfos() { return paramList; @@ -61,12 +64,6 @@ public class ParamInfoManager { if (!method.getName().toLowerCase().equals(methodName.toLowerCase())) continue; - if (method.getParameterTypes().length != 1) - continue; - - if (method.getAnnotation(Deprecated.class) != null) - continue; - return getParamInfo(method.getParameterTypes()[0]); } @@ -75,6 +72,7 @@ public class ParamInfoManager { static { paramList = new ParamInfoTypes().getParamInfos(); + disguiseMethods = new DisguiseMethods(); //paramList.sort((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName())); } @@ -84,7 +82,7 @@ public class ParamInfoManager { return new Method[0]; } - ArrayList methods = new ArrayList<>(Arrays.asList(watcherClass.getMethods())); + ArrayList methods = new ArrayList<>(disguiseMethods.getMethods(watcherClass)); Iterator itel = methods.iterator(); @@ -93,20 +91,8 @@ public class ParamInfoManager { if (!ReflectionManager.isSupported(method)) { itel.remove(); - } else if (method.getParameterTypes().length != 1) { - itel.remove(); - } else if (method.getName().startsWith("get")) { - itel.remove(); - } else if (method.isAnnotationPresent(Deprecated.class)) { - itel.remove(); } else if (getParamInfo(method.getParameterTypes()[0]) == null) { itel.remove(); - } else if (!method.getReturnType().equals(Void.TYPE)) { - itel.remove(); - } else if (method.getName().equals("removePotionEffect")) { - itel.remove(); - } else if (!FlagWatcher.class.isAssignableFrom(method.getDeclaringClass())) { - itel.remove(); } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoTypes.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoTypes.java index f4ae5ae7..84f1a082 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoTypes.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/params/ParamInfoTypes.java @@ -9,6 +9,7 @@ import me.libraryaddict.disguise.disguisetypes.RabbitType; import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; import me.libraryaddict.disguise.utilities.parser.params.types.base.*; import me.libraryaddict.disguise.utilities.parser.params.types.custom.*; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import org.apache.commons.lang.StringUtils; import org.bukkit.*; import org.bukkit.block.BlockFace; @@ -41,8 +42,12 @@ public class ParamInfoTypes { paramInfos.add(new ParamInfoEnum(Villager.Profession.class, "Villager Profession", "View all the professions you can set on a Villager and Zombie Villager")); - paramInfos.add(new ParamInfoEnum(Villager.Type.class, "Villager Biome", - "View all the biomes you can set on a Villager and Zombie Villager")); + + if (NmsVersion.v1_14.isSupported()) { + paramInfos.add(new ParamInfoEnum(Villager.Type.class, "Villager Biome", + "View all the biomes you can set on a Villager and Zombie Villager")); + } + paramInfos.add(new ParamInfoEnum(BlockFace.class, "Direction", "Direction (North, East, South, West, Up, Down)", "View the directions usable on player setSleeping and shulker direction", Arrays.copyOf(BlockFace.values(), 6))); @@ -62,12 +67,15 @@ public class ParamInfoTypes { paramInfos.add(new ParamInfoEnum(DyeColor.class, "DyeColor", "Dye colors of many different colors")); paramInfos.add(new ParamInfoEnum(Horse.Style.class, "Horse Style", "Horse style which is the patterns on the horse")); - paramInfos.add(new ParamInfoEnum(EntityPose.class, "EntityPose", "The pose the entity should strike")); - paramInfos.add(new ParamInfoEnum(Cat.Type.class, "Cat Type", "The type of cat")); - paramInfos.add(new ParamInfoEnum(Fox.Type.class, "Fox Type", "The type of fox")); - paramInfos.add(new ParamInfoEnum(Panda.Gene.class, "Panda Gene", "The panda gene type")); - paramInfos.add(new ParamInfoEnum(MushroomCow.Variant.class, "Mushroom Cow Variant", - "The different variants for mushroom cows")); + + if (NmsVersion.v1_14.isSupported()) { + paramInfos.add(new ParamInfoEnum(EntityPose.class, "EntityPose", "The pose the entity should strike")); + paramInfos.add(new ParamInfoEnum(Cat.Type.class, "Cat Type", "The type of cat")); + paramInfos.add(new ParamInfoEnum(Fox.Type.class, "Fox Type", "The type of fox")); + paramInfos.add(new ParamInfoEnum(Panda.Gene.class, "Panda Gene", "The panda gene type")); + paramInfos.add(new ParamInfoEnum(MushroomCow.Variant.class, "Mushroom Cow Variant", + "The different variants for mushroom cows")); + } // Register custom types paramInfos.add(new ParamInfoEulerAngle(EulerAngle.class, "Euler Angle", "Euler Angle (X,Y,Z)", diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassGetter.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassGetter.java index c85365fe..e3820540 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassGetter.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassGetter.java @@ -2,11 +2,14 @@ package me.libraryaddict.disguise.utilities.reflection; import org.bukkit.entity.Entity; +import java.io.File; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.net.MalformedURLException; import java.net.URL; +import java.net.URLClassLoader; import java.net.URLDecoder; import java.security.CodeSource; import java.util.ArrayList; @@ -20,27 +23,36 @@ import java.util.jar.JarFile; // Code for this taken and slightly modified from // https://github.com/ddopson/java-class-enumerator public class ClassGetter { - private class TestPrem { - String user = "%%__USER__%%"; - } - - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.METHOD) - private @interface PremInfo { - String user(); - } - public static ArrayList> getClassesForPackage(String pkgname) { + return getClassesForPackage(Entity.class, pkgname); + } + + public static ArrayList> getClassesForPackage(Class runFrom, String pkgname) { ArrayList> classes = new ArrayList<>(); // String relPath = pkgname.replace('.', '/'); // Get a File object for the package - CodeSource src = Entity.class.getProtectionDomain().getCodeSource(); + CodeSource src = runFrom.getProtectionDomain().getCodeSource(); if (src != null) { URL resource = src.getLocation(); - resource.getPath(); - processJarfile(resource, pkgname, classes); + + if (resource.getPath().endsWith(".jar")) { + processJarfile(resource, pkgname, classes); + } else { + for (File f : new File(resource.getPath() + "/" + pkgname.replace(".", "/")).listFiles()) { + if (!f.getName().endsWith(".class")) { + continue; + } + + try { + classes.add(Class.forName(pkgname + "." + f.getName().replace(".class", ""))); + } + catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + } } return classes; @@ -58,7 +70,6 @@ public class ClassGetter { } } - @PremInfo(user = "%%__USER__%%") private static void processJarfile(URL resource, String pkgname, ArrayList> classes) { try { String relPath = pkgname.replace('.', '/'); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/CompileMethods.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/CompileMethods.java new file mode 100644 index 00000000..8a365a9c --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/CompileMethods.java @@ -0,0 +1,79 @@ +package me.libraryaddict.disguise.utilities.reflection; + +import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.MushroomCowWatcher; +import org.apache.commons.lang.StringUtils; + +import java.io.File; +import java.io.PrintWriter; +import java.lang.reflect.Method; +import java.util.ArrayList; + +/** + * Created by libraryaddict on 13/02/2020. + */ +public class CompileMethods { + public static void main(String[] args) { + ArrayList> classes = ClassGetter + .getClassesForPackage(FlagWatcher.class, "me.libraryaddict.disguise.disguisetypes.watchers"); + classes.add(FlagWatcher.class); + classes.add(MushroomCowWatcher.class); + + ArrayList methods = new ArrayList<>(); + + for (Class c : classes) { + for (Method method : c.getMethods()) { + if (method.getParameterTypes().length != 1) { + continue; + } else if (method.getName().startsWith("get")) { + continue; + } else if (method.isAnnotationPresent(Deprecated.class) && + !method.isAnnotationPresent(NmsRemovedIn.class)) { + continue; + } else if (!method.getReturnType().equals(Void.TYPE)) { + continue; + } else if (method.getName().equals("removePotionEffect")) { + continue; + } else if (!FlagWatcher.class.isAssignableFrom(method.getDeclaringClass())) { + continue; + } + + int added = -1; + int removed = -1; + + if (method.isAnnotationPresent(NmsAddedIn.class)) { + added = method.getAnnotation(NmsAddedIn.class).val().ordinal(); + } else if (method.getDeclaringClass().isAnnotationPresent(NmsAddedIn.class)) { + added = method.getDeclaringClass().getAnnotation(NmsAddedIn.class).val().ordinal(); + } + + if (method.isAnnotationPresent(NmsRemovedIn.class)) { + removed = method.getAnnotation(NmsRemovedIn.class).val().ordinal(); + } else if (method.getDeclaringClass().isAnnotationPresent(NmsRemovedIn.class)) { + removed = method.getDeclaringClass().getAnnotation(NmsRemovedIn.class).val().ordinal(); + } + + Class param = method.getParameterTypes()[0]; + + String s = ((added >= 0 || removed >= 0) ? added + ":" + removed + ":" : "") + + method.getDeclaringClass().getSimpleName() + ":" + method.getName() + ":" + + param.getName(); + + if (methods.contains(s)) { + continue; + } + + methods.add(s); + } + } + + File methodsFile = new File("target/classes/methods.txt"); + + try (PrintWriter writer = new PrintWriter(methodsFile, "UTF-8")) { + writer.write(StringUtils.join(methods, "\n")); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/DisguiseMethods.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/DisguiseMethods.java new file mode 100644 index 00000000..81cfcfcc --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/DisguiseMethods.java @@ -0,0 +1,133 @@ +package me.libraryaddict.disguise.utilities.reflection; + +import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import org.apache.commons.lang.ClassUtils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Array; +import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; + +/** + * Created by libraryaddict on 13/02/2020. + */ +public class DisguiseMethods { + private HashMap, List> watcherMethods = new HashMap<>(); + + public ArrayList getMethods(Class c) { + ArrayList methods = new ArrayList<>(); + + if (watcherMethods.containsKey(c)) { + methods.addAll(watcherMethods.get(c)); + } + + if (c != FlagWatcher.class) { + methods.addAll(getMethods(c.getSuperclass())); + } + + return methods; + } + + public DisguiseMethods() { + try (InputStream stream = LibsDisguises.getInstance().getResource("methods.txt")) { + List lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines() + .collect(Collectors.toList()); + HashMap> classes = new HashMap<>(); + classes.put(FlagWatcher.class.getSimpleName(), FlagWatcher.class); + + for (DisguiseType t : DisguiseType.values()) { + if (t.getWatcherClass() == null) { + continue; + } + + Class c = t.getWatcherClass(); + + while (!classes.containsKey(c.getSimpleName())) { + classes.put(c.getSimpleName(), c); + c = ReflectionManager.getSuperClass(c); + } + } + + for (String line : lines) { + String[] split = line.split(":"); + + if (split.length > 3) { + int added = Integer.parseInt(split[0]); + int removed = Integer.parseInt(split[1]); + + if (added >= 0 && added > ReflectionManager.getVersion().ordinal()) { + continue; + } else if (removed >= 0 && removed <= ReflectionManager.getVersion().ordinal()) { + continue; + } + } + + Class watcher = classes.get(split[split.length - 3]); + + if (watcher == null) { + continue; + } + + String paramName = split[split.length - 1]; + Class param; + + if (!paramName.contains(".")) { + param = parseType(paramName); + } else { + param = Class.forName(paramName); + } + + Method method = watcher.getMethod(split[split.length - 2], param); + + watcherMethods.computeIfAbsent(watcher, (a) -> new ArrayList<>()).add(method); + } + } + catch (IOException | ClassNotFoundException | NoSuchMethodException e) { + e.printStackTrace(); + } + } + + /** + * Return the java {@link java.lang.Class} object with the specified class name. + *

+ * This is an "extended" {@link java.lang.Class#forName(java.lang.String) } operation. + *

+ * + It is able to return Class objects for primitive types + * + Classes in name space `java.lang` do not need the fully qualified name + * + It does not throw a checked Exception + * + * @param className The class name, never `null` + * @throws IllegalArgumentException if no class can be loaded + */ + private Class parseType(final String className) { + switch (className) { + case "boolean": + return boolean.class; + case "byte": + return byte.class; + case "short": + return short.class; + case "int": + return int.class; + case "long": + return long.class; + case "float": + return float.class; + case "double": + return double.class; + case "char": + return char.class; + case "[I": + return int[].class; + default: + throw new IllegalArgumentException("Class not found: " + className); + } + } +} diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsAdded.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsAddedIn.java similarity index 81% rename from src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsAdded.java rename to src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsAddedIn.java index a5c7d2aa..bfcbb42d 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsAdded.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsAddedIn.java @@ -7,6 +7,6 @@ import java.lang.annotation.RetentionPolicy; * Created by libraryaddict on 6/02/2020. */ @Retention(RetentionPolicy.RUNTIME) -public @interface NmsAdded { - NmsVersion added(); +public @interface NmsAddedIn { + NmsVersion val(); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsRemoved.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsRemovedIn.java similarity index 80% rename from src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsRemoved.java rename to src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsRemovedIn.java index 189c02a5..6cf3e31a 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsRemoved.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsRemovedIn.java @@ -7,6 +7,6 @@ import java.lang.annotation.RetentionPolicy; * Created by libraryaddict on 6/02/2020. */ @Retention(RetentionPolicy.RUNTIME) -public @interface NmsRemoved { - NmsVersion removed(); +public @interface NmsRemovedIn { + NmsVersion val(); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java index 258e8757..f7fadc05 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java @@ -4,6 +4,14 @@ package me.libraryaddict.disguise.utilities.reflection; * Created by libraryaddict on 6/02/2020. */ public enum NmsVersion { + v1_13, v1_14, - v1_15 + v1_15; + + /** + * If this nms version isn't newer than the running version + */ + public boolean isSupported() { + return ReflectionManager.getVersion().ordinal() >= ordinal(); + } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index 17b79a7a..de77837b 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -18,7 +18,7 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.*; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils; +import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap; import org.bukkit.entity.*; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -26,15 +26,19 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.util.Vector; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.lang.reflect.*; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Map; import java.util.Optional; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; public class ReflectionManager { private static String bukkitVersion; @@ -43,18 +47,20 @@ public class ReflectionManager { private static Constructor boundingBoxConstructor; private static Method setBoundingBoxMethod; private static Field pingField; - public static Field entityCountField; + private static Field entityCountField; private static Field chunkMapField; private static Field chunkProviderField; private static Field entityTrackerField; private static Field trackedEntitiesField; + @NmsRemovedIn(val = NmsVersion.v1_14) + private static Method ihmGet; + @NmsRemovedIn(val = NmsVersion.v1_14) + private static Field trackerField; + @NmsRemovedIn(val = NmsVersion.v1_14) + private static Field entitiesField; @Getter private static NmsVersion version; - public static boolean isSupported(NmsVersion version) { - return getVersion().ordinal() >= version.ordinal(); - } - public static void init() { try { Object entity = createEntityInstance(DisguiseType.COW, "Cow"); @@ -88,10 +94,16 @@ public class ReflectionManager { pingField = getNmsField("EntityPlayer", "ping"); - chunkProviderField = getNmsField("World", "chunkProvider"); - chunkMapField = getNmsField("ChunkProviderServer", "playerChunkMap"); - trackedEntitiesField = getNmsField("PlayerChunkMap", "trackedEntities"); - entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", "trackerEntry"); + if (NmsVersion.v1_14.isSupported()) { + chunkProviderField = getNmsField("World", "chunkProvider"); + chunkMapField = getNmsField("ChunkProviderServer", "playerChunkMap"); + trackedEntitiesField = getNmsField("PlayerChunkMap", "trackedEntities"); + entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", "trackerEntry"); + } else { + trackerField = getNmsField("WorldServer", "tracker"); + entitiesField = getNmsField("EntityTracker", "trackedEntities"); + ihmGet = getNmsMethod("IntHashMap", "get", int.class); + } boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class, double.class, double.class); @@ -104,19 +116,19 @@ public class ReflectionManager { } public static boolean isSupported(AccessibleObject obj) { - if (obj.isAnnotationPresent(NmsAdded.class)) { - NmsAdded added = obj.getAnnotation(NmsAdded.class); + if (obj.isAnnotationPresent(NmsAddedIn.class)) { + NmsAddedIn added = obj.getAnnotation(NmsAddedIn.class); - // If it was added after/on this version - if (!isSupported(added.added())) { + // If it was added after this version + if (!added.val().isSupported()) { return false; } } - if (obj.isAnnotationPresent(NmsRemoved.class)) { - NmsRemoved removed = obj.getAnnotation(NmsRemoved.class); + if (obj.isAnnotationPresent(NmsRemovedIn.class)) { + NmsRemovedIn removed = obj.getAnnotation(NmsRemovedIn.class); - if (isSupported(removed.removed())) { + if (removed.val().isSupported()) { return false; } } @@ -152,7 +164,8 @@ public class ReflectionManager { public static YamlConfiguration getPluginYaml(ClassLoader loader) { try (InputStream stream = loader.getResourceAsStream("plugin.yml")) { YamlConfiguration config = new YamlConfiguration(); - config.loadFromString(IOUtils.toString(stream, "UTF-8")); + config.loadFromString(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines() + .collect(Collectors.joining("\n"))); return config; } @@ -169,17 +182,21 @@ public class ReflectionManager { public static int getNewEntityId(boolean increment) { try { - AtomicInteger entityCount = (AtomicInteger) entityCountField.get(null); - - int id; + Number entityCount = (Number) entityCountField.get(null); if (increment) { - id = entityCount.getAndIncrement(); - } else { - id = entityCount.get(); + if (NmsVersion.v1_14.isSupported()) { + return ((AtomicInteger) entityCount).getAndIncrement(); + } else { + int id = entityCount.intValue(); + + entityCountField.set(null, id + 1); + + return id; + } } - return id; + return entityCount.intValue(); } catch (IllegalAccessException e) { e.printStackTrace(); @@ -194,34 +211,44 @@ public class ReflectionManager { Object entityObject; Object world = getWorldServer(Bukkit.getWorlds().get(0)); - switch (entityName) { - case "Player": - Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null); + if (entityName.equals("Player")) { + Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null); - Object playerinteractmanager = getNmsClass("PlayerInteractManager") - .getDeclaredConstructor(getNmsClass("WorldServer")).newInstance(world); + Object playerinteractmanager = getNmsClass("PlayerInteractManager") + .getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World")) + .newInstance(world); - WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve"); + WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve"); - entityObject = entityClass - .getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), - gameProfile.getHandleType(), playerinteractmanager.getClass()) - .newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager); - break; - case "EnderPearl": - entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving")) - .newInstance(world, createEntityInstance(DisguiseType.COW, "Cow")); - break; - case "FishingHook": + entityObject = entityClass + .getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), + gameProfile.getHandleType(), playerinteractmanager.getClass()) + .newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager); + } else if (entityName.equals("EnderPearl")) { + entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving")) + .newInstance(world, createEntityInstance(DisguiseType.COW, "Cow")); + } else if (entityName.equals("FishingHook")) { + if (NmsVersion.v1_14.isSupported()) { entityObject = entityClass .getDeclaredConstructor(getNmsClass("EntityHuman"), getNmsClass("World"), int.class, int.class) .newInstance(createEntityInstance(DisguiseType.PLAYER, "Player"), world, 0, 0); - break; - default: + } else { + entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityHuman")) + .newInstance(world, createEntityInstance(DisguiseType.PLAYER, "Player")); + } + } else if (!NmsVersion.v1_14.isSupported() && entityName.equals("Potion")) { + entityObject = entityClass + .getDeclaredConstructor(getNmsClass("World"), Double.TYPE, Double.TYPE, Double.TYPE, + getNmsClass("ItemStack")) + .newInstance(world, 0d, 0d, 0d, getNmsItem(new ItemStack(Material.SPLASH_POTION))); + } else { + if (NmsVersion.v1_14.isSupported()) { entityObject = entityClass.getDeclaredConstructor(getNmsClass("EntityTypes"), getNmsClass("World")) .newInstance(getEntityType(disguiseType.getEntityType()), world); - break; + } else { + entityObject = entityClass.getDeclaredConstructor(getNmsClass("World")).newInstance(world); + } } return entityObject; @@ -395,17 +422,25 @@ public class ReflectionManager { public static Object getEntityTrackerEntry(Entity target) throws Exception { Object world = getWorldServer(target.getWorld()); - Object chunkProvider = chunkProviderField.get(world); - Object chunkMap = chunkMapField.get(chunkProvider); - Map trackedEntities = (Map) trackedEntitiesField.get(chunkMap); - Object entityTracker = trackedEntities.get(target.getEntityId()); + if (NmsVersion.v1_14.isSupported()) { + Object chunkProvider = chunkProviderField.get(world); + Object chunkMap = chunkMapField.get(chunkProvider); + Map trackedEntities = (Map) trackedEntitiesField.get(chunkMap); - if (entityTracker == null) { - return null; + Object entityTracker = trackedEntities.get(target.getEntityId()); + + if (entityTracker == null) { + return null; + } + + return entityTrackerField.get(entityTracker); } - return entityTrackerField.get(entityTracker); + Object tracker = trackerField.get(world); + Object trackedEntities = entitiesField.get(tracker); + + return ihmGet.invoke(trackedEntities, target.getEntityId()); } public static Object getMinecraftServer() { @@ -675,13 +710,21 @@ public class ReflectionManager { public static float[] getSize(Entity entity) { try { - Object size = getNmsField("Entity", "size").get(getNmsEntity(entity)); + if (NmsVersion.v1_14.isSupported()) { + Object size = getNmsField("Entity", "size").get(getNmsEntity(entity)); - //float length = getNmsField("EntitySize", "length").getFloat(size); - float width = getNmsField("EntitySize", "width").getFloat(size); - float height = getNmsField("Entity", "headHeight").getFloat(getNmsEntity(entity)); + //float length = getNmsField("EntitySize", "length").getFloat(size); + float width = getNmsField("EntitySize", "width").getFloat(size); + float height = getNmsField("Entity", "headHeight").getFloat(getNmsEntity(entity)); - return new float[]{width, height}; + return new float[]{width, height}; + } else { + + // float length = getNmsField("Entity", "length").getFloat(getNmsEntity(entity)); + float width = getNmsField("Entity", "width").getFloat(getNmsEntity(entity)); + float height = (Float) getNmsMethod("Entity", "getHeadHeight").invoke(getNmsEntity(entity)); + return new float[]{width, height}; + } } catch (Exception ex) { ex.printStackTrace(); @@ -1045,6 +1088,30 @@ public class ReflectionManager { return null; } + public static boolean isAssignableFrom(Class toCheck, Class checkAgainst) { + if (!NmsVersion.v1_14.isSupported() && toCheck != checkAgainst) { + if (toCheck == OcelotWatcher.class) { + toCheck = TameableWatcher.class; + } + } + + return checkAgainst.isAssignableFrom(toCheck); + } + + public static Class getSuperClass(Class cl) { + if (cl == FlagWatcher.class) { + return null; + } + + if (!NmsVersion.v1_14.isSupported()) { + if (cl == OcelotWatcher.class) { + return TameableWatcher.class; + } + } + + return cl.getSuperclass(); + } + public static Object getVillagerProfession(Villager.Profession profession) { try { Object villagerProfession = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null); @@ -1124,10 +1191,14 @@ public class ReflectionManager { public static Object getEntityType(EntityType entityType) { try { Method entityTypes = getNmsMethod("EntityTypes", "a", String.class); + Object val = entityTypes.invoke(null, + entityType.getName() == null ? entityType.name().toLowerCase() : entityType.getName()); - Optional entityObj = (Optional) entityTypes.invoke(null, entityType.getName()); + if (NmsVersion.v1_14.isSupported()) { + return ((Optional) val).orElse(null); + } - return entityObj.orElse(null); + return val; } catch (Exception e) { e.printStackTrace(); @@ -1513,6 +1584,7 @@ public class ReflectionManager { DisguiseUtilities.getLogger() .severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " + disguiseType.getWatcherClass().getSimpleName()); + continue; }