Merge pull request #13 from SBDPlugins/development

v1.4.2: 1.19.3 support
This commit is contained in:
Stijn Bannink 2022-12-22 20:21:24 +01:00 committed by GitHub
commit 7cdcc7b222
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 54 deletions

View file

@ -8,8 +8,9 @@ First, include the API using Maven:
```xml
<repository>
<id>sbdevelopment-repo</id>
<url>https://repo.sbdevelopment.tech/repository/maven-releases/</url>
<id>sbdevelopment-releases</id>
<name>SBDevelopment Repository</name>
<url>https://repo.sbdevelopment.tech/releases</url>
</repository>
<dependency>

35
pom.xml
View file

@ -24,7 +24,7 @@
<groupId>tech.sbdevelopment</groupId>
<artifactId>MapReflectionAPI</artifactId>
<version>1.4.1</version>
<version>1.4.2</version>
<packaging>jar</packaging>
<name>MapReflectionAPI</name>
@ -38,8 +38,8 @@
<distributionManagement>
<repository>
<id>nexus-releases</id>
<url>https://repo.sbdevelopment.tech/repository/maven-releases/</url>
<id>sbdevelopment-repo</id>
<url>https://repo.sbdevelopment.tech/releases</url>
</repository>
</distributionManagement>
@ -86,33 +86,6 @@
</execution>
</executions>
</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>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
@ -188,7 +161,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version>
<version>1.19.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View file

@ -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

View file

@ -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.
@ -317,14 +321,6 @@ public class MapWrapper extends AbstractMapWrapper {
private void sendItemFramePacket(Player player, int entityId, ItemStack stack, int mapId) {
Object nmsStack = createCraftItemStack(stack, mapId);
Object dataWatcher = ReflectionUtil.callConstructorNull(dataWatcherClass, entityClass);
Object packet = ReflectionUtil.callConstructor(entityMetadataPacketClass,
entityId,
dataWatcher, //dummy watcher!
true
);
String dataWatcherObjectName;
if (ReflectionUtil.supports(19)) { //1.19, same as 1.17 and 1.18(.2)
dataWatcherObjectName = "ao";
@ -340,10 +336,41 @@ public class MapWrapper extends AbstractMapWrapper {
dataWatcherObjectName = "c";
}
Object dataWatcherObject = ReflectionUtil.getDeclaredField(entityItemFrameClass, dataWatcherObjectName);
ReflectionUtil.ListParam list = new ReflectionUtil.ListParam<>();
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 list = new ArrayList<>();
list.add(dataWatcherItem);
ReflectionUtil.setDeclaredField(packet, "b", list);
}
ReflectionUtil.sendPacketSync(player, packet);
}

View file

@ -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 <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) {
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;
}