🐛 Fixed bugs in the code
This commit is contained in:
parent
ed127b7e71
commit
ba1b3e515f
5 changed files with 107 additions and 13 deletions
37
pom.xml
37
pom.xml
|
@ -40,6 +40,13 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>nexus-releases</id>
|
||||
<url>https://repo.sbdevelopment.tech/repository/maven-releases/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -73,6 +80,33 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.0.0-M2</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>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
|
@ -102,6 +136,7 @@
|
|||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bergerkiller.bukkit</groupId>
|
||||
|
@ -112,7 +147,7 @@
|
|||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>4.8.0</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -73,7 +73,7 @@ public class MapSender {
|
|||
}
|
||||
|
||||
private static final Class<?> packetPlayOutMapClass = ReflectionUtil.getNMSClass("network.protocol.game", "PacketPlayOutMap");
|
||||
private static final Class<?> worldMapData = ReflectionUtil.supports(17) ? ReflectionUtil.getNMSClass("world.level.saveddata.maps", "WorldMap") : null;
|
||||
private static final Class<?> worldMapData = ReflectionUtil.supports(17) ? ReflectionUtil.getNMSClass("world.level.saveddata.maps", "WorldMap$b") : null;
|
||||
|
||||
/**
|
||||
* Send a map to a player
|
||||
|
|
|
@ -47,9 +47,9 @@ public class MapWrapper {
|
|||
this.content = image;
|
||||
}
|
||||
|
||||
private static final Class<?> craftStackClass = ReflectionUtil.getCraftClass("CraftItemStack");
|
||||
private static final Class<?> craftStackClass = ReflectionUtil.getCraftClass("inventory.CraftItemStack");
|
||||
private static final Class<?> setSlotPacketClass = ReflectionUtil.getNMSClass("network.protocol.game", "PacketPlayOutSetSlot");
|
||||
private static final Class<?> tagCompoundClass = ReflectionUtil.getCraftClass("NBTTagCompound");
|
||||
private static final Class<?> tagCompoundClass = ReflectionUtil.getNMSClass("nbt", "NBTTagCompound");
|
||||
private static final Class<?> entityClass = ReflectionUtil.getNMSClass("world.entity", "Entity");
|
||||
private static final Class<?> dataWatcherClass = ReflectionUtil.getNMSClass("network.syncher", "DataWatcher");
|
||||
private static final Class<?> entityMetadataPacketClass = ReflectionUtil.getNMSClass("network.protocol.game", "PacketPlayOutEntityMetadata");
|
||||
|
@ -260,7 +260,7 @@ public class MapWrapper {
|
|||
}
|
||||
|
||||
ReflectionUtil.callMethod(nbtObject, ReflectionUtil.supports(18) ? "a" : "setInt", "map", mapId);
|
||||
Object dataWatcher = ReflectionUtil.callConstructor(dataWatcherClass, entityClass.cast(null));
|
||||
Object dataWatcher = ReflectionUtil.callConstructorNull(dataWatcherClass, entityClass);
|
||||
|
||||
Object packet = ReflectionUtil.callConstructor(entityMetadataPacketClass,
|
||||
entityId,
|
||||
|
@ -268,9 +268,9 @@ public class MapWrapper {
|
|||
true
|
||||
);
|
||||
|
||||
List<Object> list = new ArrayList<>();
|
||||
List list = new ArrayList<>();
|
||||
Object dataWatcherObject = ReflectionUtil.getDeclaredField(entityItemFrameClass, ReflectionUtil.supports(17) ? "ao" : ReflectionUtil.supports(14) ? "ITEM" : ReflectionUtil.supports(13) ? "e" : "c");
|
||||
Object dataWatcherItem = ReflectionUtil.callConstructor(dataWatcherItemClass, dataWatcherObject, nmsStack);
|
||||
Object dataWatcherItem = ReflectionUtil.callFirstConstructor(dataWatcherItemClass, dataWatcherObject, nmsStack);
|
||||
list.add(dataWatcherItem);
|
||||
ReflectionUtil.setDeclaredField(packet, "b", list);
|
||||
|
||||
|
|
|
@ -69,12 +69,18 @@ public class PacketListener extends PacketAdapter {
|
|||
if (event.getPacketType() == PacketType.Play.Client.USE_ENTITY) {
|
||||
int entityId = event.getPacket().getIntegers().read(0); //entityId
|
||||
WrappedEnumEntityUseAction action = event.getPacket().getEnumEntityUseActions().read(0);
|
||||
EnumWrappers.EntityUseAction actionEnum = action.getAction();
|
||||
EnumWrappers.Hand hand = action.getHand();
|
||||
Vector pos = action.getPosition();
|
||||
EnumWrappers.EntityUseAction actionEnum = null;
|
||||
EnumWrappers.Hand hand = null;
|
||||
Vector pos = null;
|
||||
try {
|
||||
actionEnum = action.getAction();
|
||||
hand = action.getHand();
|
||||
pos = action.getPosition();
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
|
||||
boolean async = !plugin.getServer().isPrimaryThread();
|
||||
MapInteractEvent interactEvent = new MapInteractEvent(event.getPlayer(), entityId, actionEnum.ordinal(), pos, hand.ordinal(), async);
|
||||
MapInteractEvent interactEvent = new MapInteractEvent(event.getPlayer(), entityId, actionEnum != null ? actionEnum.ordinal() : 0, pos, hand != null ? hand.ordinal() : 0, async);
|
||||
if (interactEvent.getFrame() != null && interactEvent.getMapWrapper() != null) {
|
||||
Bukkit.getPluginManager().callEvent(interactEvent);
|
||||
if (interactEvent.isCancelled()) event.setCancelled(true);
|
||||
|
|
|
@ -36,7 +36,9 @@ 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.concurrent.CompletableFuture;
|
||||
|
||||
|
@ -191,12 +193,13 @@ 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;
|
||||
return clazz;
|
||||
}
|
||||
|
||||
private static Class<?>[] toParamTypes(Object... params) {
|
||||
return Arrays.stream(params)
|
||||
.map(obj -> wrapperToPrimitive(obj.getClass()))
|
||||
.map(obj -> obj != null ? wrapperToPrimitive(obj.getClass()) : null)
|
||||
.toArray(Class<?>[]::new);
|
||||
}
|
||||
|
||||
|
@ -210,6 +213,32 @@ public class ReflectionUtil {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object callConstructorNull(Class<?> clazz, Class<?> paramClass) {
|
||||
try {
|
||||
Constructor<?> con = clazz.getConstructor(paramClass);
|
||||
con.setAccessible(true);
|
||||
return con.newInstance(clazz.cast(null));
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException |
|
||||
InvocationTargetException ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object callFirstConstructor(Class<?> clazz, Object... params) {
|
||||
try {
|
||||
Constructor<?> con = clazz.getConstructors()[0];
|
||||
con.setAccessible(true);
|
||||
return con.newInstance(params);
|
||||
} catch (IllegalAccessException | InstantiationException |
|
||||
InvocationTargetException ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object callConstructor(Class<?> clazz, Object... params) {
|
||||
try {
|
||||
|
@ -236,6 +265,18 @@ public class ReflectionUtil {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object callMethod(Class<?> clazz, String method, Object... params) {
|
||||
try {
|
||||
Method m = clazz.getMethod(method, toParamTypes(params));
|
||||
m.setAccessible(true);
|
||||
return m.invoke(null, params);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object callMethod(Object obj, String method, Object... params) {
|
||||
try {
|
||||
|
@ -272,6 +313,18 @@ public class ReflectionUtil {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object getDeclaredField(Class<?> clazz, String field) {
|
||||
try {
|
||||
Field f = clazz.getDeclaredField(field);
|
||||
f.setAccessible(true);
|
||||
return f.get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object getDeclaredField(Object object, String field) {
|
||||
try {
|
||||
|
@ -288,7 +341,7 @@ public class ReflectionUtil {
|
|||
try {
|
||||
Field f = object.getClass().getDeclaredField(field);
|
||||
f.setAccessible(true);
|
||||
f.set(object, toParamTypes(value));
|
||||
f.set(object, value);
|
||||
} catch (NoSuchFieldException | IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue