diff --git a/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapSender.java b/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapSender.java index f5f3393..56fcaed 100644 --- a/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapSender.java +++ b/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapSender.java @@ -123,7 +123,7 @@ public class MapSender { id, //ID (byte) 0, //Scale, 0 = 1 block per pixel false, //Show icons - new ArrayList<>(), //Icons + new ReflectionUtil.CollectionParam<>(), //Icons updateData ); } else if (ReflectionUtil.supports(14)) { //1.16-1.14 @@ -132,7 +132,7 @@ public class MapSender { (byte) 0, //Scale, 0 = 1 block per pixel false, //Tracking position false, //Locked - new ArrayList<>(), //Icons + new ReflectionUtil.CollectionParam<>(), //Icons content.array, //Data content.minX, //X pos content.minY, //Y pos @@ -144,7 +144,7 @@ public class MapSender { id, //ID (byte) 0, //Scale, 0 = 1 block per pixel false, //??? - new ArrayList<>(), //Icons + new ReflectionUtil.CollectionParam<>(), //Icons content.array, //Data content.minX, //X pos content.minY, //Y pos diff --git a/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapWrapper.java b/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapWrapper.java index 6ae84d8..d572ec4 100644 --- a/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapWrapper.java +++ b/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapWrapper.java @@ -31,7 +31,11 @@ import tech.sbdevelopment.mapreflectionapi.api.exceptions.MapLimitExceededExcept import tech.sbdevelopment.mapreflectionapi.managers.Configuration; import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtil; -import java.util.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; /** * A {@link MapWrapper} wraps one image. @@ -333,12 +337,21 @@ public class MapWrapper extends AbstractMapWrapper { } Object dataWatcherObject = ReflectionUtil.getDeclaredField(entityItemFrameClass, dataWatcherObjectName); - List list = new ArrayList<>(); + ReflectionUtil.ListParam list = new ReflectionUtil.ListParam<>(); Object packet; - if (ReflectionUtil.supports(19, 3)) { //1.19.3 - Object dataWatcherField = ReflectionUtil.getDeclaredField(dataWatcherClass, "b"); - Object dataWatcherItem = ReflectionUtil.callDeclaredMethod(dataWatcherField, "a", dataWatcherObject, nmsStack); + if (ReflectionUtil.supports(19, 2)) { //1.19.3 + Class dataWatcherRecordClass = ReflectionUtil.getNMSClass("network.syncher", "DataWatcher$b"); + // Sadly not possible to use ReflectionUtil (in its current state), because of the Object parameter + Object dataWatcherItem; + try { + Method m = dataWatcherRecordClass.getMethod("a", dataWatcherObject.getClass(), Object.class); + m.setAccessible(true); + dataWatcherItem = m.invoke(null, dataWatcherObject, nmsStack); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + ex.printStackTrace(); + return; + } list.add(dataWatcherItem); packet = ReflectionUtil.callConstructor(entityMetadataPacketClass, diff --git a/src/main/java/tech/sbdevelopment/mapreflectionapi/utils/ReflectionUtil.java b/src/main/java/tech/sbdevelopment/mapreflectionapi/utils/ReflectionUtil.java index 19ee0d9..324a27f 100644 --- a/src/main/java/tech/sbdevelopment/mapreflectionapi/utils/ReflectionUtil.java +++ b/src/main/java/tech/sbdevelopment/mapreflectionapi/utils/ReflectionUtil.java @@ -31,10 +31,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Objects; +import java.util.*; import java.util.concurrent.CompletableFuture; /** @@ -200,6 +197,24 @@ public class ReflectionUtil { return VER >= major && VER_MINOR >= minor; } + /** + * Helper class converted to {@link List} + * + * @param The storage type + */ + public static class ListParam extends ArrayList { + + } + + /** + * Helper class converted to {@link Collection} + * + * @param The storage type + */ + public static class CollectionParam extends ArrayList { + + } + private static Class wrapperToPrimitive(Class clazz) { if (clazz == Boolean.class) return boolean.class; if (clazz == Integer.class) return int.class; @@ -210,7 +225,10 @@ public class ReflectionUtil { if (clazz == Byte.class) return byte.class; if (clazz == Void.class) return void.class; if (clazz == Character.class) return char.class; - if (clazz == ArrayList.class) return Collection.class; + if (clazz == CollectionParam.class) return Collection.class; + if (clazz == ListParam.class) return List.class; + if (clazz == ArrayList.class) return Collection.class; //LEGACY! + if (clazz == HashMap.class) return Map.class; return clazz; }