From 9f6b2fb535650df06fc19bafa3c4997ea2cb548e Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 8 Dec 2021 14:10:19 +1300 Subject: [PATCH] Minor fixes --- plugin/pom.xml | 8 +++++ .../disguise/utilities/DisguiseUtilities.java | 29 ++++++++------- .../reflection/ReflectionManager.java | 35 ++++--------------- .../utilities/watchers/CompileMethods.java | 2 +- .../reflection/v1_18}/ReflectionManager.java | 2 +- 5 files changed, 33 insertions(+), 43 deletions(-) rename v1_18_R1/src/main/java/me/libraryaddict/disguise/{v1_18/utilities/reflection => utilities/reflection/v1_18}/ReflectionManager.java (99%) diff --git a/plugin/pom.xml b/plugin/pom.xml index db4aaafc..e1861470 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -38,6 +38,14 @@ + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + ../target + + maven-surefire-plugin 3.0.0-M5 diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 81555b74..de11ac34 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -480,7 +480,12 @@ public class DisguiseUtilities { // If we are on 1.17, you need this release or dev build // ProtocolLib is a little funny in that it provides next release version as the current version - return new String[]{"4.7.0", "528"}; + if (!NmsVersion.v1_18.isSupported()) { + return new String[]{"4.7.0", "528"}; + } + + // If you're on 1.18.. + return new String[]{"4.8.0", "538"}; } public static boolean isProtocolLibOutdated() { @@ -1609,8 +1614,8 @@ public class DisguiseUtilities { Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); - Method clear = ReflectionManager - .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", ReflectionManager.getNmsClass("EntityPlayer")); + Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", + ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer", ReflectionManager.getNmsClass("EntityPlayer")); @@ -1665,8 +1670,8 @@ public class DisguiseUtilities { if (entityTrackerEntry != null) { Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); - Method clear = ReflectionManager - .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", ReflectionManager.getNmsClass("EntityPlayer")); + Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", + ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer", ReflectionManager.getNmsClass("EntityPlayer")); @@ -1732,8 +1737,8 @@ public class DisguiseUtilities { Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); // TODO Store the fields - final Method clear = ReflectionManager - .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", ReflectionManager.getNmsClass("EntityPlayer")); + final Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", + ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer", ReflectionManager.getNmsClass("EntityPlayer")); @@ -1859,8 +1864,8 @@ public class DisguiseUtilities { ((Set) trackedPlayersObj).remove(ReflectionManager.getPlayerConnectionOrPlayer(player)); } else { - ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap").get(entityTrackerEntry)) - .remove(ReflectionManager.getPlayerConnectionOrPlayer(player)); + ((Map) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap").get(entityTrackerEntry)).remove( + ReflectionManager.getPlayerConnectionOrPlayer(player)); } } } catch (Exception ex) { @@ -2962,8 +2967,8 @@ public class DisguiseUtilities { name = ChatColor.translateAlternateColorCodes('&', newNames[i]); } - WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager - .createDataWatcherObject(NmsVersion.v1_13.isSupported() ? MetaIndex.ENTITY_CUSTOM_NAME : MetaIndex.ENTITY_CUSTOM_NAME_OLD, name); + WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject( + NmsVersion.v1_13.isSupported() ? MetaIndex.ENTITY_CUSTOM_NAME : MetaIndex.ENTITY_CUSTOM_NAME_OLD, name); watcher.setObject(obj, ReflectionManager.convertInvalidMeta(name)); @@ -2985,7 +2990,7 @@ public class DisguiseUtilities { Location loc = disguise.getEntity().getLocation(); packet.getDoubles().write(0, loc.getX()); - packet.getDoubles().write(1, loc.getY() + height + (0.28 * i)); + packet.getDoubles().write(1, loc.getY() + height + (0.28 * i)); packet.getDoubles().write(2, loc.getZ()); packets.add(packet); diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index 91c307fe..613f1a88 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -108,7 +108,6 @@ public class ReflectionManager { private static Field noDamageTicks; private static Method isInvul; private static Object genericDamage; - private static HashMap classLocations = new HashMap<>(); private static Field playerConnection; private static Method incrementedInventoryStateId; private static Field playerInventoryContainer; @@ -766,7 +765,7 @@ public class ReflectionManager { public static ReflectionManagerAbstract getReflectionManager(NmsVersion nmsVersion) { try { - Class aClass = Class.forName("me.libraryaddict.disguise." + nmsVersion.name() + ".utilities.reflection.ReflectionManager"); + Class aClass = Class.forName("me.libraryaddict.disguise.utilities.reflection." + nmsVersion.name() + ".ReflectionManager"); Object o = aClass.getConstructor().newInstance(); return (ReflectionManagerAbstract) o; } catch (ReflectiveOperationException e) { @@ -970,31 +969,7 @@ public class ReflectionManager { } private static String getLocation(String pack, String className) { - if (NmsVersion.v1_18.isSupported()) { - return ClassMappings.getClass(pack, className); - } - - String toReturn = classLocations.get(className); - - if (toReturn != null) { - return toReturn; - } - - try { - ArrayList classes = ClassGetter.getEntriesForPackage(pack); - - String realLocation = classes.stream().filter(s -> s.endsWith("/" + className + ".class")).findAny().get().replace("/", ".").replace(".class", ""); - - classLocations.put(className, realLocation); - - return realLocation; - } catch (Throwable throwable) { - // System.err.println(pack + " - " + className); - // throwable.printStackTrace(); - classLocations.put(className, className); - } - - return className; + return ClassMappings.getClass(pack, className); } public static Class getNmsClass(String className) { @@ -1865,7 +1840,8 @@ public class ReflectionManager { public static Object getNmsEntityPose(EntityPose entityPose) { if (NmsVersion.v1_18.isSupported()) { - return v1_18ReflectionManager.getNmsEntityPose(entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name()); + return v1_18ReflectionManager.getNmsEntityPose( + entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name()); } return Enum.valueOf(entityPoseClass, entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name()); @@ -2263,7 +2239,8 @@ public class ReflectionManager { return; } - Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType, NmsVersion.v1_18.isSupported() ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName); + Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType, + NmsVersion.v1_18.isSupported() ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName); if (nmsEntity == null) { DisguiseUtilities.getLogger().warning("Entity not found! (" + nmsEntityName + ")"); diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java index a033b514..7e961ed4 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java @@ -65,7 +65,7 @@ public class CompileMethods { list.add(sound.toString()); } - File soundsFile = new File("plugin/target/classes/ANTI_PIRACY_ENCRYPTION"); + File soundsFile = new File("plugin/target/classes/ANTI_PIRACY_SECRET_FILE"); try (FileOutputStream fos = new FileOutputStream(soundsFile)) { byte[] array = String.join("\n", list).getBytes(StandardCharsets.UTF_8); diff --git a/v1_18_R1/src/main/java/me/libraryaddict/disguise/v1_18/utilities/reflection/ReflectionManager.java b/v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18/ReflectionManager.java similarity index 99% rename from v1_18_R1/src/main/java/me/libraryaddict/disguise/v1_18/utilities/reflection/ReflectionManager.java rename to v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18/ReflectionManager.java index 2106d68c..a1b2a794 100644 --- a/v1_18_R1/src/main/java/me/libraryaddict/disguise/v1_18/utilities/reflection/ReflectionManager.java +++ b/v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18/ReflectionManager.java @@ -1,4 +1,4 @@ -package me.libraryaddict.disguise.v1_18.utilities.reflection; +package me.libraryaddict.disguise.utilities.reflection.v1_18; import com.comphenix.protocol.wrappers.*; import com.comphenix.protocol.wrappers.EnumWrappers.Direction;