mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-12-04 13:54:35 +01:00
Fix tracking/untracking of entity trackers not being called correctly, thus breaking some of paper's API. Thanks TonytheMacaroni!
This commit is contained in:
parent
862ef03345
commit
359dfcaf65
@ -175,12 +175,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkProvider();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Map<Integer, ChunkMap.TrackedEntity> entityMap = chunkMap.G;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.decoration.Motive;
|
||||
@ -55,7 +54,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -177,12 +175,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkSource();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.decoration.Motive;
|
||||
@ -56,7 +55,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -179,12 +177,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkSource();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.decoration.PaintingVariant;
|
||||
@ -56,7 +55,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -178,12 +176,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkSource();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -195,12 +195,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkSource();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.decoration.PaintingVariant;
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
@ -58,7 +57,6 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -192,12 +190,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkSource();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -190,12 +190,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkSource();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -199,12 +199,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkSource();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -211,12 +211,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkSource();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -214,12 +214,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkSource();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -214,12 +214,19 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
public ChunkMap.TrackedEntity getEntityTracker(Entity target) {
|
||||
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
|
||||
ServerChunkCache chunkSource = world.getChunkSource();
|
||||
ChunkMap chunkMap = chunkSource.chunkMap;
|
||||
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
|
||||
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
|
||||
|
||||
return entityMap.get(target.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
|
||||
ChunkMap.TrackedEntity trackedEntity = getEntityTracker(target);
|
||||
|
||||
if (trackedEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1889,7 +1889,9 @@ public class DisguiseUtilities {
|
||||
}
|
||||
}, 2);
|
||||
} else {
|
||||
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||
final Object entityTracker = ReflectionManager.getEntityTracker(disguise.getEntity());
|
||||
final Object entityTrackerEntry =
|
||||
!NmsVersion.v1_14.isSupported() ? entityTracker : ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||
|
||||
if (entityTrackerEntry == null) {
|
||||
return;
|
||||
@ -1905,7 +1907,7 @@ public class DisguiseUtilities {
|
||||
continue;
|
||||
}
|
||||
|
||||
ReflectionManager.clearEntityTracker(entityTrackerEntry, p);
|
||||
ReflectionManager.clearEntityTracker(entityTracker, p);
|
||||
|
||||
WrapperPlayServerDestroyEntities destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
||||
|
||||
@ -1913,7 +1915,7 @@ public class DisguiseUtilities {
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||
try {
|
||||
ReflectionManager.addEntityTracker(entityTrackerEntry, p);
|
||||
ReflectionManager.addEntityTracker(entityTracker, p);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -1938,8 +1940,9 @@ public class DisguiseUtilities {
|
||||
|
||||
if (entity.isValid()) {
|
||||
try {
|
||||
|
||||
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity);
|
||||
final Object entityTracker = ReflectionManager.getEntityTracker(entity);
|
||||
final Object entityTrackerEntry =
|
||||
NmsVersion.v1_14.isSupported() ? entityTracker : ReflectionManager.getEntityTrackerEntry(entity);
|
||||
|
||||
if (entityTrackerEntry != null) {
|
||||
Set trackedPlayers = ReflectionManager.getClonedTrackedPlayers(entityTrackerEntry);
|
||||
@ -1952,14 +1955,14 @@ public class DisguiseUtilities {
|
||||
continue;
|
||||
}
|
||||
|
||||
ReflectionManager.clearEntityTracker(entityTrackerEntry, p);
|
||||
ReflectionManager.clearEntityTracker(entityTracker, p);
|
||||
|
||||
WrapperPlayServerDestroyEntities destroyPacket = getDestroyPacket(entity.getEntityId());
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, destroyPacket);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||
try {
|
||||
ReflectionManager.addEntityTracker(entityTrackerEntry, p);
|
||||
ReflectionManager.addEntityTracker(entityTracker, p);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -2001,7 +2004,9 @@ public class DisguiseUtilities {
|
||||
}, 2);
|
||||
}
|
||||
|
||||
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||
final Object entityTracker = ReflectionManager.getEntityTracker(disguise.getEntity());
|
||||
final Object entityTrackerEntry =
|
||||
!NmsVersion.v1_14.isSupported() ? entityTracker : ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||
|
||||
if (entityTrackerEntry != null) {
|
||||
Set trackedPlayers = ReflectionManager.getClonedTrackedPlayers(entityTrackerEntry);
|
||||
@ -2013,14 +2018,14 @@ public class DisguiseUtilities {
|
||||
if (disguise.getEntity() == player || !disguise.canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
ReflectionManager.clearEntityTracker(entityTrackerEntry, p);
|
||||
ReflectionManager.clearEntityTracker(entityTracker, p);
|
||||
|
||||
WrapperPlayServerDestroyEntities destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, destroyPacket);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
|
||||
try {
|
||||
ReflectionManager.addEntityTracker(entityTrackerEntry, p);
|
||||
ReflectionManager.addEntityTracker(entityTracker, p);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
@ -201,20 +201,26 @@ public class ReflectionManager {
|
||||
nmsReflection = getReflectionManager(getVersion());
|
||||
|
||||
getGameProfile = getCraftMethod("CraftPlayer", "getProfile");
|
||||
trackedPlayers = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers");
|
||||
trackedPlayers = getNmsField("EntityTrackerEntry", "trackedPlayers");
|
||||
|
||||
if (DisguiseUtilities.isRunningPaper() && !NmsVersion.v1_17.isSupported()) {
|
||||
trackedPlayersMap = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap");
|
||||
// In 1.12 to 1.13, it's all in EntityTrackerEntry
|
||||
// In 1.14+, we have it in EntityTracker in PlayerChunkMap
|
||||
if (NmsVersion.v1_14.isSupported()) {
|
||||
clearEntityTracker = getNmsMethod("PlayerChunkMap$EntityTracker", "a", getNmsClass("EntityPlayer"));
|
||||
addEntityTracker = getNmsMethod("PlayerChunkMap$EntityTracker", "b", getNmsClass("EntityPlayer"));
|
||||
} else {
|
||||
clearEntityTracker = getNmsMethod("EntityTrackerEntry", "clear", getNmsClass("EntityPlayer"));
|
||||
addEntityTracker = getNmsMethod("EntityTrackerEntry", "updatePlayer", getNmsClass("EntityPlayer"));
|
||||
}
|
||||
|
||||
clearEntityTracker = ReflectionManager.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear",
|
||||
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
addEntityTracker = ReflectionManager.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer",
|
||||
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
trackerIsMoving = ReflectionManager.getNmsField("EntityTrackerEntry", NmsVersion.v1_20_R2.isSupported() ? "i" :
|
||||
trackerIsMoving = getNmsField("EntityTrackerEntry", NmsVersion.v1_20_R2.isSupported() ? "i" :
|
||||
NmsVersion.v1_19_R1.isSupported() ? "p" :
|
||||
NmsVersion.v1_17.isSupported() ? "r" : NmsVersion.v1_14.isSupported() ? "q" : "isMoving");
|
||||
|
||||
if (DisguiseUtilities.isRunningPaper() && !NmsVersion.v1_17.isSupported()) {
|
||||
trackedPlayersMap = getNmsField("EntityTrackerEntry", "trackedPlayerMap");
|
||||
}
|
||||
|
||||
if (nmsReflection != null) {
|
||||
sessionService = nmsReflection.getMinecraftSessionService();
|
||||
} else {
|
||||
@ -359,6 +365,7 @@ public class ReflectionManager {
|
||||
} else {
|
||||
trackerField = getNmsField("WorldServer", "tracker");
|
||||
entitiesField = getNmsField("EntityTracker", "trackedEntities");
|
||||
|
||||
ihmGet = getNmsMethod("IntHashMap", "get", int.class);
|
||||
}
|
||||
|
||||
@ -407,7 +414,7 @@ public class ReflectionManager {
|
||||
return nmsReflection.hasInvul(entity);
|
||||
}
|
||||
|
||||
Object nmsEntity = ReflectionManager.getNmsEntity(entity);
|
||||
Object nmsEntity = getNmsEntity(entity);
|
||||
|
||||
try {
|
||||
if (entity instanceof LivingEntity) {
|
||||
@ -926,6 +933,22 @@ public class ReflectionManager {
|
||||
return getCraftConstructor(getCraftClass(className), parameters);
|
||||
}
|
||||
|
||||
public static Object getEntityTracker(Entity target) throws Exception {
|
||||
if (nmsReflection != null) {
|
||||
return nmsReflection.getEntityTracker(target);
|
||||
} else if (!NmsVersion.v1_14.isSupported()) {
|
||||
return getEntityTrackerEntry(target);
|
||||
}
|
||||
|
||||
Object world = getWorldServer(target.getWorld());
|
||||
|
||||
Object chunkProvider = chunkProviderField.get(world);
|
||||
Object chunkMap = chunkMapField.get(chunkProvider);
|
||||
Map trackedEntities = (Map) trackedEntitiesField.get(chunkMap);
|
||||
|
||||
return trackedEntities.get(target.getEntityId());
|
||||
}
|
||||
|
||||
public static Object getEntityTrackerEntry(Entity target) throws Exception {
|
||||
if (nmsReflection != null) {
|
||||
return nmsReflection.getEntityTrackerEntry(target);
|
||||
@ -1166,22 +1189,22 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void clearEntityTracker(Object tracker, Object player) {
|
||||
clearEntityTracker.invoke(tracker, player);
|
||||
public static void clearEntityTracker(Object trackerEntry, Object player) {
|
||||
clearEntityTracker.invoke(trackerEntry, player);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void addEntityTracker(Object tracker, Object player) {
|
||||
addEntityTracker.invoke(tracker, player);
|
||||
public static void addEntityTracker(Object trackerEntry, Object player) {
|
||||
addEntityTracker.invoke(trackerEntry, player);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static void addEntityToTrackedMap(Object tracker, Player player) {
|
||||
Object nmsEntity = ReflectionManager.getPlayerConnectionOrPlayer(player);
|
||||
Object nmsEntity = getPlayerConnectionOrPlayer(player);
|
||||
|
||||
// Add the player to their own entity tracker
|
||||
if (!DisguiseUtilities.isRunningPaper() || NmsVersion.v1_17.isSupported()) {
|
||||
ReflectionManager.getTrackedPlayers(tracker).add(nmsEntity);
|
||||
getTrackedPlayers(tracker).add(nmsEntity);
|
||||
} else {
|
||||
Map<Object, Object> map = ((Map<Object, Object>) trackedPlayersMap.get(tracker));
|
||||
map.put(nmsEntity, true);
|
||||
@ -1190,10 +1213,10 @@ public class ReflectionManager {
|
||||
|
||||
@SneakyThrows
|
||||
public static void removeEntityFromTracked(Object tracker, Player player) {
|
||||
Object nmsEntity = ReflectionManager.getPlayerConnectionOrPlayer(player);
|
||||
Object nmsEntity = getPlayerConnectionOrPlayer(player);
|
||||
|
||||
if (!DisguiseUtilities.isRunningPaper() || NmsVersion.v1_17.isSupported()) {
|
||||
ReflectionManager.getTrackedPlayers(tracker).remove(nmsEntity);
|
||||
getTrackedPlayers(tracker).remove(nmsEntity);
|
||||
} else {
|
||||
Map<Object, Object> map = ((Map<Object, Object>) trackedPlayersMap.get(tracker));
|
||||
map.remove(nmsEntity);
|
||||
@ -1240,7 +1263,7 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
try {
|
||||
return pingField.getInt(ReflectionManager.getNmsEntity(player));
|
||||
return pingField.getInt(getNmsEntity(player));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -2052,14 +2075,14 @@ public class ReflectionManager {
|
||||
private static void createNMSValues(DisguiseType disguiseType) {
|
||||
String nmsEntityName = toReadable(disguiseType.name());
|
||||
|
||||
Class nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
|
||||
Class nmsClass = getNmsClassIgnoreErrors("Entity" + nmsEntityName);
|
||||
|
||||
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
|
||||
String[] split = splitReadable(disguiseType.name());
|
||||
ArrayUtils.reverse(split);
|
||||
|
||||
nmsEntityName = StringUtils.join(split);
|
||||
nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
|
||||
nmsClass = getNmsClassIgnoreErrors("Entity" + nmsEntityName);
|
||||
|
||||
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
|
||||
nmsEntityName = null;
|
||||
@ -2180,18 +2203,18 @@ public class ReflectionManager {
|
||||
return;
|
||||
}
|
||||
|
||||
Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType,
|
||||
nmsReflection != null ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName);
|
||||
Object nmsEntity =
|
||||
createEntityInstance(disguiseType, nmsReflection != null ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName);
|
||||
|
||||
if (nmsEntity == null) {
|
||||
LibsDisguises.getInstance().getLogger().warning("Entity not found! (" + nmsEntityName + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
disguiseType.setTypeId(NmsVersion.v1_13.isSupported() ? ReflectionManager.getEntityType(disguiseType.getEntityType()) : null,
|
||||
ReflectionManager.getEntityTypeId(disguiseType.getEntityType()));
|
||||
disguiseType.setTypeId(NmsVersion.v1_13.isSupported() ? getEntityType(disguiseType.getEntityType()) : null,
|
||||
getEntityTypeId(disguiseType.getEntityType()));
|
||||
|
||||
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
|
||||
Entity bukkitEntity = getBukkitEntity(nmsEntity);
|
||||
|
||||
DisguiseValues disguiseValues =
|
||||
new DisguiseValues(disguiseType, bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
|
||||
@ -2222,8 +2245,8 @@ public class ReflectionManager {
|
||||
indexes.remove(metaIndex);
|
||||
|
||||
Object ourDefaultBukkit = metaIndex.getDefault();
|
||||
Object ourDefaultSerialized = ReflectionManager.convertMetaToSerialized(metaIndex, ourDefaultBukkit);
|
||||
Object minecraftDefaultBukkit = ReflectionManager.convertMetaFromSerialized(metaIndex, data.getValue());
|
||||
Object ourDefaultSerialized = convertMetaToSerialized(metaIndex, ourDefaultBukkit);
|
||||
Object minecraftDefaultBukkit = convertMetaFromSerialized(metaIndex, data.getValue());
|
||||
Object minecraftDefaultSerialized = data.getValue();
|
||||
|
||||
if (minecraftDefaultBukkit == null) {
|
||||
@ -2236,7 +2259,7 @@ public class ReflectionManager {
|
||||
|
||||
if (minecraftDefaultBukkit.getClass().getSimpleName().equals("CraftItemStack") &&
|
||||
ourDefaultBukkit.getClass().getSimpleName().equals("ItemStack")) {
|
||||
ourDefaultBukkit = ReflectionManager.getCraftItem((ItemStack) ourDefaultBukkit);
|
||||
ourDefaultBukkit = getCraftItem((ItemStack) ourDefaultBukkit);
|
||||
}
|
||||
|
||||
if (ourDefaultBukkit.getClass() != minecraftDefaultBukkit.getClass() || metaIndex.getDataType() != data.getType() ||
|
||||
@ -2279,7 +2302,7 @@ public class ReflectionManager {
|
||||
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
|
||||
|
||||
if (sound != null) {
|
||||
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
|
||||
Float soundStrength = getSoundModifier(nmsEntity);
|
||||
|
||||
if (soundStrength != null) {
|
||||
sound.setDamageAndIdleSoundVolume(soundStrength);
|
||||
@ -2293,20 +2316,20 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
// Get the bounding box
|
||||
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||
disguiseValues.setAdultBox(getBoundingBox(bukkitEntity));
|
||||
|
||||
if (bukkitEntity instanceof Ageable) {
|
||||
((Ageable) bukkitEntity).setBaby();
|
||||
|
||||
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||
disguiseValues.setBabyBox(getBoundingBox(bukkitEntity));
|
||||
} else if (bukkitEntity instanceof Zombie) {
|
||||
((Zombie) bukkitEntity).setBaby(true);
|
||||
|
||||
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||
disguiseValues.setBabyBox(getBoundingBox(bukkitEntity));
|
||||
} else if (bukkitEntity instanceof ArmorStand) {
|
||||
((ArmorStand) bukkitEntity).setSmall(true);
|
||||
|
||||
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||
disguiseValues.setBabyBox(getBoundingBox(bukkitEntity));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LibsDisguises.getInstance().getLogger()
|
||||
|
@ -52,6 +52,8 @@ public interface ReflectionManagerAbstract {
|
||||
|
||||
ItemStack getCraftItem(ItemStack bukkitItem);
|
||||
|
||||
Object getEntityTracker(Entity target) throws Exception;
|
||||
|
||||
Object getEntityTrackerEntry(Entity target) throws Exception;
|
||||
|
||||
Object getMinecraftServer();
|
||||
|
Loading…
Reference in New Issue
Block a user