Migrate reflections to mojang mapped by default

This commit is contained in:
Lixfel
2025-01-06 16:44:10 +01:00
parent 94a1ed3569
commit 9888700273
44 changed files with 216 additions and 110 deletions
@@ -33,14 +33,14 @@ import java.util.Map;
public class BlockIdWrapper14 implements BlockIdWrapper {
private static final Class<?> chunkProviderServer = Reflection.getClass("net.minecraft.server.level.ChunkProviderServer");
private static final Class<?> chunkProviderServer = Reflection.getClass("net.minecraft.server.level.ServerChunkCache");
private static final Reflection.Method getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer);
private static final Class<?> playerChunkMap = Reflection.getClass("net.minecraft.server.level.PlayerChunkMap");
private static final Class<?> playerChunkMap = Reflection.getClass("net.minecraft.server.level.ChunkMap");
private static final Reflection.Field<?> getPlayerChunkMap = Reflection.getField(chunkProviderServer, playerChunkMap, 0);
private static final Reflection.Field<? extends Map> entityTrackers = Core.getVersion() > 15 ? Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0) : Reflection.getField(playerChunkMap, org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap.class, 0);
private static final Class<?> block = Reflection.getClass("net.minecraft.world.level.block.Block");
private static final Class<?> iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.IBlockData");
private static final Class<?> blockPosition = Reflection.getClass("net.minecraft.core.BlockPosition");
private static final Class<?> iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.BlockState");
private static final Class<?> blockPosition = Reflection.getClass("net.minecraft.core.BlockPos");
private final Map trackers;
public BlockIdWrapper14() {
@@ -70,7 +70,7 @@ public class BlockIdWrapper14 implements BlockIdWrapper {
flagDirty.invoke(getChunkProvider.invoke(nworld), pos);
}
private static final Class<?> entityTracker = Reflection.getClass("net.minecraft.server.level.PlayerChunkMap$EntityTracker");
private static final Class<?> entityTracker = Reflection.getClass("net.minecraft.server.level.ChunkMap$TrackedEntity");
private static final Reflection.Method updatePlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "b" : "updatePlayer", entityPlayer);
@Override
public void trackEntity(Player player, Entity entity) {
@@ -43,7 +43,7 @@ import java.util.Map;
public class BountifulWrapper9 implements BountifulWrapper {
private static final Class<?> enumHand = Reflection.getClass("net.minecraft.world.EnumHand");
private static final Class<?> enumHand = Reflection.getClass("net.minecraft.world.InteractionHand");
private static final Object mainHand = enumHand.getEnumConstants()[0];
private static final Reflection.Field<?> blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0);
@@ -217,7 +217,7 @@ public class Kit {
private static final Class<?> itemStack = Reflection.getClass("net.minecraft.world.item.ItemStack");
private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.inventory.CraftItemStack"), "asNMSCopy", itemStack, ItemStack.class);
private static final Class<?> nbtTagCompound = Reflection.getClass("net.minecraft.nbt.NBTTagCompound");
private static final Class<?> nbtTagCompound = Reflection.getClass("net.minecraft.nbt.CompoundTag");
private static final Reflection.Method getTag = Reflection.getTypedMethod(itemStack, null, nbtTagCompound);
private static final Reflection.Method getKeys = Reflection.getTypedMethod(nbtTagCompound, null, Set.class);
public static boolean hasItems(ItemStack stack) {
@@ -41,7 +41,7 @@ public class ArrowStopper {
new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1);
}
private static final Class<?> entityArrow = Reflection.getClass("net.minecraft.world.entity.projectile.EntityArrow");
private static final Class<?> entityArrow = Reflection.getClass("net.minecraft.world.entity.projectile.AbstractArrow");
private void run() {
Recording.iterateOverEntities(entityArrow::isInstance, entity -> {
Projectile arrow = (Projectile) entity;
@@ -43,7 +43,7 @@ public class ClickAnalyzer {
public ClickAnalyzer() {
TinyProtocol.instance.addFilter(Recording.blockPlacePacket, this::onBlockPlace);
if(Core.getVersion() > 8)
TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInUseItem"), this::onBlockPlace);
TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"), this::onBlockPlace);
}
public Object onBlockPlace(Player player, Object packet) {
@@ -77,7 +77,7 @@ public class Recording implements Listener {
return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE;
}
public static final Class<?> primedTnt = Reflection.getClass("net.minecraft.world.entity.item.EntityTNTPrimed");
public static final Class<?> primedTnt = Reflection.getClass("net.minecraft.world.entity.item.PrimedTnt");
private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("net.minecraft.world.entity.Entity"), "getBukkitEntity", null);
public static void iterateOverEntities(Predicate<Object> filter, Consumer<Entity> consumer) {
CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(consumer);
@@ -129,7 +129,7 @@ public class Recording implements Listener {
GlobalRecorder.getInstance().entitySpeed(entity);
}
private static final Class<?> blockDigPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInBlockDig");
private static final Class<?> blockDigPacket = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket");
private static final Class<?> playerDigType = blockDigPacket.getDeclaredClasses()[0];
private static final Reflection.Field<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0);
private static final Object releaseUseItem = playerDigType.getEnumConstants()[5];
@@ -139,7 +139,7 @@ public class Recording implements Listener {
return packet;
}
public static final Class<?> blockPlacePacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayInBlockPlace");
public static final Class<?> blockPlacePacket = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemPacket");
private Object blockPlace(Player p, Object packet) {
boolean mainHand = BountifulWrapper.impl.mainHand(packet);
if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p))
@@ -29,11 +29,11 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public interface BlockIdWrapper {
Class<?> worldServer = Reflection.getClass("net.minecraft.server.level.WorldServer");
Class<?> worldServer = Reflection.getClass("net.minecraft.server.level.ServerLevel");
Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", worldServer);
Class<?> craftPlayer = Reflection.getClass("org.bukkit.craftbukkit.entity.CraftPlayer");
Class<?> entityPlayer = Reflection.getClass("net.minecraft.server.level.EntityPlayer");
Class<?> entityPlayer = Reflection.getClass("net.minecraft.server.level.ServerPlayer");
Reflection.Method getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer);
BlockIdWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin());
@@ -71,8 +71,8 @@ public class HullHider implements Listener {
packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider);
packetHiders.put(packetPlayOutExplosion, this::explosionHider);
posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutWorldParticles", Core.getVersion() >= 18 ? double.class : float.class, 1.0);
posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect", int.class, 8.0);
posHiderGenerator("net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket", Core.getVersion() >= 18 ? double.class : float.class, 1.0);
posHiderGenerator("net.minecraft.network.protocol.game.ClientboundSoundPacket", int.class, 8.0);
if(Core.getVersion() >= 9 && Core.getVersion() < 18)
posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect", int.class, 8.0);
@@ -198,15 +198,15 @@ public class HullHider implements Listener {
}
private static final Class<?> packetPlayOutWorldEvent = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutWorldEvent");
private static final Class<?> packetPlayOutWorldEvent = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelEventPacket");
private static final Reflection.Field<?> worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0);
public static final Reflection.Field<Integer> blockPositionY = Reflection.getField("net.minecraft.core.BaseBlockPosition", int.class, 1);
public static final Reflection.Field<Integer> blockPositionY = Reflection.getField("net.minecraft.core.Vec3i", int.class, 1);
private Object worldEventHider(Player player, Object packet) {
Object baseBlock = worldEventPosition.get(packet);
return packetHider(player, packet, new Location(Config.world, TechHider.blockPositionX.get(baseBlock), blockPositionY.get(baseBlock), TechHider.blockPositionZ.get(baseBlock)));
}
private static final Class<?> packetPlayOutExplosion = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutExplosion");
private static final Class<?> packetPlayOutExplosion = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket");
private static final Reflection.Field<List> explosionBlocks = Reflection.getField(packetPlayOutExplosion, List.class, 0);
private static final Function<Object, Location> explosionLocation = posPacketToLocation(packetPlayOutExplosion, double.class, 1.0);
private Object explosionHider(Player player, Object packet) {