Merge pull request #13 from SBDPlugins/development
v1.4.2: 1.19.3 support
This commit is contained in:
commit
7cdcc7b222
5 changed files with 73 additions and 54 deletions
|
@ -8,8 +8,9 @@ First, include the API using Maven:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<repository>
|
<repository>
|
||||||
<id>sbdevelopment-repo</id>
|
<id>sbdevelopment-releases</id>
|
||||||
<url>https://repo.sbdevelopment.tech/repository/maven-releases/</url>
|
<name>SBDevelopment Repository</name>
|
||||||
|
<url>https://repo.sbdevelopment.tech/releases</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
35
pom.xml
35
pom.xml
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
<groupId>tech.sbdevelopment</groupId>
|
<groupId>tech.sbdevelopment</groupId>
|
||||||
<artifactId>MapReflectionAPI</artifactId>
|
<artifactId>MapReflectionAPI</artifactId>
|
||||||
<version>1.4.1</version>
|
<version>1.4.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>MapReflectionAPI</name>
|
<name>MapReflectionAPI</name>
|
||||||
|
@ -38,8 +38,8 @@
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>nexus-releases</id>
|
<id>sbdevelopment-repo</id>
|
||||||
<url>https://repo.sbdevelopment.tech/repository/maven-releases/</url>
|
<url>https://repo.sbdevelopment.tech/releases</url>
|
||||||
</repository>
|
</repository>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
|
@ -86,33 +86,6 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
|
||||||
<version>3.0.0</version>
|
|
||||||
<configuration>
|
|
||||||
<skip>true</skip>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
|
||||||
<version>1.6.13</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>default-deploy</id>
|
|
||||||
<phase>deploy</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>deploy</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<serverId>nexus-releases</serverId>
|
|
||||||
<nexusUrl>https://repo.sbdevelopment.tech/</nexusUrl>
|
|
||||||
<skipStaging>true</skipStaging>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok-maven-plugin</artifactId>
|
<artifactId>lombok-maven-plugin</artifactId>
|
||||||
|
@ -188,7 +161,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.19.2-R0.1-SNAPSHOT</version>
|
<version>1.19.3-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class MapSender {
|
||||||
id, //ID
|
id, //ID
|
||||||
(byte) 0, //Scale, 0 = 1 block per pixel
|
(byte) 0, //Scale, 0 = 1 block per pixel
|
||||||
false, //Show icons
|
false, //Show icons
|
||||||
new ArrayList<>(), //Icons
|
new ReflectionUtil.CollectionParam<>(), //Icons
|
||||||
updateData
|
updateData
|
||||||
);
|
);
|
||||||
} else if (ReflectionUtil.supports(14)) { //1.16-1.14
|
} else if (ReflectionUtil.supports(14)) { //1.16-1.14
|
||||||
|
@ -132,7 +132,7 @@ public class MapSender {
|
||||||
(byte) 0, //Scale, 0 = 1 block per pixel
|
(byte) 0, //Scale, 0 = 1 block per pixel
|
||||||
false, //Tracking position
|
false, //Tracking position
|
||||||
false, //Locked
|
false, //Locked
|
||||||
new ArrayList<>(), //Icons
|
new ReflectionUtil.CollectionParam<>(), //Icons
|
||||||
content.array, //Data
|
content.array, //Data
|
||||||
content.minX, //X pos
|
content.minX, //X pos
|
||||||
content.minY, //Y pos
|
content.minY, //Y pos
|
||||||
|
@ -144,7 +144,7 @@ public class MapSender {
|
||||||
id, //ID
|
id, //ID
|
||||||
(byte) 0, //Scale, 0 = 1 block per pixel
|
(byte) 0, //Scale, 0 = 1 block per pixel
|
||||||
false, //???
|
false, //???
|
||||||
new ArrayList<>(), //Icons
|
new ReflectionUtil.CollectionParam<>(), //Icons
|
||||||
content.array, //Data
|
content.array, //Data
|
||||||
content.minX, //X pos
|
content.minX, //X pos
|
||||||
content.minY, //Y pos
|
content.minY, //Y pos
|
||||||
|
|
|
@ -31,7 +31,11 @@ import tech.sbdevelopment.mapreflectionapi.api.exceptions.MapLimitExceededExcept
|
||||||
import tech.sbdevelopment.mapreflectionapi.managers.Configuration;
|
import tech.sbdevelopment.mapreflectionapi.managers.Configuration;
|
||||||
import tech.sbdevelopment.mapreflectionapi.utils.ReflectionUtil;
|
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.
|
* A {@link MapWrapper} wraps one image.
|
||||||
|
@ -317,14 +321,6 @@ public class MapWrapper extends AbstractMapWrapper {
|
||||||
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
|
||||||
Object nmsStack = createCraftItemStack(stack, mapId);
|
Object nmsStack = createCraftItemStack(stack, mapId);
|
||||||
|
|
||||||
Object dataWatcher = ReflectionUtil.callConstructorNull(dataWatcherClass, entityClass);
|
|
||||||
|
|
||||||
Object packet = ReflectionUtil.callConstructor(entityMetadataPacketClass,
|
|
||||||
entityId,
|
|
||||||
dataWatcher, //dummy watcher!
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
String dataWatcherObjectName;
|
String dataWatcherObjectName;
|
||||||
if (ReflectionUtil.supports(19)) { //1.19, same as 1.17 and 1.18(.2)
|
if (ReflectionUtil.supports(19)) { //1.19, same as 1.17 and 1.18(.2)
|
||||||
dataWatcherObjectName = "ao";
|
dataWatcherObjectName = "ao";
|
||||||
|
@ -340,10 +336,41 @@ public class MapWrapper extends AbstractMapWrapper {
|
||||||
dataWatcherObjectName = "c";
|
dataWatcherObjectName = "c";
|
||||||
}
|
}
|
||||||
Object dataWatcherObject = ReflectionUtil.getDeclaredField(entityItemFrameClass, dataWatcherObjectName);
|
Object dataWatcherObject = ReflectionUtil.getDeclaredField(entityItemFrameClass, dataWatcherObjectName);
|
||||||
Object dataWatcherItem = ReflectionUtil.callFirstConstructor(dataWatcherItemClass, dataWatcherObject, nmsStack);
|
|
||||||
List list = new ArrayList<>();
|
ReflectionUtil.ListParam list = new ReflectionUtil.ListParam<>();
|
||||||
list.add(dataWatcherItem);
|
|
||||||
ReflectionUtil.setDeclaredField(packet, "b", list);
|
Object packet;
|
||||||
|
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,
|
||||||
|
entityId,
|
||||||
|
list
|
||||||
|
);
|
||||||
|
} else { //1.19.2 or lower
|
||||||
|
Object dataWatcher = ReflectionUtil.callConstructorNull(dataWatcherClass, entityClass);
|
||||||
|
|
||||||
|
packet = ReflectionUtil.callConstructor(entityMetadataPacketClass,
|
||||||
|
entityId,
|
||||||
|
dataWatcher, //dummy watcher!
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
Object dataWatcherItem = ReflectionUtil.callFirstConstructor(dataWatcherItemClass, dataWatcherObject, nmsStack);
|
||||||
|
list.add(dataWatcherItem);
|
||||||
|
ReflectionUtil.setDeclaredField(packet, "b", list);
|
||||||
|
}
|
||||||
|
|
||||||
ReflectionUtil.sendPacketSync(player, packet);
|
ReflectionUtil.sendPacketSync(player, packet);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,7 @@ import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -200,6 +197,24 @@ public class ReflectionUtil {
|
||||||
return VER >= major && VER_MINOR >= minor;
|
return VER >= major && VER_MINOR >= minor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class converted to {@link List}
|
||||||
|
*
|
||||||
|
* @param <E> The storage type
|
||||||
|
*/
|
||||||
|
public static class ListParam<E> extends ArrayList<E> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class converted to {@link Collection}
|
||||||
|
*
|
||||||
|
* @param <E> The storage type
|
||||||
|
*/
|
||||||
|
public static class CollectionParam<E> extends ArrayList<E> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static Class<?> wrapperToPrimitive(Class<?> clazz) {
|
private static Class<?> wrapperToPrimitive(Class<?> clazz) {
|
||||||
if (clazz == Boolean.class) return boolean.class;
|
if (clazz == Boolean.class) return boolean.class;
|
||||||
if (clazz == Integer.class) return int.class;
|
if (clazz == Integer.class) return int.class;
|
||||||
|
@ -210,7 +225,10 @@ public class ReflectionUtil {
|
||||||
if (clazz == Byte.class) return byte.class;
|
if (clazz == Byte.class) return byte.class;
|
||||||
if (clazz == Void.class) return void.class;
|
if (clazz == Void.class) return void.class;
|
||||||
if (clazz == Character.class) return char.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;
|
return clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue