Change 1.17 to use the nms stuff too
This commit is contained in:
		| @@ -185,6 +185,14 @@ | |||||||
|             <scope>compile</scope> |             <scope>compile</scope> | ||||||
|             <optional>true</optional> |             <optional>true</optional> | ||||||
|         </dependency> |         </dependency> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>LibsDisguises</groupId> | ||||||
|  |             <artifactId>v1_17_R1</artifactId> | ||||||
|  |             <version>${project.version}</version> | ||||||
|  |             <classifier>remapped-spigot</classifier> | ||||||
|  |             <scope>compile</scope> | ||||||
|  |             <optional>true</optional> | ||||||
|  |         </dependency> | ||||||
|     </dependencies> |     </dependencies> | ||||||
|  |  | ||||||
| </project> | </project> | ||||||
| @@ -111,8 +111,7 @@ public class ReflectionManager { | |||||||
|     private static Field playerConnection; |     private static Field playerConnection; | ||||||
|     private static Method incrementedInventoryStateId; |     private static Method incrementedInventoryStateId; | ||||||
|     private static Field playerInventoryContainer; |     private static Field playerInventoryContainer; | ||||||
|  |     private static ReflectionManagerAbstract nmsReflection; | ||||||
|     private static ReflectionManagerAbstract v1_18ReflectionManager = getReflectionManager(NmsVersion.v1_18); |  | ||||||
|  |  | ||||||
|     public static void init() { |     public static void init() { | ||||||
|         try { |         try { | ||||||
| @@ -121,37 +120,17 @@ public class ReflectionManager { | |||||||
|                 entityPoseClass = getNmsClass("EntityPose"); |                 entityPoseClass = getNmsClass("EntityPose"); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (NmsVersion.v1_18.isSupported()) { |             nmsReflection = getReflectionManager(getVersion()); | ||||||
|                 v1_18ReflectionManager = getReflectionManager(NmsVersion.v1_18); |  | ||||||
|  |             if (nmsReflection != null) { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class, double.class, double.class); |             boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class, double.class, double.class); | ||||||
|  |  | ||||||
|             setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB")); |             setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB")); | ||||||
|  |  | ||||||
|             if (NmsVersion.v1_17.isSupported()) { |  | ||||||
|                 for (Field f : getNmsClass("Entity").getDeclaredFields()) { |  | ||||||
|                     if (f.getType() != AtomicInteger.class) { |  | ||||||
|                         continue; |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                     f.setAccessible(true); |  | ||||||
|                     entityCountField = f; |  | ||||||
|                     break; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 for (Field f : getNmsClass("EntityHuman").getDeclaredFields()) { |  | ||||||
|                     if (!f.getType().getSimpleName().equals("ContainerPlayer")) { |  | ||||||
|                         continue; |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                     f.setAccessible(true); |  | ||||||
|                     playerInventoryContainer = f; |  | ||||||
|                     break; |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|             entityCountField = getNmsField("Entity", "entityCount"); |             entityCountField = getNmsField("Entity", "entityCount"); | ||||||
|             } |  | ||||||
|  |  | ||||||
|             mobEffectConstructor = getNmsConstructor("MobEffect", getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE); |             mobEffectConstructor = getNmsConstructor("MobEffect", getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE); | ||||||
|             mobEffectList = getNmsMethod("MobEffectList", "fromId", Integer.TYPE); |             mobEffectList = getNmsMethod("MobEffectList", "fromId", Integer.TYPE); | ||||||
| @@ -170,15 +149,9 @@ public class ReflectionManager { | |||||||
|             enumPlayerInfoAction = (Enum[]) getNmsClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction").getEnumConstants(); |             enumPlayerInfoAction = (Enum[]) getNmsClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction").getEnumConstants(); | ||||||
|             chatComponentConstructor = getNmsConstructor("ChatComponentText", String.class); |             chatComponentConstructor = getNmsConstructor("ChatComponentText", String.class); | ||||||
|  |  | ||||||
|             if (NmsVersion.v1_17.isSupported()) { |  | ||||||
|                 packetPlayOutConstructor = |  | ||||||
|                         getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", GameProfile.class, int.class, getNmsClass("EnumGamemode"), |  | ||||||
|                                 getNmsClass("IChatBaseComponent")); |  | ||||||
|             } else { |  | ||||||
|             packetPlayOutConstructor = |             packetPlayOutConstructor = | ||||||
|                     getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", getNmsClass("PacketPlayOutPlayerInfo"), GameProfile.class, int.class, |                     getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", getNmsClass("PacketPlayOutPlayerInfo"), GameProfile.class, int.class, | ||||||
|                             getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent")); |                             getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent")); | ||||||
|             } |  | ||||||
|  |  | ||||||
|             enumGamemode = (Enum[]) getNmsClass("EnumGamemode").getEnumConstants(); |             enumGamemode = (Enum[]) getNmsClass("EnumGamemode").getEnumConstants(); | ||||||
|             getNmsEntityMethod = getCraftMethod("CraftEntity", "getHandle"); |             getNmsEntityMethod = getCraftMethod("CraftEntity", "getHandle"); | ||||||
| @@ -209,16 +182,9 @@ public class ReflectionManager { | |||||||
|                     registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "get", getNmsClass("MinecraftKey")); |                     registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "get", getNmsClass("MinecraftKey")); | ||||||
|                     villagerDataConstructor = getNmsConstructor("VillagerData", getNmsClass("VillagerType"), getNmsClass("VillagerProfession"), int.class); |                     villagerDataConstructor = getNmsConstructor("VillagerData", getNmsClass("VillagerType"), getNmsClass("VillagerProfession"), int.class); | ||||||
|  |  | ||||||
|                     if (NmsVersion.v1_17.isSupported()) { |  | ||||||
|                         villagerProfessionRegistry = getNmsField("IRegistry", "ap").get(null); |  | ||||||
|                         villagerTypeRegistry = getNmsField("IRegistry", "ao").get(null); |  | ||||||
|                         playerConnection = getNmsField("EntityPlayer", "b"); |  | ||||||
|                         connectionEntityMethod = getNmsMethod("PlayerConnection", "d"); |  | ||||||
|                         incrementedInventoryStateId = getNmsMethod("Container", "incrementStateId"); |  | ||||||
|                     } else { |  | ||||||
|                     villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null); |                     villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null); | ||||||
|                     villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null); |                     villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null); | ||||||
|                     } |  | ||||||
|                 } else { |                 } else { | ||||||
|                     registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "getOrDefault", getNmsClass("MinecraftKey")); |                     registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "getOrDefault", getNmsClass("MinecraftKey")); | ||||||
|                 } |                 } | ||||||
| @@ -234,20 +200,7 @@ public class ReflectionManager { | |||||||
|             getNmsWorld = getCraftMethod("CraftWorld", "getHandle"); |             getNmsWorld = getCraftMethod("CraftWorld", "getHandle"); | ||||||
|             deserializedItemMeta = getCraftMethod(getCraftClass("CraftMetaItem$SerializableMeta"), "deserialize", Map.class); |             deserializedItemMeta = getCraftMethod(getCraftClass("CraftMetaItem$SerializableMeta"), "deserialize", Map.class); | ||||||
|  |  | ||||||
|             if (NmsVersion.v1_17.isSupported()) { |  | ||||||
|                 boolean nextInt = false; |  | ||||||
|  |  | ||||||
|                 for (Field f : getNmsClass("Entity").getDeclaredFields()) { |  | ||||||
|                     if (f.getType().getSimpleName().equals("Tag")) { |  | ||||||
|                         nextInt = true; |  | ||||||
|                     } else if (f.getType() == int.class && nextInt) { |  | ||||||
|                         noDamageTicks = f; |  | ||||||
|                         break; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|             noDamageTicks = getNmsField("Entity", "noDamageTicks"); |             noDamageTicks = getNmsField("Entity", "noDamageTicks"); | ||||||
|             } |  | ||||||
|  |  | ||||||
|             isInvul = getNmsMethod("Entity", "isInvulnerable", getNmsClass("DamageSource")); |             isInvul = getNmsMethod("Entity", "isInvulnerable", getNmsClass("DamageSource")); | ||||||
|  |  | ||||||
| @@ -311,15 +264,15 @@ public class ReflectionManager { | |||||||
|             ex.printStackTrace(); |             ex.printStackTrace(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         pingField = getNmsField("EntityPlayer", NmsVersion.v1_17.isSupported() ? "e" : "ping"); |         pingField = getNmsField("EntityPlayer", "ping"); | ||||||
|  |  | ||||||
|         if (NmsVersion.v1_14.isSupported()) { |         if (NmsVersion.v1_14.isSupported()) { | ||||||
|             chunkMapField = getNmsField("ChunkProviderServer", NmsVersion.v1_17.isSupported() ? "a" : "playerChunkMap"); |             chunkMapField = getNmsField("ChunkProviderServer", "playerChunkMap"); | ||||||
|             trackedEntitiesField = getNmsField("PlayerChunkMap", NmsVersion.v1_17.isSupported() ? "G" : "trackedEntities"); |             trackedEntitiesField = getNmsField("PlayerChunkMap", "trackedEntities"); | ||||||
|             entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", NmsVersion.v1_17.isSupported() ? "b" : "trackerEntry"); |             entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", "trackerEntry"); | ||||||
|  |  | ||||||
|             if (NmsVersion.v1_16.isSupported()) { |             if (NmsVersion.v1_16.isSupported()) { | ||||||
|                 chunkProviderField = getNmsField("WorldServer", NmsVersion.v1_17.isSupported() ? "C" : "chunkProvider"); |                 chunkProviderField = getNmsField("WorldServer", "chunkProvider"); | ||||||
|             } else { |             } else { | ||||||
|                 chunkProviderField = getNmsField("World", "chunkProvider"); |                 chunkProviderField = getNmsField("World", "chunkProvider"); | ||||||
|             } |             } | ||||||
| @@ -331,8 +284,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static boolean hasInvul(Entity entity) { |     public static boolean hasInvul(Entity entity) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.hasInvul(entity); |             return nmsReflection.hasInvul(entity); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         Object nmsEntity = ReflectionManager.getNmsEntity(entity); |         Object nmsEntity = ReflectionManager.getNmsEntity(entity); | ||||||
| @@ -351,8 +304,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getIncrementedStateId(Player player) { |     public static int getIncrementedStateId(Player player) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getIncrementedStateId(player); |             return nmsReflection.getIncrementedStateId(player); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -465,8 +418,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getNewEntityId(boolean increment) { |     public static int getNewEntityId(boolean increment) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getNewEntityId(increment); |             return nmsReflection.getNewEntityId(increment); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -493,15 +446,11 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getPlayerConnectionOrPlayer(Player player) { |     public static Object getPlayerConnectionOrPlayer(Player player) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getPlayerConnectionOrPlayer(player); |             return nmsReflection.getPlayerConnectionOrPlayer(player); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|             if (NmsVersion.v1_17.isSupported()) { |  | ||||||
|                 return playerConnection.get(getNmsEntity(player)); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return getNmsEntity(player); |             return getNmsEntity(player); | ||||||
|         } catch (Throwable throwable) { |         } catch (Throwable throwable) { | ||||||
|             throwable.printStackTrace(); |             throwable.printStackTrace(); | ||||||
| @@ -511,22 +460,12 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object createEntityInstance(DisguiseType disguiseType, String entityName) { |     public static Object createEntityInstance(DisguiseType disguiseType, String entityName) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.createEntityInstance(entityName); |             return nmsReflection.createEntityInstance(entityName); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|             Class<?> entityClass; |             Class<?> entityClass = getNmsClass("Entity" + entityName); | ||||||
|  |  | ||||||
|             if (NmsVersion.v1_17.isSupported()) { |  | ||||||
|                 entityClass = getNmsClassIgnoreErrors("Entity" + entityName); |  | ||||||
|  |  | ||||||
|                 if (entityClass == null) { |  | ||||||
|                     entityClass = getNmsClass(entityName); |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|                 entityClass = getNmsClass("Entity" + entityName); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             Object entityObject; |             Object entityObject; | ||||||
|             Object world = getWorldServer(Bukkit.getWorlds().get(0)); |             Object world = getWorldServer(Bukkit.getWorlds().get(0)); | ||||||
| @@ -535,17 +474,13 @@ public class ReflectionManager { | |||||||
|                 Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null); |                 Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null); | ||||||
|                 WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve"); |                 WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve"); | ||||||
|  |  | ||||||
|                 if (NmsVersion.v1_17.isSupported()) { |  | ||||||
|                     entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), gameProfile.getHandleType()) |  | ||||||
|                             .newInstance(minecraftServer, world, gameProfile.getHandle()); |  | ||||||
|                 } else { |  | ||||||
|                 Object playerinteractmanager = |                 Object playerinteractmanager = | ||||||
|                         getNmsClass("PlayerInteractManager").getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World")) |                         getNmsClass("PlayerInteractManager").getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World")) | ||||||
|                                 .newInstance(world); |                                 .newInstance(world); | ||||||
|  |  | ||||||
|                 entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), gameProfile.getHandleType(), |                 entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), gameProfile.getHandleType(), | ||||||
|                         playerinteractmanager.getClass()).newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager); |                         playerinteractmanager.getClass()).newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager); | ||||||
|                 } |  | ||||||
|             } else if (entityName.equals("EnderPearl")) { |             } else if (entityName.equals("EnderPearl")) { | ||||||
|                 entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving")) |                 entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving")) | ||||||
|                         .newInstance(world, createEntityInstance(DisguiseType.COW, "Cow")); |                         .newInstance(world, createEntityInstance(DisguiseType.COW, "Cow")); | ||||||
| @@ -583,8 +518,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getMobEffectList(int id) { |     public static Object getMobEffectList(int id) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getMobEffectList(id); |             return nmsReflection.getMobEffectList(id); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -601,8 +536,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) { |     public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.createMobEffect(id, duration, amplification, ambient, particles); |             return nmsReflection.createMobEffect(id, duration, amplification, ambient, particles); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -615,10 +550,10 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static FakeBoundingBox getBoundingBox(Entity entity) { |     public static FakeBoundingBox getBoundingBox(Entity entity) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             double x = v1_18ReflectionManager.getXBoundingBox(entity); |             double x = nmsReflection.getXBoundingBox(entity); | ||||||
|             double y = v1_18ReflectionManager.getYBoundingBox(entity); |             double y = nmsReflection.getYBoundingBox(entity); | ||||||
|             double z = v1_18ReflectionManager.getZBoundingBox(entity); |             double z = nmsReflection.getZBoundingBox(entity); | ||||||
|             return new FakeBoundingBox(x, y, z); |             return new FakeBoundingBox(x, y, z); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -668,16 +603,11 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getPlayerFromPlayerConnection(Object nmsEntity) { |     public static Object getPlayerFromPlayerConnection(Object nmsEntity) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getPlayerFromPlayerConnection(nmsEntity); |             return nmsReflection.getPlayerFromPlayerConnection(nmsEntity); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|             if (NmsVersion.v1_17.isSupported()) { |  | ||||||
|                 // Convert from player connection to EntityPlayer |  | ||||||
|                 nmsEntity = connectionEntityMethod.invoke(nmsEntity); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return nmsEntity; |             return nmsEntity; | ||||||
|         } catch (Exception ex) { |         } catch (Exception ex) { | ||||||
|             ex.printStackTrace(); |             ex.printStackTrace(); | ||||||
| @@ -687,8 +617,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Entity getBukkitEntity(Object nmsEntity) { |     public static Entity getBukkitEntity(Object nmsEntity) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getBukkitEntity(nmsEntity); |             return nmsReflection.getBukkitEntity(nmsEntity); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -701,8 +631,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static ItemStack getBukkitItem(Object nmsItem) { |     public static ItemStack getBukkitItem(Object nmsItem) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getBukkitItem(nmsItem); |             return nmsReflection.getBukkitItem(nmsItem); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -715,8 +645,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static ItemStack getCraftItem(ItemStack bukkitItem) { |     public static ItemStack getCraftItem(ItemStack bukkitItem) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getCraftItem(bukkitItem); |             return nmsReflection.getCraftItem(bukkitItem); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -767,6 +697,7 @@ public class ReflectionManager { | |||||||
|         try { |         try { | ||||||
|             Class<?> aClass = Class.forName("me.libraryaddict.disguise.utilities.reflection." + nmsVersion.name() + ".ReflectionManager"); |             Class<?> aClass = Class.forName("me.libraryaddict.disguise.utilities.reflection." + nmsVersion.name() + ".ReflectionManager"); | ||||||
|             Object o = aClass.getConstructor().newInstance(); |             Object o = aClass.getConstructor().newInstance(); | ||||||
|  |  | ||||||
|             return (ReflectionManagerAbstract) o; |             return (ReflectionManagerAbstract) o; | ||||||
|         } catch (ReflectiveOperationException e) { |         } catch (ReflectiveOperationException e) { | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
| @@ -792,8 +723,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getCraftSound(Sound sound) { |     public static Object getCraftSound(Sound sound) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getCraftSound(sound); |             return nmsReflection.getCraftSound(sound); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -806,8 +737,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getEntityTrackerEntry(Entity target) throws Exception { |     public static Object getEntityTrackerEntry(Entity target) throws Exception { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getEntityTrackerEntry(target); |             return nmsReflection.getEntityTrackerEntry(target); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         Object world = getWorldServer(target.getWorld()); |         Object world = getWorldServer(target.getWorld()); | ||||||
| @@ -833,8 +764,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getMinecraftServer() { |     public static Object getMinecraftServer() { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getMinecraftServer(); |             return nmsReflection.getMinecraftServer(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -846,8 +777,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static String getEnumArt(Art art) { |     public static String getEnumArt(Art art) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getEnumArt(art); |             return nmsReflection.getEnumArt(art); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -865,8 +796,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getBlockPosition(int x, int y, int z) { |     public static Object getBlockPosition(int x, int y, int z) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getBlockPosition(x, y, z); |             return nmsReflection.getBlockPosition(x, y, z); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -879,8 +810,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Enum getEnumDirection(int direction) { |     public static Enum getEnumDirection(int direction) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getEnumDirection(direction); |             return nmsReflection.getEnumDirection(direction); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -893,8 +824,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Enum getEnumPlayerInfoAction(int action) { |     public static Enum getEnumPlayerInfoAction(int action) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getEnumPlayerInfoAction(action); |             return nmsReflection.getEnumPlayerInfoAction(action); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -907,17 +838,13 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getPlayerInfoData(Object playerInfoPacket, WrappedGameProfile gameProfile) { |     public static Object getPlayerInfoData(Object playerInfoPacket, WrappedGameProfile gameProfile) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getPlayerInfoData(gameProfile); |             return nmsReflection.getPlayerInfoData(gameProfile); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|             Object playerListName = chatComponentConstructor.newInstance(gameProfile.getName()); |             Object playerListName = chatComponentConstructor.newInstance(gameProfile.getName()); | ||||||
|  |  | ||||||
|             if (NmsVersion.v1_17.isSupported()) { |  | ||||||
|                 return packetPlayOutConstructor.newInstance(gameProfile.getHandle(), 0, enumGamemode[1], playerListName); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return packetPlayOutConstructor.newInstance(playerInfoPacket, gameProfile.getHandle(), 0, enumGamemode[1], playerListName); |             return packetPlayOutConstructor.newInstance(playerInfoPacket, gameProfile.getHandle(), 0, enumGamemode[1], playerListName); | ||||||
|         } catch (Exception ex) { |         } catch (Exception ex) { | ||||||
|             ex.printStackTrace(); |             ex.printStackTrace(); | ||||||
| @@ -1008,8 +935,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getNmsEntity(Entity entity) { |     public static Object getNmsEntity(Entity entity) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getNmsEntity(entity); |             return nmsReflection.getNmsEntity(entity); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1039,8 +966,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getNmsItem(ItemStack itemstack) { |     public static Object getNmsItem(ItemStack itemstack) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getNmsItem(itemstack); |             return nmsReflection.getNmsItem(itemstack); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1087,8 +1014,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static double getPing(Player player) { |     public static double getPing(Player player) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getPing(player); |             return nmsReflection.getPing(player); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1101,8 +1028,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static float[] getSize(Entity entity) { |     public static float[] getSize(Entity entity) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getSize(entity); |             return nmsReflection.getSize(entity); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1129,8 +1056,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) { |     public static WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getSkullBlob(gameProfile); |             return nmsReflection.getSkullBlob(gameProfile); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1153,8 +1080,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Float getSoundModifier(Object entity) { |     public static Float getSoundModifier(Object entity) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getSoundModifier(entity); |             return nmsReflection.getSoundModifier(entity); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1172,8 +1099,8 @@ public class ReflectionManager { | |||||||
|             Object minecraftServer = getMinecraftServer(); |             Object minecraftServer = getMinecraftServer(); | ||||||
|  |  | ||||||
|             LibsProfileLookupCaller callback = new LibsProfileLookupCaller(); |             LibsProfileLookupCaller callback = new LibsProfileLookupCaller(); | ||||||
|             if (NmsVersion.v1_18.isSupported()) { |             if (nmsReflection != null) { | ||||||
|                 v1_18ReflectionManager.injectCallback(playername, callback); |                 nmsReflection.injectCallback(playername, callback); | ||||||
|             } else { |             } else { | ||||||
|                 for (Method method : getNmsClass("MinecraftServer").getMethods()) { |                 for (Method method : getNmsClass("MinecraftServer").getMethods()) { | ||||||
|                     if (method.getReturnType().getSimpleName().equals("GameProfileRepository")) { |                     if (method.getReturnType().getSimpleName().equals("GameProfileRepository")) { | ||||||
| @@ -1202,8 +1129,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setBoundingBox(Entity entity, FakeBoundingBox newBox) { |     public static void setBoundingBox(Entity entity, FakeBoundingBox newBox) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             v1_18ReflectionManager.setBoundingBox(entity, newBox.getX(), newBox.getY(), newBox.getZ()); |             nmsReflection.setBoundingBox(entity, newBox.getX(), newBox.getY(), newBox.getZ()); | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -1220,8 +1147,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Enum getSoundCategory(String category) { |     public static Enum getSoundCategory(String category) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getSoundCategory(category); |             return nmsReflection.getSoundCategory(category); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return soundCategories.get(category); |         return soundCategories.get(category); | ||||||
| @@ -1252,8 +1179,8 @@ public class ReflectionManager { | |||||||
|      * @return null if the equipment slot is null |      * @return null if the equipment slot is null | ||||||
|      */ |      */ | ||||||
|     public static Enum createEnumItemSlot(EquipmentSlot slot) { |     public static Enum createEnumItemSlot(EquipmentSlot slot) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.createEnumItemSlot(slot); |             return nmsReflection.createEnumItemSlot(slot); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         switch (slot) { |         switch (slot) { | ||||||
| @@ -1333,8 +1260,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getSoundString(Sound sound) { |     public static Object getSoundString(Sound sound) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getSoundString(sound); |             return nmsReflection.getSoundString(sound); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1381,8 +1308,8 @@ public class ReflectionManager { | |||||||
|     public static Object convertInvalidMeta(Object value) { |     public static Object convertInvalidMeta(Object value) { | ||||||
|         if (value instanceof Optional) { |         if (value instanceof Optional) { | ||||||
|             Optional opt = (Optional) value; |             Optional opt = (Optional) value; | ||||||
|             if (NmsVersion.v1_18.isSupported()) { |             if (nmsReflection != null) { | ||||||
|                 return v1_18ReflectionManager.convertOptional(opt); |                 return nmsReflection.convertOptional(opt); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (!opt.isPresent()) { |             if (!opt.isPresent()) { | ||||||
| @@ -1425,8 +1352,8 @@ public class ReflectionManager { | |||||||
|             } |             } | ||||||
|         } else if (value instanceof Vector3F) { |         } else if (value instanceof Vector3F) { | ||||||
|             Vector3F angle = (Vector3F) value; |             Vector3F angle = (Vector3F) value; | ||||||
|             if (NmsVersion.v1_18.isSupported()) { |             if (nmsReflection != null) { | ||||||
|                 return v1_18ReflectionManager.convertVec3(angle); |                 return nmsReflection.convertVec3(angle); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             try { |             try { | ||||||
| @@ -1436,8 +1363,8 @@ public class ReflectionManager { | |||||||
|             } |             } | ||||||
|         } else if (value instanceof EulerAngle) { |         } else if (value instanceof EulerAngle) { | ||||||
|             EulerAngle angle = (EulerAngle) value; |             EulerAngle angle = (EulerAngle) value; | ||||||
|             if (NmsVersion.v1_18.isSupported()) { |             if (nmsReflection != null) { | ||||||
|                 return v1_18ReflectionManager.convertVec3(angle); |                 return nmsReflection.convertVec3(angle); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             try { |             try { | ||||||
| @@ -1446,8 +1373,8 @@ public class ReflectionManager { | |||||||
|                 ex.printStackTrace(); |                 ex.printStackTrace(); | ||||||
|             } |             } | ||||||
|         } else if (value instanceof Direction) { |         } else if (value instanceof Direction) { | ||||||
|             if (NmsVersion.v1_18.isSupported()) { |             if (nmsReflection != null) { | ||||||
|                 return v1_18ReflectionManager.convertDirection((Direction) value); |                 return nmsReflection.convertDirection((Direction) value); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             try { |             try { | ||||||
| @@ -1457,8 +1384,8 @@ public class ReflectionManager { | |||||||
|             } |             } | ||||||
|         } else if (value instanceof BlockPosition) { |         } else if (value instanceof BlockPosition) { | ||||||
|             BlockPosition pos = (BlockPosition) value; |             BlockPosition pos = (BlockPosition) value; | ||||||
|             if (NmsVersion.v1_18.isSupported()) { |             if (nmsReflection != null) { | ||||||
|                 return v1_18ReflectionManager.getBlockPosition(pos.getX(), pos.getY(), pos.getZ()); |                 return nmsReflection.getBlockPosition(pos.getX(), pos.getY(), pos.getZ()); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             try { |             try { | ||||||
| @@ -1486,8 +1413,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Material getMaterial(String name) { |     public static Material getMaterial(String name) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getMaterial(name); |             return nmsReflection.getMaterial(name); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1501,7 +1428,7 @@ public class ReflectionManager { | |||||||
|  |  | ||||||
|             Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name); |             Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name); | ||||||
|  |  | ||||||
|             Object registry = getNmsField("IRegistry", NmsVersion.v1_17.isSupported() ? "Z" : "ITEM").get(null); |             Object registry = getNmsField("IRegistry", "ITEM").get(null); | ||||||
|  |  | ||||||
|             Method getMethod = getNmsMethod(getNmsClass("RegistryMaterials"), "get", mcKey.getClass()); |             Method getMethod = getNmsMethod(getNmsClass("RegistryMaterials"), "get", mcKey.getClass()); | ||||||
|             Object item = getMethod.invoke(registry, mcKey); |             Object item = getMethod.invoke(registry, mcKey); | ||||||
| @@ -1526,8 +1453,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static String getItemName(Material material) { |     public static String getItemName(Material material) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getItemName(material); |             return nmsReflection.getItemName(material); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1540,7 +1467,7 @@ public class ReflectionManager { | |||||||
|             Object registry; |             Object registry; | ||||||
|  |  | ||||||
|             if (NmsVersion.v1_13.isSupported()) { |             if (NmsVersion.v1_13.isSupported()) { | ||||||
|                 registry = getNmsField("IRegistry", NmsVersion.v1_17.isSupported() ? "Z" : "ITEM").get(null); |                 registry = getNmsField("IRegistry", "ITEM").get(null); | ||||||
|             } else { |             } else { | ||||||
|                 registry = getNmsField("Item", "REGISTRY").get(null); |                 registry = getNmsField("Item", "REGISTRY").get(null); | ||||||
|             } |             } | ||||||
| @@ -1562,8 +1489,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getNmsVillagerData(VillagerData data) { |     public static Object getNmsVillagerData(VillagerData data) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getNmsVillagerData(data.getType(), data.getProfession()); |             return nmsReflection.getNmsVillagerData(data.getType(), data.getProfession()); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         Object type = getVillagerType(data.getType()); |         Object type = getVillagerType(data.getType()); | ||||||
| @@ -1579,8 +1506,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getVillagerType(Villager.Type type) { |     public static Object getVillagerType(Villager.Type type) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getVillagerType(type); |             return nmsReflection.getVillagerType(type); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1619,8 +1546,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getVillagerProfession(Villager.Profession profession) { |     public static Object getVillagerProfession(Villager.Profession profession) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getVillagerProfession(profession); |             return nmsReflection.getVillagerProfession(profession); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1658,8 +1585,8 @@ public class ReflectionManager { | |||||||
|     public static Object createDataWatcherItem(MetaIndex id, Object value) { |     public static Object createDataWatcherItem(MetaIndex id, Object value) { | ||||||
|         WrappedDataWatcherObject watcherObject = createDataWatcherObject(id, value); |         WrappedDataWatcherObject watcherObject = createDataWatcherObject(id, value); | ||||||
|  |  | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.createDataWatcherItem(watcherObject, convertInvalidMeta(value)); |             return nmsReflection.createDataWatcherItem(watcherObject, convertInvalidMeta(value)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1673,8 +1600,8 @@ public class ReflectionManager { | |||||||
|  |  | ||||||
|     @Deprecated |     @Deprecated | ||||||
|     public static Object createSoundEffect(String minecraftKey) { |     public static Object createSoundEffect(String minecraftKey) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.createSoundEffect(minecraftKey); |             return nmsReflection.createSoundEffect(minecraftKey); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1687,8 +1614,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object createMinecraftKey(String name) { |     public static Object createMinecraftKey(String name) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.createMinecraftKey(name); |             return nmsReflection.createMinecraftKey(name); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1701,8 +1628,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getVec3D(Vector vector) { |     public static Object getVec3D(Vector vector) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getVec3D(vector); |             return nmsReflection.getVec3D(vector); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1715,8 +1642,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getEntityType(EntityType entityType) { |     public static Object getEntityType(EntityType entityType) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getEntityType(entityType); |             return nmsReflection.getEntityType(entityType); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1735,8 +1662,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object registerEntityType(NamespacedKey key) { |     public static Object registerEntityType(NamespacedKey key) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.registerEntityType(key); |             return nmsReflection.registerEntityType(key); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1744,7 +1671,7 @@ public class ReflectionManager { | |||||||
|  |  | ||||||
|             Class typesClass = getNmsClass("IRegistry"); |             Class typesClass = getNmsClass("IRegistry"); | ||||||
|  |  | ||||||
|             Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null); |             Object registry = typesClass.getField("ENTITY_TYPE").get(null); | ||||||
|  |  | ||||||
|             Constructor c = getNmsClass("EntityTypes").getConstructors()[0]; |             Constructor c = getNmsClass("EntityTypes").getConstructors()[0]; | ||||||
|  |  | ||||||
| @@ -1778,16 +1705,16 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getEntityTypeId(Object entityTypes) { |     public static int getEntityTypeId(Object entityTypes) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getEntityTypeId(entityTypes); |             return nmsReflection.getEntityTypeId(entityTypes); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|             Class typesClass = getNmsClass("IRegistry"); |             Class typesClass = getNmsClass("IRegistry"); | ||||||
|  |  | ||||||
|             Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null); |             Object registry = typesClass.getField("ENTITY_TYPE").get(null); | ||||||
|  |  | ||||||
|             return (int) registry.getClass().getMethod(NmsVersion.v1_17.isSupported() ? "getId" : "a", Object.class).invoke(registry, entityTypes); |             return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes); | ||||||
|         } catch (Exception ex) { |         } catch (Exception ex) { | ||||||
|             ex.printStackTrace(); |             ex.printStackTrace(); | ||||||
|         } |         } | ||||||
| @@ -1796,8 +1723,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getEntityTypeId(EntityType entityType) { |     public static int getEntityTypeId(EntityType entityType) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getEntityTypeId(entityType); |             return nmsReflection.getEntityTypeId(entityType); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1806,9 +1733,9 @@ public class ReflectionManager { | |||||||
|  |  | ||||||
|                 Class typesClass = getNmsClass("IRegistry"); |                 Class typesClass = getNmsClass("IRegistry"); | ||||||
|  |  | ||||||
|                 Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null); |                 Object registry = typesClass.getField("ENTITY_TYPE").get(null); | ||||||
|  |  | ||||||
|                 return (int) registry.getClass().getMethod(NmsVersion.v1_17.isSupported() ? "getId" : "a", Object.class).invoke(registry, entityTypes); |                 return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return entityType.getTypeId(); |             return entityType.getTypeId(); | ||||||
| @@ -1820,17 +1747,17 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getEntityType(NamespacedKey name) { |     public static Object getEntityType(NamespacedKey name) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getEntityType(name); |             return nmsReflection.getEntityType(name); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|             Class typesClass = getNmsClass("IRegistry"); |             Class typesClass = getNmsClass("IRegistry"); | ||||||
|  |  | ||||||
|             Object registry = typesClass.getField(NmsVersion.v1_17.isSupported() ? "Y" : "ENTITY_TYPE").get(null); |             Object registry = typesClass.getField("ENTITY_TYPE").get(null); | ||||||
|             Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name.toString()); |             Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name.toString()); | ||||||
|  |  | ||||||
|             return registry.getClass().getMethod(NmsVersion.v1_17.isSupported() ? "getId" : "a", mcKey.getClass()).invoke(registry, mcKey); |             return registry.getClass().getMethod("a", mcKey.getClass()).invoke(registry, mcKey); | ||||||
|         } catch (Exception ex) { |         } catch (Exception ex) { | ||||||
|             ex.printStackTrace(); |             ex.printStackTrace(); | ||||||
|         } |         } | ||||||
| @@ -1839,9 +1766,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getNmsEntityPose(EntityPose entityPose) { |     public static Object getNmsEntityPose(EntityPose entityPose) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getNmsEntityPose( |             return nmsReflection.getNmsEntityPose(entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name()); | ||||||
|                     entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name()); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return Enum.valueOf(entityPoseClass, entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name()); |         return Enum.valueOf(entityPoseClass, entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name()); | ||||||
| @@ -1863,8 +1789,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getCombinedIdByBlockData(BlockData data) { |     public static int getCombinedIdByBlockData(BlockData data) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getCombinedIdByBlockData(data); |             return nmsReflection.getCombinedIdByBlockData(data); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1879,8 +1805,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getCombinedIdByItemStack(ItemStack itemStack) { |     public static int getCombinedIdByItemStack(ItemStack itemStack) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getCombinedIdByItemStack(itemStack); |             return nmsReflection.getCombinedIdByItemStack(itemStack); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1901,8 +1827,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static BlockData getBlockDataByCombinedId(int id) { |     public static BlockData getBlockDataByCombinedId(int id) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getBlockDataByCombinedId(id); |             return nmsReflection.getBlockDataByCombinedId(id); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1919,8 +1845,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static ItemStack getItemStackByCombinedId(int id) { |     public static ItemStack getItemStackByCombinedId(int id) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getItemStackByCombinedId(id); |             return nmsReflection.getItemStackByCombinedId(id); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1947,8 +1873,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static Object getWorldServer(World w) { |     public static Object getWorldServer(World w) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getWorldServer(w); |             return nmsReflection.getWorldServer(w); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -1961,8 +1887,8 @@ public class ReflectionManager { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static ItemMeta getDeserializedItemMeta(Map<String, Object> meta) { |     public static ItemMeta getDeserializedItemMeta(Map<String, Object> meta) { | ||||||
|         if (NmsVersion.v1_18.isSupported()) { |         if (nmsReflection != null) { | ||||||
|             return v1_18ReflectionManager.getDeserializedItemMeta(meta); |             return nmsReflection.getDeserializedItemMeta(meta); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
| @@ -2240,7 +2166,7 @@ public class ReflectionManager { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType, |             Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType, | ||||||
|                     NmsVersion.v1_18.isSupported() ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName); |                     nmsReflection != null ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName); | ||||||
|  |  | ||||||
|             if (nmsEntity == null) { |             if (nmsEntity == null) { | ||||||
|                 DisguiseUtilities.getLogger().warning("Entity not found! (" + nmsEntityName + ")"); |                 DisguiseUtilities.getLogger().warning("Entity not found! (" + nmsEntityName + ")"); | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -9,6 +9,7 @@ | |||||||
|     <version>10.0.26-SNAPSHOT</version> |     <version>10.0.26-SNAPSHOT</version> | ||||||
|     <modules> |     <modules> | ||||||
|         <module>shared</module> |         <module>shared</module> | ||||||
|  |         <module>v1_17_R1</module> | ||||||
|         <module>v1_18_R1</module> |         <module>v1_18_R1</module> | ||||||
|         <module>plugin</module> |         <module>plugin</module> | ||||||
|     </modules> |     </modules> | ||||||
|   | |||||||
| @@ -7,8 +7,8 @@ | |||||||
|         <groupId>LibsDisguises</groupId> |         <groupId>LibsDisguises</groupId> | ||||||
|         <version>10.0.26-SNAPSHOT</version> |         <version>10.0.26-SNAPSHOT</version> | ||||||
|     </parent> |     </parent> | ||||||
|     <modelVersion>4.0.0</modelVersion> |  | ||||||
|  |  | ||||||
|  |     <modelVersion>4.0.0</modelVersion> | ||||||
|     <artifactId>shared</artifactId> |     <artifactId>shared</artifactId> | ||||||
|  |  | ||||||
|     <dependencies> |     <dependencies> | ||||||
|   | |||||||
							
								
								
									
										81
									
								
								v1_17_R1/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								v1_17_R1/pom.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,81 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||||
|  |          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
|  |          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||||
|  |     <parent> | ||||||
|  |         <artifactId>LibsDisguises</artifactId> | ||||||
|  |         <groupId>LibsDisguises</groupId> | ||||||
|  |         <version>10.0.26-SNAPSHOT</version> | ||||||
|  |         <relativePath>../pom.xml</relativePath> | ||||||
|  |     </parent> | ||||||
|  |  | ||||||
|  |     <modelVersion>4.0.0</modelVersion> | ||||||
|  |  | ||||||
|  |     <artifactId>v1_17_R1</artifactId> | ||||||
|  |  | ||||||
|  |     <dependencies> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>org.spigotmc</groupId> | ||||||
|  |             <artifactId>spigot</artifactId> | ||||||
|  |             <version>1.17.1-R0.1-SNAPSHOT</version> | ||||||
|  |             <classifier>remapped-mojang</classifier> | ||||||
|  |             <scope>provided</scope> | ||||||
|  |         </dependency> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>org.spigotmc</groupId> | ||||||
|  |             <artifactId>spigot-api</artifactId> | ||||||
|  |             <version>1.17.1-R0.1-SNAPSHOT</version> | ||||||
|  |             <scope>provided</scope> | ||||||
|  |         </dependency> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>LibsDisguises</groupId> | ||||||
|  |             <artifactId>shared</artifactId> | ||||||
|  |             <version>${project.version}</version> | ||||||
|  |         </dependency> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>com.comphenix.protocol</groupId> | ||||||
|  |             <artifactId>ProtocolLib</artifactId> | ||||||
|  |         </dependency> | ||||||
|  |     </dependencies> | ||||||
|  |  | ||||||
|  |     <build> | ||||||
|  |         <plugins> | ||||||
|  |             <plugin> | ||||||
|  |                 <groupId>net.md-5</groupId> | ||||||
|  |                 <artifactId>specialsource-maven-plugin</artifactId> | ||||||
|  |                 <version>1.2.2</version> | ||||||
|  |                 <executions> | ||||||
|  |                     <execution> | ||||||
|  |                         <phase>package</phase> | ||||||
|  |                         <goals> | ||||||
|  |                             <goal>remap</goal> | ||||||
|  |                         </goals> | ||||||
|  |                         <id>remap-obf</id> | ||||||
|  |                         <configuration> | ||||||
|  |                             <srgIn>org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:txt:maps-mojang</srgIn> | ||||||
|  |                             <reverse>true</reverse> | ||||||
|  |                             <remappedDependencies>org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies> | ||||||
|  |                             <remappedArtifactAttached>true</remappedArtifactAttached> | ||||||
|  |                             <remappedClassifierName>remapped-obf</remappedClassifierName> | ||||||
|  |                         </configuration> | ||||||
|  |                     </execution> | ||||||
|  |                     <execution> | ||||||
|  |                         <phase>package</phase> | ||||||
|  |                         <goals> | ||||||
|  |                             <goal>remap</goal> | ||||||
|  |                         </goals> | ||||||
|  |                         <id>remap-spigot</id> | ||||||
|  |                         <configuration> | ||||||
|  |                             <inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile> | ||||||
|  |                             <srgIn>org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn> | ||||||
|  |                             <remappedDependencies>org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies> | ||||||
|  |                             <remappedArtifactAttached>true</remappedArtifactAttached> | ||||||
|  |                             <remappedClassifierName>remapped-spigot</remappedClassifierName> | ||||||
|  |                         </configuration> | ||||||
|  |                     </execution> | ||||||
|  |                 </executions> | ||||||
|  |             </plugin> | ||||||
|  |         </plugins> | ||||||
|  |     </build> | ||||||
|  |  | ||||||
|  | </project> | ||||||
| @@ -0,0 +1,437 @@ | |||||||
|  | package me.libraryaddict.disguise.utilities.reflection.v1_17; | ||||||
|  |  | ||||||
|  | import com.comphenix.protocol.wrappers.*; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers.Direction; | ||||||
|  | import com.mojang.authlib.Agent; | ||||||
|  | import com.mojang.authlib.GameProfile; | ||||||
|  | import com.mojang.authlib.ProfileLookupCallback; | ||||||
|  | import com.mojang.authlib.minecraft.MinecraftSessionService; | ||||||
|  | import me.libraryaddict.disguise.utilities.reflection.ReflectionManagerAbstract; | ||||||
|  | import net.minecraft.core.BlockPos; | ||||||
|  | import net.minecraft.core.Registry; | ||||||
|  | import net.minecraft.core.Vector3f; | ||||||
|  | import net.minecraft.network.chat.TextComponent; | ||||||
|  | import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket; | ||||||
|  | import net.minecraft.network.syncher.EntityDataAccessor; | ||||||
|  | import net.minecraft.network.syncher.SynchedEntityData; | ||||||
|  | import net.minecraft.resources.ResourceLocation; | ||||||
|  | import net.minecraft.server.dedicated.DedicatedServer; | ||||||
|  | import net.minecraft.server.level.*; | ||||||
|  | import net.minecraft.server.network.ServerGamePacketListenerImpl; | ||||||
|  | import net.minecraft.server.network.ServerPlayerConnection; | ||||||
|  | import net.minecraft.sounds.SoundEvent; | ||||||
|  | import net.minecraft.sounds.SoundSource; | ||||||
|  | import net.minecraft.world.damagesource.DamageSource; | ||||||
|  | import net.minecraft.world.effect.MobEffect; | ||||||
|  | import net.minecraft.world.effect.MobEffectInstance; | ||||||
|  | import net.minecraft.world.entity.EntityDimensions; | ||||||
|  | import net.minecraft.world.entity.npc.VillagerData; | ||||||
|  | import net.minecraft.world.entity.npc.VillagerProfession; | ||||||
|  | import net.minecraft.world.entity.npc.VillagerType; | ||||||
|  | import net.minecraft.world.level.GameType; | ||||||
|  | import net.minecraft.world.level.block.Block; | ||||||
|  | import net.minecraft.world.level.block.state.BlockState; | ||||||
|  | import net.minecraft.world.phys.AABB; | ||||||
|  | import net.minecraft.world.phys.Vec3; | ||||||
|  | import org.bukkit.*; | ||||||
|  | import org.bukkit.block.data.BlockData; | ||||||
|  | import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectFunction; | ||||||
|  | import org.bukkit.craftbukkit.v1_17_R1.CraftArt; | ||||||
|  | import org.bukkit.craftbukkit.v1_17_R1.CraftServer; | ||||||
|  | import org.bukkit.craftbukkit.v1_17_R1.CraftSound; | ||||||
|  | import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; | ||||||
|  | import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; | ||||||
|  | import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; | ||||||
|  | import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; | ||||||
|  | import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; | ||||||
|  | import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers; | ||||||
|  | import org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey; | ||||||
|  | import org.bukkit.entity.Entity; | ||||||
|  | import org.bukkit.entity.EntityType; | ||||||
|  | import org.bukkit.entity.Player; | ||||||
|  | import org.bukkit.entity.Villager; | ||||||
|  | import org.bukkit.inventory.EquipmentSlot; | ||||||
|  | import org.bukkit.inventory.ItemStack; | ||||||
|  | import org.bukkit.inventory.meta.ItemMeta; | ||||||
|  | import org.bukkit.potion.PotionEffect; | ||||||
|  | import org.bukkit.util.EulerAngle; | ||||||
|  | import org.bukkit.util.Vector; | ||||||
|  |  | ||||||
|  | import java.lang.reflect.Field; | ||||||
|  | import java.lang.reflect.Method; | ||||||
|  | import java.util.*; | ||||||
|  | import java.util.concurrent.atomic.AtomicInteger; | ||||||
|  |  | ||||||
|  | public class ReflectionManager implements ReflectionManagerAbstract { | ||||||
|  |     public boolean hasInvul(Entity entity) { | ||||||
|  |         net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||||
|  |  | ||||||
|  |         if (nmsEntity instanceof net.minecraft.world.entity.LivingEntity) { | ||||||
|  |             return nmsEntity.invulnerableTime > 0; | ||||||
|  |         } else { | ||||||
|  |             return nmsEntity.isInvulnerableTo(DamageSource.GENERIC); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public int getIncrementedStateId(Player player) { | ||||||
|  |         ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); | ||||||
|  |         return serverPlayer.containerMenu.incrementStateId(); // TODO Check correct container | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public int getNewEntityId() { | ||||||
|  |         return getNewEntityId(true); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public int getNewEntityId(boolean increment) { | ||||||
|  |         try { | ||||||
|  |             Field entityCounter = net.minecraft.world.entity.Entity.class.getDeclaredField("b"); | ||||||
|  |             entityCounter.setAccessible(true); | ||||||
|  |             AtomicInteger atomicInteger = (AtomicInteger) entityCounter.get(null); | ||||||
|  |             if (increment) { | ||||||
|  |                 return atomicInteger.incrementAndGet(); | ||||||
|  |             } else { | ||||||
|  |                 return atomicInteger.get(); | ||||||
|  |             } | ||||||
|  |         } catch (ReflectiveOperationException e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ServerGamePacketListenerImpl getPlayerConnectionOrPlayer(Player player) { | ||||||
|  |         return ((CraftPlayer) player).getHandle().connection; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public net.minecraft.world.entity.Entity createEntityInstance(String entityName) { | ||||||
|  |         Optional<net.minecraft.world.entity.EntityType<?>> optional = net.minecraft.world.entity.EntityType.byString(entityName.toLowerCase(Locale.ROOT)); | ||||||
|  |         if (optional.isPresent()) { | ||||||
|  |             net.minecraft.world.entity.EntityType<?> entityType = optional.get(); | ||||||
|  |             ServerLevel world = getWorldServer(Bukkit.getWorlds().get(0)); | ||||||
|  |             net.minecraft.world.entity.Entity entity; | ||||||
|  |             if (entityType == net.minecraft.world.entity.EntityType.PLAYER) { | ||||||
|  |                 WrappedGameProfile gameProfile = ReflectionManagerAbstract.getGameProfile(new UUID(0, 0), "Steve"); | ||||||
|  |                 entity = new ServerPlayer(getMinecraftServer(), world, (GameProfile) gameProfile.getHandle()); | ||||||
|  |             }/* else if (entityType == net.minecraft.world.entity.EntityType.ENDER_PEARL) { | ||||||
|  |                 entity = new ThrownEnderpearl(world, (net.minecraft.world.entity.LivingEntity) createEntityInstance("cow")); | ||||||
|  |             } else if (entityType == net.minecraft.world.entity.EntityType.FISHING_BOBBER) { | ||||||
|  |                 entity = new FishingHook((net.minecraft.world.entity.player.Player) createEntityInstance("player"), world, 0, 0); | ||||||
|  |             }*/ else { | ||||||
|  |                 entity = entityType.create(world); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             // Workaround for paper being 2 smart 4 me | ||||||
|  |             entity.setPos(1.0, 1.0, 1.0); | ||||||
|  |             entity.setPos(0.0, 0.0, 0.0); | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public MobEffect getMobEffectList(int id) { | ||||||
|  |         return MobEffect.byId(id); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public MobEffectInstance createMobEffect(PotionEffect effect) { | ||||||
|  |         return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public MobEffectInstance createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) { | ||||||
|  |         return new MobEffectInstance(getMobEffectList(id), duration, amplification, ambient, particles); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public AABB getBoundingBox(Entity entity) { | ||||||
|  |         return ((CraftEntity) entity).getHandle().getBoundingBox(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public double getXBoundingBox(Entity entity) { | ||||||
|  |         return getBoundingBox(entity).maxX - getBoundingBox(entity).minX; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public double getYBoundingBox(Entity entity) { | ||||||
|  |         return getBoundingBox(entity).maxY - getBoundingBox(entity).minY; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public double getZBoundingBox(Entity entity) { | ||||||
|  |         return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ServerPlayer getPlayerFromPlayerConnection(Object nmsEntity) { | ||||||
|  |         return ((ServerPlayerConnection) nmsEntity).getPlayer(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Entity getBukkitEntity(Object nmsEntity) { | ||||||
|  |         return ((net.minecraft.world.entity.Entity) nmsEntity).getBukkitEntity(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ItemStack getBukkitItem(Object nmsItem) { | ||||||
|  |         return CraftItemStack.asBukkitCopy((net.minecraft.world.item.ItemStack) nmsItem); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ItemStack getCraftItem(ItemStack bukkitItem) { | ||||||
|  |         return CraftItemStack.asCraftCopy(bukkitItem); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public SoundEvent getCraftSound(Sound sound) { | ||||||
|  |         return CraftSound.getSoundEffect(sound); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ServerEntity getEntityTrackerEntry(Entity target) throws Exception { | ||||||
|  |         ServerLevel world = ((CraftWorld) target.getWorld()).getHandle(); | ||||||
|  |         ServerChunkCache chunkSource = world.getChunkProvider(); | ||||||
|  |         ChunkMap chunkMap = chunkSource.chunkMap; | ||||||
|  |         Map<Integer, ChunkMap.TrackedEntity> entityMap = chunkMap.G; | ||||||
|  |         ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId()); | ||||||
|  |         if (trackedEntity == null) { | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         Field field = ChunkMap.TrackedEntity.class.getDeclaredField("b"); | ||||||
|  |         field.setAccessible(true); | ||||||
|  |  | ||||||
|  |         return (ServerEntity) field.get(trackedEntity); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public DedicatedServer getMinecraftServer() { | ||||||
|  |         return ((CraftServer) Bukkit.getServer()).getServer(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public String getEnumArt(Art art) { | ||||||
|  |         return Registry.MOTIVE.getKey(CraftArt.BukkitToNotch(art)).getPath(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public BlockPos getBlockPosition(int x, int y, int z) { | ||||||
|  |         return new BlockPos(x, y, z); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public net.minecraft.core.Direction getEnumDirection(int direction) { | ||||||
|  |         return net.minecraft.core.Direction.from2DDataValue(direction); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ClientboundPlayerInfoPacket.Action getEnumPlayerInfoAction(int action) { | ||||||
|  |         return ClientboundPlayerInfoPacket.Action.values()[action]; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ClientboundPlayerInfoPacket.PlayerUpdate getPlayerInfoData(WrappedGameProfile gameProfile) { | ||||||
|  |         return new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL, | ||||||
|  |                 new TextComponent(gameProfile.getName())); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Object getNmsEntity(Entity entity) { | ||||||
|  |         return ((CraftEntity) entity).getHandle(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public double getPing(Player player) { | ||||||
|  |         return player.getPing(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public float[] getSize(Entity entity) { | ||||||
|  |         net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle(); | ||||||
|  |         EntityDimensions dimensions = nmsEntity.getDimensions(net.minecraft.world.entity.Pose.STANDING); | ||||||
|  |         return new float[]{dimensions.width, nmsEntity.getEyeHeight()}; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) { | ||||||
|  |         DedicatedServer minecraftServer = getMinecraftServer(); | ||||||
|  |         MinecraftSessionService sessionService = minecraftServer.getSessionService(); | ||||||
|  |         return WrappedGameProfile.fromHandle(sessionService.fillProfileProperties((GameProfile) gameProfile.getHandle(), true)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Float getSoundModifier(Object entity) { | ||||||
|  |         if (!(entity instanceof net.minecraft.world.entity.LivingEntity)) { | ||||||
|  |             return 0.0f; | ||||||
|  |         } else { | ||||||
|  |             return ((net.minecraft.world.entity.LivingEntity) entity).getVoicePitch(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void injectCallback(String playername, ProfileLookupCallback callback) { | ||||||
|  |         Agent agent = Agent.MINECRAFT; | ||||||
|  |         getMinecraftServer().getProfileRepository().findProfilesByNames(new String[]{playername}, agent, callback); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void setBoundingBox(Entity entity, double x, double y, double z) { | ||||||
|  |         Location loc = entity.getLocation(); | ||||||
|  |         ((CraftEntity) entity).getHandle().setBoundingBox( | ||||||
|  |                 new AABB(loc.getX() - x / 2, loc.getY() - y / 2, loc.getZ() - z / 2, loc.getX() + x / 2, loc.getY() + y / 2, loc.getZ() + z / 2)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Enum getSoundCategory(String category) { | ||||||
|  |         return Arrays.stream(SoundSource.values()).filter(soundSource -> category.equalsIgnoreCase(soundSource.getName())).findAny().get(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Creates the NMS object EnumItemSlot from an EquipmentSlot. | ||||||
|  |      * | ||||||
|  |      * @param slot | ||||||
|  |      * @return null if the equipment slot is null | ||||||
|  |      */ | ||||||
|  |     public Enum createEnumItemSlot(EquipmentSlot slot) { | ||||||
|  |         switch (slot) { | ||||||
|  |             case HAND: | ||||||
|  |                 return net.minecraft.world.entity.EquipmentSlot.MAINHAND; | ||||||
|  |             case OFF_HAND: | ||||||
|  |                 return net.minecraft.world.entity.EquipmentSlot.OFFHAND; | ||||||
|  |             case FEET: | ||||||
|  |                 return net.minecraft.world.entity.EquipmentSlot.FEET; | ||||||
|  |             case LEGS: | ||||||
|  |                 return net.minecraft.world.entity.EquipmentSlot.LEGS; | ||||||
|  |             case CHEST: | ||||||
|  |                 return net.minecraft.world.entity.EquipmentSlot.CHEST; | ||||||
|  |             case HEAD: | ||||||
|  |                 return net.minecraft.world.entity.EquipmentSlot.HEAD; | ||||||
|  |             default: | ||||||
|  |                 return null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Object getSoundString(Sound sound) { | ||||||
|  |         return CraftSound.getSoundEffect(sound).getLocation().toString(); // TODO | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Optional<?> convertOptional(Object val) { | ||||||
|  |         if (val instanceof BlockPosition) { | ||||||
|  |             BlockPosition pos = (BlockPosition) val; | ||||||
|  |             return Optional.of(getBlockPosition(pos.getX(), pos.getY(), pos.getZ())); | ||||||
|  |         } else if (val instanceof WrappedBlockData) { | ||||||
|  |             Object obj = ((WrappedBlockData) val).getHandle(); | ||||||
|  |             return Optional.of(obj); | ||||||
|  |         } else if (val instanceof ItemStack) { | ||||||
|  |             Object obj = getNmsItem((ItemStack) val); | ||||||
|  |             return Optional.of(obj); | ||||||
|  |         } else if (val instanceof WrappedChatComponent) { | ||||||
|  |             Object obj = ((WrappedChatComponent) val).getHandle(); | ||||||
|  |             return Optional.of(obj); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return Optional.empty(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Vector3f convertVec3(Object object) { | ||||||
|  |         if (object instanceof Vector3F) { | ||||||
|  |             Vector3F vector3F = (Vector3F) object; | ||||||
|  |             return new Vector3f(vector3F.getX(), vector3F.getY(), vector3F.getZ()); | ||||||
|  |         } else if (object instanceof EulerAngle) { | ||||||
|  |             EulerAngle eulerAngle = (EulerAngle) object; | ||||||
|  |             return new Vector3f((float) eulerAngle.getX(), (float) eulerAngle.getY(), (float) eulerAngle.getZ()); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public net.minecraft.core.Direction convertDirection(Direction direction) { | ||||||
|  |         return net.minecraft.core.Direction.from3DDataValue(direction.ordinal()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Material getMaterial(String name) { | ||||||
|  |         return CraftMagicNumbers.INSTANCE.getMaterial(name, CraftMagicNumbers.INSTANCE.getDataVersion()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public String getItemName(Material material) { | ||||||
|  |         return Registry.ITEM.getKey(CraftMagicNumbers.getItem(material)).getPath(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public net.minecraft.world.item.ItemStack getNmsItem(ItemStack itemStack) { | ||||||
|  |         return CraftItemStack.asNMSCopy(itemStack); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public VillagerData getNmsVillagerData(Villager.Type villagerType, Villager.Profession villagerProfession) { | ||||||
|  |         VillagerType nmsVillagerType = Registry.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(villagerType.getKey())); | ||||||
|  |         VillagerProfession nmsVillagerProfession = Registry.VILLAGER_PROFESSION.get(CraftNamespacedKey.toMinecraft(villagerProfession.getKey())); | ||||||
|  |  | ||||||
|  |         return new net.minecraft.world.entity.npc.VillagerData(nmsVillagerType, nmsVillagerProfession, 1); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public VillagerType getVillagerType(Villager.Type type) { | ||||||
|  |         return Registry.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey())); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public VillagerProfession getVillagerProfession(Villager.Profession profession) { | ||||||
|  |         return Registry.VILLAGER_PROFESSION.get(CraftNamespacedKey.toMinecraft(profession.getKey())); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public <T> SynchedEntityData.DataItem<T> createDataWatcherItem(WrappedDataWatcher.WrappedDataWatcherObject wrappedDataWatcherObject, T metaItem) { | ||||||
|  |         return new SynchedEntityData.DataItem<>((EntityDataAccessor<T>) wrappedDataWatcherObject.getHandle(), metaItem); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Deprecated | ||||||
|  |     public SoundEvent createSoundEffect(String minecraftKey) { | ||||||
|  |         return new SoundEvent(new ResourceLocation(minecraftKey)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public ResourceLocation createMinecraftKey(String name) { | ||||||
|  |         return new ResourceLocation(name); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Vec3 getVec3D(Vector vector) { | ||||||
|  |         return new Vec3(vector.getX(), vector.getY(), vector.getZ()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public net.minecraft.world.entity.EntityType getEntityType(EntityType entityType) { | ||||||
|  |         return net.minecraft.world.entity.EntityType.byString( | ||||||
|  |                 entityType.getName() == null ? entityType.name().toLowerCase(Locale.ENGLISH) : entityType.getName()).orElse(null); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Object registerEntityType(NamespacedKey key) { | ||||||
|  |         net.minecraft.world.entity.EntityType<net.minecraft.world.entity.Entity> newEntity = | ||||||
|  |                 new net.minecraft.world.entity.EntityType<>(null, null, false, false, false, false, null, null, 0, 0); | ||||||
|  |         Registry.register(Registry.ENTITY_TYPE, CraftNamespacedKey.toMinecraft(key), newEntity); | ||||||
|  |         newEntity.getDescriptionId(); | ||||||
|  |         return newEntity; // TODO ??? Some reflection in legacy that I'm unsure about | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public int getEntityTypeId(Object entityTypes) { | ||||||
|  |         net.minecraft.world.entity.EntityType entityType = (net.minecraft.world.entity.EntityType) entityTypes; | ||||||
|  |         return Registry.ENTITY_TYPE.getId(entityType); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public int getEntityTypeId(EntityType entityType) { | ||||||
|  |         return getEntityTypeId(getEntityType(entityType)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Object getEntityType(NamespacedKey name) { | ||||||
|  |         return Registry.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(name)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Object getNmsEntityPose(String enumPose) { | ||||||
|  |         return net.minecraft.world.entity.Pose.valueOf(enumPose); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public int getCombinedIdByBlockData(BlockData data) { | ||||||
|  |         BlockState state = ((CraftBlockData) data).getState(); | ||||||
|  |         return Block.getId(state); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public int getCombinedIdByItemStack(ItemStack itemStack) { | ||||||
|  |         Block block = CraftMagicNumbers.getBlock(itemStack.getType()); | ||||||
|  |         return Block.getId(block.defaultBlockState()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public BlockData getBlockDataByCombinedId(int id) { | ||||||
|  |         return CraftBlockData.fromData(Block.stateById(id)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ItemStack getItemStackByCombinedId(int id) { | ||||||
|  |         return new ItemStack(CraftMagicNumbers.getMaterial(Block.stateById(id).getBlock())); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ServerLevel getWorldServer(World w) { | ||||||
|  |         return ((CraftWorld) w).getHandle(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ItemMeta getDeserializedItemMeta(Map<String, Object> meta) { | ||||||
|  |         try { | ||||||
|  |             Class<?> aClass = Class.forName("org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaItem$SerializableMeta"); | ||||||
|  |             Method deserialize = aClass.getDeclaredMethod("deserialize", Map.class); | ||||||
|  |             Object itemMeta = deserialize.invoke(null, meta); | ||||||
|  |  | ||||||
|  |             return (ItemMeta) itemMeta; | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -6,9 +6,10 @@ | |||||||
|         <artifactId>LibsDisguises</artifactId> |         <artifactId>LibsDisguises</artifactId> | ||||||
|         <groupId>LibsDisguises</groupId> |         <groupId>LibsDisguises</groupId> | ||||||
|         <version>10.0.26-SNAPSHOT</version> |         <version>10.0.26-SNAPSHOT</version> | ||||||
|  |         <relativePath>../pom.xml</relativePath> | ||||||
|     </parent> |     </parent> | ||||||
|     <modelVersion>4.0.0</modelVersion> |  | ||||||
|  |  | ||||||
|  |     <modelVersion>4.0.0</modelVersion> | ||||||
|     <artifactId>v1_18_R1</artifactId> |     <artifactId>v1_18_R1</artifactId> | ||||||
|  |  | ||||||
|     <dependencies> |     <dependencies> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user