From 3c48e7c02dd38b48475897f0579401a9a344da9a Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 15 May 2026 20:33:14 +0200 Subject: [PATCH 1/5] Remove most calls to Reflection.getClass --- .../fightsystem/commands/Commands.java | 6 ++-- .../fightsystem/listener/ArrowStopper.java | 4 +-- .../fightsystem/listener/ClickAnalyzer.java | 4 +-- .../fightsystem/listener/Recording.java | 11 +++--- .../fightsystem/utils/BlockIdWrapper.java | 10 +++--- .../fightsystem/utils/BountifulWrapper.java | 3 +- .../fightsystem/utils/CraftbukkitWrapper.java | 5 +-- .../steamwar/fightsystem/utils/HullHider.java | 9 +++-- .../fightsystem/utils/HullHiderWrapper.java | 3 +- .../de/steamwar/core/BountifulWrapper.java | 12 ++++--- .../de/steamwar/core/FlatteningWrapper.java | 36 +++++++++++-------- .../src/de/steamwar/core/ProtocolWrapper.java | 12 +++---- .../src/de/steamwar/core/TPSWatcher.java | 3 +- .../src/de/steamwar/core/WorldIdentifier.java | 2 +- .../de/steamwar/core/events/AntiNocom.java | 9 +++-- .../src/de/steamwar/entity/RBlockDisplay.java | 6 ++-- .../src/de/steamwar/entity/REntity.java | 24 +++++++------ .../src/de/steamwar/entity/REntityServer.java | 3 +- .../src/de/steamwar/entity/RTextDisplay.java | 3 +- .../network/handlers/ServerDataHandler.java | 7 ++-- .../src/de/steamwar/techhider/BlockIds.java | 15 +++++--- .../src/de/steamwar/techhider/ChunkHider.java | 9 +++-- .../src/de/steamwar/techhider/TechHider.java | 36 ++++++++++++------- 23 files changed, 141 insertions(+), 91 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java index 7119173e..5e4ecc45 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java @@ -19,7 +19,6 @@ package de.steamwar.fightsystem.commands; -import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; @@ -33,15 +32,14 @@ import lombok.experimental.UtilityClass; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; import org.bukkit.command.Command; -import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Player; @UtilityClass public class Commands { - private static final Reflection.Field commandMap = Reflection.getField("org.bukkit.craftbukkit.CraftServer", "commandMap", SimpleCommandMap.class); public static void injectCommand(Command cmd) { - commandMap.get(Bukkit.getServer()).register("FightSystem", cmd); + ((CraftServer) Bukkit.getServer()).getCommandMap().register("FightSystem", cmd); } private static void errNoTeam(Player p){ diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 19d2db5f..29ef298f 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -25,6 +25,7 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.utils.WorldOfColorWrapper; import de.steamwar.linkage.Linked; +import net.minecraft.world.entity.projectile.AbstractArrow; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -43,9 +44,8 @@ public class ArrowStopper { new StateDependentTask(Config.GameModeConfig.Techhider.Active, FightState.Running, this::run, 1, 1); } - private static final Class entityArrow = Reflection.getClass("net.minecraft.world.entity.projectile.AbstractArrow"); private void run() { - Recording.iterateOverEntities(entityArrow::isInstance, entity -> { + Recording.iterateOverEntities(AbstractArrow.class::isInstance, entity -> { Projectile arrow = (Projectile) entity; if (invalidEntity(arrow)) return; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java index 009a9bd4..f2834e31 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java @@ -20,11 +20,11 @@ package de.steamwar.fightsystem.listener; import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.Reflection; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.utils.CraftbukkitWrapper; import de.steamwar.linkage.Linked; +import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; import org.bukkit.entity.Player; import java.io.*; @@ -45,7 +45,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.ServerboundUseItemOnPacket"), this::onBlockPlace); + TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, this::onBlockPlace); } public Object onBlockPlace(Player player, Object packet) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index 1f23312b..24735f58 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -40,6 +40,9 @@ import de.steamwar.fightsystem.utils.CraftbukkitWrapper; import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.linkage.Linked; +import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket; +import net.minecraft.network.protocol.game.ServerboundUseItemPacket; +import net.minecraft.world.entity.item.PrimedTnt; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -79,8 +82,8 @@ 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.PrimedTnt"); - private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("net.minecraft.world.entity.Entity"), "getBukkitEntity", null); + public static final Class primedTnt = PrimedTnt.class; + private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(net.minecraft.world.entity.Entity.class, "getBukkitEntity", null); public static void iterateOverEntities(Predicate filter, Consumer consumer) { CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(consumer); } @@ -131,7 +134,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().entitySpeed(entity); } - private static final Class blockDigPacket = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket"); + private static final Class blockDigPacket = ServerboundPlayerActionPacket.class; 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]; @@ -141,7 +144,7 @@ public class Recording implements Listener { return packet; } - public static final Class blockPlacePacket = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemPacket"); + public static final Class blockPlacePacket = ServerboundUseItemPacket.class; private Object blockPlace(Player p, Object packet) { boolean mainHand = BountifulWrapper.impl.mainHand(packet); if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p)) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index db865f19..b6c3fd56 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -26,6 +26,7 @@ import de.steamwar.core.ProtocolWrapper; import de.steamwar.fightsystem.FightSystem; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.GameMode; import org.bukkit.Material; @@ -33,16 +34,17 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.block.CraftBlockState; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; public class BlockIdWrapper { - public static final Class worldServer = Reflection.getClass("net.minecraft.server.level.ServerLevel"); - public static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", worldServer); + public static final Class worldServer = ServerLevel.class; + public static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(CraftWorld.class, "getHandle", worldServer); - public static final Class craftPlayer = Reflection.getClass("org.bukkit.craftbukkit.entity.CraftPlayer"); - public static final Class entityPlayer = Reflection.getClass("net.minecraft.server.level.ServerPlayer"); + public static final Class craftPlayer = CraftPlayer.class; + public static final Class entityPlayer = ServerPlayer.class; public static final Reflection.Method getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer); public static final BlockIdWrapper impl = new BlockIdWrapper(); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java index ac31b2ac..2723f23d 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java @@ -24,6 +24,7 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.listener.Recording; import de.steamwar.fightsystem.record.GlobalRecorder; +import net.minecraft.world.InteractionHand; import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; @@ -44,7 +45,7 @@ import java.util.Map; public class BountifulWrapper { public static final BountifulWrapper impl = new BountifulWrapper(); - private static final Class enumHand = Reflection.getClass("net.minecraft.world.InteractionHand"); + private static final Class enumHand = InteractionHand.class; private static final Object mainHand = enumHand.getEnumConstants()[0]; private static final Reflection.Field blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java index c42faa24..3a9dbbe7 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java @@ -30,6 +30,7 @@ import org.bukkit.Chunk; import org.bukkit.GameRule; import org.bukkit.World; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.entity.Entity; import java.util.HashSet; @@ -40,14 +41,14 @@ import java.util.stream.StreamSupport; public class CraftbukkitWrapper { public static final CraftbukkitWrapper impl = new CraftbukkitWrapper(); - private static final Reflection.Method getWorld = Reflection.getMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle"); + private static final Reflection.Method getWorld = Reflection.getMethod(CraftWorld.class, "getHandle"); private static final Reflection.Method getChunk = Reflection.getTypedMethod(ServerLevel.class, null, LevelChunk.class, int.class, int.class); private static final Reflection.Method getChunkSections = Reflection.getTypedMethod(LevelChunk.class, null, LevelChunkSection[].class); private LevelChunkSection[] getChunkSections(World world, int x, int z) { return (LevelChunkSection[]) getChunkSections.invoke(getChunk.invoke(getWorld.invoke(world), x, z)); } - private static final Reflection.Method getEntity = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.entity.CraftEntity"), "getHandle", net.minecraft.world.entity.Entity.class); + private static final Reflection.Method getEntity = Reflection.getTypedMethod(CraftEntity.class, "getHandle", net.minecraft.world.entity.Entity.class); protected net.minecraft.world.entity.Entity getEntity(Entity e) { return (net.minecraft.world.entity.Entity) getEntity.invoke(e); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index e7c505a3..49aaf4dd 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -34,6 +34,9 @@ import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.techhider.TechHider; import lombok.Getter; +import net.minecraft.core.Vec3i; +import net.minecraft.network.protocol.game.ClientboundExplodePacket; +import net.minecraft.network.protocol.game.ClientboundLevelEventPacket; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -61,7 +64,7 @@ public class HullHider implements Listener { private final Hull[] hulls; private final Map, BiFunction> packetHiders = new HashMap<>(); - private static final Class packetPlayOutExplosion = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); + private static final Class packetPlayOutExplosion = ClientboundExplodePacket.class; public HullHider() { if(!TechHiderWrapper.ENABLED) { hulls = new Hull[0]; @@ -200,9 +203,9 @@ public class HullHider implements Listener { } - private static final Class packetPlayOutWorldEvent = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelEventPacket"); + private static final Class packetPlayOutWorldEvent = ClientboundLevelEventPacket.class; private static final Reflection.Field worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0); - public static final Reflection.Field blockPositionY = Reflection.getField("net.minecraft.core.Vec3i", int.class, 1); + public static final Reflection.Field blockPositionY = Reflection.getField(Vec3i.class, 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))); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java index 061e3877..35203a20 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java @@ -27,13 +27,14 @@ import net.minecraft.core.SectionPos; import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket; import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.block.data.CraftBlockData; import java.util.List; public class HullHiderWrapper { public static final HullHiderWrapper impl = new HullHiderWrapper(); - private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", BlockState.class); + private static final Reflection.Method getState = Reflection.getTypedMethod(CraftBlockData.class, "getState", BlockState.class); public Object generateBlockChangePacket(List changes) { Object[] blockdata = new Object[changes.size()]; for(int i = 0; i < blockdata.length; i++) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java index 0ff13595..2803cf87 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java @@ -22,6 +22,10 @@ package de.steamwar.core; import de.steamwar.Reflection; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializer; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.world.entity.PositionMoveRotation; import net.minecraft.world.phys.Vec3; import org.bukkit.Sound; @@ -43,15 +47,15 @@ public class BountifulWrapper { player.spigot().sendMessage(type, msg); } - private static final Class dataWatcherObject = Reflection.getClass("net.minecraft.network.syncher.EntityDataAccessor"); - private static final Class dataWatcherRegistry = Reflection.getClass("net.minecraft.network.syncher.EntityDataSerializers"); - private static final Class dataWatcherSerializer = Reflection.getClass("net.minecraft.network.syncher.EntityDataSerializer"); + private static final Class dataWatcherObject = EntityDataAccessor.class; + private static final Class dataWatcherRegistry = EntityDataSerializers.class; + private static final Class dataWatcherSerializer = EntityDataSerializer.class; private static final Reflection.Constructor dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); public Object getDataWatcherObject(int index, Class type) { return dataWatcherObjectConstructor.invoke(index, Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null)); } - private static final Class item = Reflection.getClass("net.minecraft.network.syncher.SynchedEntityData$DataItem"); + private static final Class item = SynchedEntityData.DataItem.class; private static final Reflection.Constructor itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class); public Object getDataWatcherItem(Object dwo, Object value) { return itemConstructor.invoke(dwo, value); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java index 0befeb68..b214330f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java @@ -21,9 +21,17 @@ package de.steamwar.core; import com.destroystokyo.paper.profile.PlayerProfile; import de.steamwar.Reflection; +import net.minecraft.core.DefaultedRegistry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundSetObjectivePacket; -import net.minecraft.network.protocol.game.ClientboundSetScorePacket; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.ProgressListener; +import net.minecraft.world.entity.Pose; import org.bukkit.*; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -229,14 +237,14 @@ public class FlatteningWrapper { renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT); } - private static final Reflection.Field scoreboardName = Reflection.getField(ClientboundSetObjectivePacket.class, Reflection.getClass("net.minecraft.network.chat.Component"), 0); + private static final Reflection.Field scoreboardName = Reflection.getField(ClientboundSetObjectivePacket.class, Component.class, 0); public void setScoreboardTitle(Object packet, String title) { scoreboardName.set(packet, ChatWrapper.impl.stringToChatComponent(title)); } - private static final Class scoreActionEnum = Core.getVersion() < 21 ? Reflection.getClass("net.minecraft.server.ServerScoreboard$Method") : null; - private static final Reflection.Field scoreAction = Core.getVersion() < 21 ? Reflection.getField(ClientboundSetScorePacket.class, scoreActionEnum, 0) : null; - private static final Object scoreActionChange = Core.getVersion() < 21 ? scoreActionEnum.getEnumConstants()[0] : null; + private static final Class scoreActionEnum = null; + private static final Reflection.Field scoreAction = null; + private static final Object scoreActionChange = null; public void setScoreAction(Object packet) { scoreAction.set(packet, scoreActionChange); @@ -302,7 +310,7 @@ public class FlatteningWrapper { return head; } - protected static final Class entityPose = Reflection.getClass("net.minecraft.world.entity.Pose"); + protected static final Class entityPose = Pose.class; protected static final Object shooting = entityPose.getEnumConstants()[16]; protected static final Object standing = entityPose.getEnumConstants()[0]; protected static final Object swimming = entityPose.getEnumConstants()[3]; @@ -329,13 +337,13 @@ public class FlatteningWrapper { return displayName != null ? Optional.of(ChatWrapper.impl.stringToChatComponent(displayName)) : Optional.empty(); } - private static final Class registryBlocks = Reflection.getClass("net.minecraft.core.DefaultedRegistry"); - private static final Class entityTypes = Reflection.getClass("net.minecraft.world.entity.EntityType"); - private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass(Core.getVersion() > 18 ? "net.minecraft.core.registries.BuiltInRegistries" : "net.minecraft.core.IRegistry"), registryBlocks, 0, entityTypes).get(null); - private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("net.minecraft.resources.ResourceLocation")); + private static final Class registryBlocks = DefaultedRegistry.class; + private static final Class entityTypes = net.minecraft.world.entity.EntityType.class; + private static final Object entityTypesRegistry = Reflection.getField(BuiltInRegistries.class, registryBlocks, 0, entityTypes).get(null); + private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, ResourceLocation.class); private static final Reflection.Field spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); - private static final Reflection.Field spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); - private static final Reflection.Method toMinecraft = Reflection.getMethod("org.bukkit.craftbukkit.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); + private static final Reflection.Field spawnLivingType = spawnType; + private static final Reflection.Method toMinecraft = Reflection.getMethod(CraftNamespacedKey.class, "toMinecraft", NamespacedKey.class); private static final Map types = new HashMap<>(); static { types.put(EntityType.ARMOR_STAND, 1); @@ -352,8 +360,8 @@ public class FlatteningWrapper { return player.getClientViewDistance(); } - private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftWorld", "getHandle"); - private static final Reflection.Method save = Reflection.getMethod("net.minecraft.server.level.ServerLevel", null, Reflection.getClass("net.minecraft.util.ProgressListener"), boolean.class, boolean.class); + private static final Reflection.Method getHandle = Reflection.getMethod(CraftWorld.class, "getHandle"); + private static final Reflection.Method save = Reflection.getMethod(ServerLevel.class, null, ProgressListener.class, boolean.class, boolean.class); public void syncSave(World world) { save.invoke(getHandle.invoke(world), null, true, false); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java index c61bdfaf..3c2d8a2c 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java @@ -22,6 +22,7 @@ package de.steamwar.core; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; import de.steamwar.Reflection; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; @@ -35,13 +36,10 @@ import java.util.EnumSet; public class ProtocolWrapper { - public static final Class itemStack = Reflection.getClass("net.minecraft.world.item.ItemStack"); - public static final Class spawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddEntityPacket"); - public static final Class spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving"); - public static final Class equipmentPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket"); - - public static final Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "net.minecraft.world.level.GameType" : "net.minecraft.WorldSettings$EnumGamemode"); - public static final Reflection.Method getGameModeById = Reflection.getTypedMethod(enumGamemode, null, enumGamemode, int.class); + public static final Class itemStack = ItemStack.class; + public static final Class spawnPacket = ClientboundAddEntityPacket.class; + public static final Class spawnLivingPacket = ProtocolWrapper.spawnPacket; + public static final Class equipmentPacket = ClientboundSetEquipmentPacket.class; // 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head public static final Object[] itemSlots = Core.getVersion() > 8 ? Reflection.getClass("net.minecraft.world.entity.EnumItemSlot").getEnumConstants() : new Integer[]{0, 0, 1, 2, 3, 4}; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index e88b1e82..f4acdad5 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -20,6 +20,7 @@ package de.steamwar.core; import de.steamwar.Reflection; +import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; public class TPSWatcher { @@ -79,7 +80,7 @@ public class TPSWatcher { } } - private static final Class minecraftServer = Reflection.getClass("net.minecraft.server.MinecraftServer"); + private static final Class minecraftServer = MinecraftServer.class; private static final Reflection.Method getServer = Reflection.getTypedMethod(minecraftServer, "getServer", minecraftServer); private static final Reflection.Field recentTps = Reflection.getField(minecraftServer, "recentTps", double[].class); private static double[] getSpigotTPS() { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldIdentifier.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldIdentifier.java index 6e6a8de3..ebd7c699 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldIdentifier.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldIdentifier.java @@ -32,7 +32,7 @@ public class WorldIdentifier { private static ResourceKey resourceKey = null; - private static final Class resourceKeyClass = Reflection.getClass("net.minecraft.resources.ResourceKey"); + private static final Class resourceKeyClass = ResourceKey.class; private static final Class minecraftKeyClass = Reflection.getClass("net.minecraft.resources.MinecraftKey"); private static final Reflection.Constructor resourceKeyConstructor = Reflection.getConstructor(resourceKeyClass, minecraftKeyClass, minecraftKeyClass); private static final Reflection.Constructor minecraftKeyConstructor = Reflection.getConstructor(minecraftKeyClass, String.class, String.class); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index 40cdb955..93cd721a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -26,6 +26,9 @@ import de.steamwar.linkage.Linked; import de.steamwar.sql.SWException; import de.steamwar.techhider.ProtocolUtils; import de.steamwar.techhider.TechHider; +import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket; +import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; +import net.minecraft.world.phys.BlockHitResult; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -54,11 +57,11 @@ public class AntiNocom implements Listener { } private void registerUseItem() { - Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"); + Class useItem = ServerboundUseItemOnPacket.class; Function getPosition; if(Core.getVersion() > 12) { - Class movingObjectPositionBlock = Reflection.getClass("net.minecraft.world.phys.BlockHitResult"); + Class movingObjectPositionBlock = BlockHitResult.class; Reflection.Field useItemPosition = Reflection.getField(useItem, movingObjectPositionBlock, 0); Reflection.Field movingBlockPosition = Reflection.getField(movingObjectPositionBlock, TechHider.blockPosition, 0); @@ -73,7 +76,7 @@ public class AntiNocom implements Listener { }); } - private static final Class blockDig = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket"); + private static final Class blockDig = ServerboundPlayerActionPacket.class; private static final Reflection.Field digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0); private Object onDig(Player player, Object packet) { Object pos = digPosition.get(packet); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index 0058617a..cf6ab36a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -23,9 +23,11 @@ import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.Core; import lombok.Getter; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.entity.EntityType; import java.util.function.BiConsumer; @@ -58,8 +60,8 @@ public class RBlockDisplay extends RDisplay { sendPacket(updatePacketSink, this::getBlock); } - private static final Class iBlockDataClass = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); - private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", iBlockDataClass); + private static final Class iBlockDataClass = BlockState.class; + private static final Reflection.Method getState = Reflection.getTypedMethod(CraftBlockData.class, "getState", iBlockDataClass); private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, iBlockDataClass); private void getBlock(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || !block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 9962878e..38184d28 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -24,7 +24,9 @@ import de.steamwar.core.*; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import lombok.Getter; +import net.minecraft.network.protocol.game.*; import org.bukkit.Location; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; @@ -160,7 +162,7 @@ public class REntity { server.postEntityMove(this, fromX, fromZ); } - private static final Class animationPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAnimatePacket"); + private static final Class animationPacket = ClientboundAnimatePacket.class; private static final Reflection.Field animationEntity = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 5 : 6) : 0); private static final Reflection.Field animationAnimation = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 6 : 7) : 1); public void showAnimation(byte animation) { @@ -170,7 +172,7 @@ public class REntity { server.updateEntity(this, packet); } - private static final Class velocityPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket"); + private static final Class velocityPacket = ClientboundSetEntityMotionPacket.class; private static final Reflection.Field velocityEntity = Reflection.getField(velocityPacket, int.class, 0); private static final Reflection.Field velocityX = Reflection.getField(velocityPacket, int.class, 1); private static final Reflection.Field velocityY = Reflection.getField(velocityPacket, int.class, 2); @@ -184,7 +186,7 @@ public class REntity { server.updateEntity(this, packet); } - private static final Class statusPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundEntityEventPacket"); + private static final Class statusPacket = ClientboundEntityEventPacket.class; private static final Reflection.Field statusEntity = Reflection.getField(statusPacket, int.class, 0); private static final Reflection.Field statusStatus = Reflection.getField(statusPacket, byte.class, 0); public void showDamage() { @@ -348,7 +350,7 @@ public class REntity { } } - private static final Class destroyPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket"); + private static final Class destroyPacket = ClientboundRemoveEntitiesPacket.class; private static final Reflection.Field destroyEntities; static { if(Core.getVersion() > 15) @@ -395,7 +397,7 @@ public class REntity { return ChatWrapper.impl.getDataWatcherPacket(entityId, dataWatcherKeyValues); } - public static final Class teleportPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket"); + public static final Class teleportPacket = ClientboundTeleportEntityPacket.class; public static final Reflection.Field teleportEntity = Reflection.getField(teleportPacket, int.class, 0); public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0); private Object getTeleportPacket(){ @@ -409,12 +411,12 @@ public class REntity { return packet; } - private static final Class entityPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket"); + private static final Class entityPacket = ClientboundMoveEntityPacket.class; private static final Reflection.Field moveEntityId = Reflection.getField(entityPacket, int.class, 0); private static final BountifulWrapper.PositionSetter movePosition = BountifulWrapper.impl.getRelMoveSetter(entityPacket); - private static final Class lookPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Rot"); - private static final Class movePacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Pos"); - private static final Class moveLookPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$PosRot"); + private static final Class lookPacket = ClientboundMoveEntityPacket.Rot.class; + private static final Class movePacket = ClientboundMoveEntityPacket.Pos.class; + private static final Class moveLookPacket = ClientboundMoveEntityPacket.PosRot.class; private Object getMoveLookPacket(double diffX, double diffY, double diffZ, boolean rotEq) { Class clazz; if(diffX == 0 && diffY == 0 && diffZ == 0) { @@ -434,7 +436,7 @@ public class REntity { return packet; } - private static final Class headRotationPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundRotateHeadPacket"); + private static final Class headRotationPacket = ClientboundRotateHeadPacket.class; private static final Reflection.Field headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); private static final Reflection.Field headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); private Object getHeadRotationPacket(){ @@ -447,7 +449,7 @@ public class REntity { private static final Reflection.Field equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0); private static final Reflection.Field equipmentSlots = Reflection.getField(ProtocolWrapper.equipmentPacket, List.class, 0); - private static final Class craftItemStack = Reflection.getClass("org.bukkit.craftbukkit.inventory.CraftItemStack"); + private static final Class craftItemStack = CraftItemStack.class; protected static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class); protected Object getEquipmentPacket(Object slot, ItemStack stack){ Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 3ba28d38..00ce14b7 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -23,6 +23,7 @@ import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; +import net.minecraft.network.protocol.game.ServerboundInteractPacket; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -47,7 +48,7 @@ public class REntityServer implements Listener { private static final HashSet emptyEntities = new HashSet<>(0); private static final HashSet emptyPlayers = new HashSet<>(0); - private static final Class useEntity = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket"); + private static final Class useEntity = ServerboundInteractPacket.class; private static final Reflection.Field useEntityTarget = Reflection.getField(useEntity, int.class, 0); private static final Class useEntityEnumAction = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action"); private static final Reflection.Field useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java index 29cb8a21..bf7f021a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RTextDisplay.java @@ -24,6 +24,7 @@ import de.steamwar.core.BountifulWrapper; import de.steamwar.core.ChatWrapper; import de.steamwar.core.Core; import lombok.Getter; +import net.minecraft.network.chat.Component; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.entity.TextDisplay; @@ -74,7 +75,7 @@ public class RTextDisplay extends RDisplay { sendPacket(updatePacketSink, this::getText); } - private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.Component"); + private static final Class iChatBaseComponent = Component.class; private static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, iChatBaseComponent); private void getText(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || !text.isEmpty()) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java index eec211b2..81ea860d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java @@ -19,17 +19,18 @@ package de.steamwar.network.handlers; -import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.linkage.Linked; import de.steamwar.linkage.MinVersion; +import net.minecraft.network.protocol.game.ClientboundServerDataPacket; +import net.minecraft.network.protocol.game.ServerboundChatSessionUpdatePacket; @Linked @MinVersion(19) public class ServerDataHandler { public ServerDataHandler() { - TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ClientboundServerDataPacket"), (p, o) -> null); - TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundChatSessionUpdatePacket"), (player, packet) -> null); + TinyProtocol.instance.addFilter(ClientboundServerDataPacket.class, (p, o) -> null); + TinyProtocol.instance.addFilter(ServerboundChatSessionUpdatePacket.class, (player, packet) -> null); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java index e0ec9a14..4cbee1d6 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java @@ -21,6 +21,11 @@ package de.steamwar.techhider; import com.google.common.collect.ImmutableList; import de.steamwar.Reflection; +import net.minecraft.core.IdMapper; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.material.FlowingFluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import org.bukkit.Material; import java.util.HashSet; @@ -31,9 +36,9 @@ public class BlockIds { Reflection.Method getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); - private static final Class blockStateList = Reflection.getClass("net.minecraft.world.level.block.state.StateDefinition"); - private static final Class fluidTypeFlowing = Reflection.getClass("net.minecraft.world.level.material.FlowingFluid"); - private static final Class fluid = Reflection.getClass("net.minecraft.world.level.material.FluidState"); + private static final Class blockStateList = StateDefinition.class; + private static final Class fluidTypeFlowing = FlowingFluid.class; + private static final Class fluid = FluidState.class; private static final Reflection.Method getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); public int materialToId(Material material) { @@ -42,8 +47,8 @@ public class BlockIds { private static final Reflection.Method getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList); private static final Reflection.Method getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); - private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Reflection.getClass("net.minecraft.world.level.material.Fluids"), fluidTypeFlowing, 1).get(null), false); - private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, Reflection.getClass("net.minecraft.core.IdMapper"), 0).get(null); + private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Fluids.class, fluidTypeFlowing, 1).get(null), false); + private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, IdMapper.class, 0).get(null); private static final Reflection.Method getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid); public Set materialToAllIds(Material material) { Set ids = new HashSet<>(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java index c1ff1e3f..7fc7c439 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java @@ -23,8 +23,11 @@ import de.steamwar.Reflection; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import lombok.Getter; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.SimpleBitStorage; import net.minecraft.world.level.block.entity.BlockEntityType; import org.bukkit.entity.Player; @@ -91,10 +94,10 @@ public class ChunkHider { public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo"); protected static final Reflection.Field entityType = Reflection.getField(tileEntity, BlockEntityType.class, 0); - private static final Class builtInRegestries = Reflection.getClass("net.minecraft.core.registries.BuiltInRegistries"); - private static final Class registry = Reflection.getClass("net.minecraft.core.Registry"); + private static final Class builtInRegestries = BuiltInRegistries.class; + private static final Class registry = Registry.class; private static final Reflection.Field nameField = Reflection.getField(builtInRegestries, "BLOCK_ENTITY_TYPE", registry); - private static final Class resourceLocation = Reflection.getClass("net.minecraft.resources.ResourceLocation"); + private static final Class resourceLocation = ResourceLocation.class; private static final Reflection.Method getKey = Reflection.getTypedMethod(registry, "getKey", resourceLocation, Object.class); private static final Reflection.Method getName = Reflection.getTypedMethod(resourceLocation, "getPath", String.class); protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 46e53bcf..4bac686e 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -23,7 +23,19 @@ import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.Reflection; import de.steamwar.core.Core; import lombok.Getter; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Vec3i; +import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.network.protocol.game.ClientboundBlockEventPacket; +import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; +import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket; +import net.minecraft.network.protocol.game.ServerboundInteractPacket; +import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Material; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.Player; import java.util.HashMap; @@ -36,17 +48,17 @@ import java.util.stream.Collectors; public class TechHider { - public static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); - private static final Class baseBlockPosition = Reflection.getClass("net.minecraft.core.Vec3i"); + public static final Class blockPosition = BlockPos.class; + private static final Class baseBlockPosition = Vec3i.class; public static final Reflection.Field blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); public static final Reflection.Field blockPositionY = Reflection.getField(baseBlockPosition, int.class, 1); public static final Reflection.Field blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); - public static final Class iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); - public static final Class block = Reflection.getClass("net.minecraft.world.level.block.Block"); + public static final Class iBlockData = BlockState.class; + public static final Class block = Block.class; private static final Reflection.Method getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); - public static final Class craftMagicNumbers = Reflection.getClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"); + public static final Class craftMagicNumbers = CraftMagicNumbers.class; private static final Reflection.Method getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); public boolean iBlockDataHidden(Object iBlockData) { @@ -82,14 +94,14 @@ public class TechHider { techhiders.put(ChunkHider.impl.mapChunkPacket(), ChunkHider.impl.chunkHiderGenerator(this)); if(Core.getVersion() > 12 && Core.getVersion() < 19) { - Class blockBreakClass = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket"); + Class blockBreakClass = ClientboundBlockDestructionPacket.class; techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass, this)); } if(Core.getVersion() > 8){ - techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"), (p, packet) -> locationEvaluator.suppressInteractions(p) ? null : packet); + techhiders.put(ServerboundUseItemOnPacket.class, (p, packet) -> locationEvaluator.suppressInteractions(p) ? null : packet); } - techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket"), (p, packet) -> locationEvaluator.suppressInteractions(p) ? null : packet); + techhiders.put(ServerboundInteractPacket.class, (p, packet) -> locationEvaluator.suppressInteractions(p) ? null : packet); } @@ -101,10 +113,10 @@ public class TechHider { techhiders.forEach(TinyProtocol.instance::removeFilter); } - public static final Class multiBlockChangePacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket"); + public static final Class multiBlockChangePacket = ClientboundSectionBlocksUpdatePacket.class; public static final UnaryOperator multiBlockChangeCloner = ProtocolUtils.shallowCloneGenerator(TechHider.multiBlockChangePacket); - private static final Class blockChangePacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket"); + private static final Class blockChangePacket = ClientboundBlockUpdatePacket.class; private static final Function blockChangeCloner = ProtocolUtils.shallowCloneGenerator(blockChangePacket); private static final Reflection.Field blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); private static final Reflection.Field blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 0); @@ -127,7 +139,7 @@ public class TechHider { } } - private static final Class blockActionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockEventPacket"); + private static final Class blockActionPacket = ClientboundBlockEventPacket.class; private static final Reflection.Field blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0); private Object blockActionHider(Player p, Object packet) { if (locationEvaluator.checkBlockPos(p, blockActionPosition.get(packet)) == State.SKIP) @@ -135,7 +147,7 @@ public class TechHider { return null; } - public static final Class tileEntityDataPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket"); + public static final Class tileEntityDataPacket = ClientboundBlockEntityDataPacket.class; private static final Reflection.Field tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); private Object tileEntityDataHider(Player p, Object packet) { switch (locationEvaluator.checkBlockPos(p, tileEntityDataPosition.get(packet))) { From a100d2d798f3a57aaae8cc6d8ad65aa80a17e729 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 16 May 2026 13:02:20 +0200 Subject: [PATCH 2/5] Remove more Reflection stuff --- .../steamwar/fightsystem/utils/HullHider.java | 12 ++++----- MissileWars/build.gradle.kts | 2 +- .../misslewars/slowmo/SlowMoUtils.java | 8 +++--- .../src/de/steamwar/core/ProtocolWrapper.java | 3 +-- .../src/de/steamwar/core/WorldIdentifier.java | 3 ++- .../src/de/steamwar/entity/RPlayer.java | 26 ++++--------------- 6 files changed, 18 insertions(+), 36 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 49aaf4dd..29751f50 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -21,7 +21,6 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.Reflection; -import de.steamwar.core.Core; import de.steamwar.entity.REntity; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; @@ -37,6 +36,8 @@ import lombok.Getter; import net.minecraft.core.Vec3i; import net.minecraft.network.protocol.game.ClientboundExplodePacket; import net.minecraft.network.protocol.game.ClientboundLevelEventPacket; +import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket; +import net.minecraft.network.protocol.game.ClientboundSoundPacket; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -76,10 +77,8 @@ public class HullHider implements Listener { packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider); packetHiders.put(packetPlayOutExplosion, this::explosionHider); - 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); + posHiderGenerator(ClientboundLevelParticlesPacket.class, double.class, 1.0); + posHiderGenerator(ClientboundSoundPacket.class, int.class, 8.0); new StateDependentListener(TechHiderWrapper.ENABLED, FightState.Schem, this); new StateDependent(TechHiderWrapper.ENABLED, FightState.Schem) { @@ -215,8 +214,7 @@ public class HullHider implements Listener { return ReflectionWrapper.impl.explosionHider(player, packet, this::packetHider); } - private void posHiderGenerator(String typeName, Class posType, double factor) { - Class type = Reflection.getClass(typeName); + private void posHiderGenerator(Class type, Class posType, double factor) { Function location = posPacketToLocation(type, posType, factor); packetHiders.put(type, (player, packet) -> packetHider(player, packet, location.apply(packet))); } diff --git a/MissileWars/build.gradle.kts b/MissileWars/build.gradle.kts index 16dc6622..c6b757e1 100644 --- a/MissileWars/build.gradle.kts +++ b/MissileWars/build.gradle.kts @@ -33,6 +33,6 @@ dependencies { compileOnly(libs.spigotapi) - compileOnly(libs.nms20) + compileOnly(libs.nms21) compileOnly(libs.fawe21) } diff --git a/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java b/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java index 4630784d..c5e01cc4 100644 --- a/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java +++ b/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java @@ -19,9 +19,10 @@ package de.steamwar.misslewars.slowmo; -import de.steamwar.Reflection; +import net.minecraft.server.level.ServerLevel; import org.bukkit.Bukkit; import org.bukkit.World; +import org.bukkit.craftbukkit.CraftWorld; import java.lang.reflect.Field; @@ -30,7 +31,6 @@ public class SlowMoUtils { private static final Field field; public static final boolean freezeEnabled; - private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", null); private static boolean frozen = false; private static final World world; @@ -38,7 +38,7 @@ public class SlowMoUtils { static { Field temp; try { - temp = Reflection.getClass("net.minecraft.server.level.ServerLevel").getField("freezed"); + temp = ServerLevel.class.getField("freezed"); } catch (NoSuchFieldException e) { temp = null; } @@ -64,7 +64,7 @@ public class SlowMoUtils { if (freezeEnabled) { if (frozen == state) return; try { - field.set(getWorldHandle.invoke(world), state); + field.set(((CraftWorld) world).getHandle(), state); frozen = state; } catch (IllegalAccessException e) { // Ignored; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java index 3c2d8a2c..d6fdd3f2 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java @@ -21,7 +21,6 @@ package de.steamwar.core; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; -import de.steamwar.Reflection; import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; @@ -42,7 +41,7 @@ public class ProtocolWrapper { public static final Class equipmentPacket = ClientboundSetEquipmentPacket.class; // 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head - public static final Object[] itemSlots = Core.getVersion() > 8 ? Reflection.getClass("net.minecraft.world.entity.EnumItemSlot").getEnumConstants() : new Integer[]{0, 0, 1, 2, 3, 4}; + public static final EquipmentSlot[] itemSlots = EquipmentSlot.values(); public static final ProtocolWrapper impl = new ProtocolWrapper(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldIdentifier.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldIdentifier.java index ebd7c699..d9edd2c7 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldIdentifier.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldIdentifier.java @@ -25,6 +25,7 @@ import de.steamwar.linkage.Linked; import net.minecraft.network.protocol.game.ClientboundLoginPacket; import net.minecraft.network.protocol.game.CommonPlayerSpawnInfo; import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.Level; @Linked @@ -33,7 +34,7 @@ public class WorldIdentifier { private static ResourceKey resourceKey = null; private static final Class resourceKeyClass = ResourceKey.class; - private static final Class minecraftKeyClass = Reflection.getClass("net.minecraft.resources.MinecraftKey"); + private static final Class minecraftKeyClass = ResourceLocation.class; private static final Reflection.Constructor resourceKeyConstructor = Reflection.getConstructor(resourceKeyClass, minecraftKeyClass, minecraftKeyClass); private static final Reflection.Constructor minecraftKeyConstructor = Reflection.getConstructor(minecraftKeyClass, String.class, String.class); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index 9883cdde..fec92cae 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -21,8 +21,10 @@ package de.steamwar.entity; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; -import de.steamwar.Reflection; -import de.steamwar.core.*; +import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; +import de.steamwar.core.ProtocolWrapper; +import de.steamwar.core.TrickyTrialsWrapper; import de.steamwar.network.CoreNetworkHandler; import de.steamwar.network.NetworkSender; import de.steamwar.network.packets.common.PlayerSkinRequestPacket; @@ -36,7 +38,6 @@ import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.UUID; import java.util.function.Consumer; -import java.util.function.Function; public class RPlayer extends REntity { @@ -114,24 +115,7 @@ public class RPlayer extends REntity { packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, saved, GameMode.CREATIVE)); } - private static Class namedSpawnPacket = null; - private static Function namedSpawnPacketGenerator = null; - private static Reflection.Field namedSpawnUUID = null; - - static { - try { - namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket"); - namedSpawnPacketGenerator = spawnPacketGenerator(namedSpawnPacket, Core.getVersion() == 8 ? 1 : 0); - namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); - } catch (IllegalArgumentException e) { } - } - private Object getNamedSpawnPacket() { - if (Core.getVersion() >= 21) return PacketConstructor.impl.createRPlayerSpawn(this); - - Object packet = namedSpawnPacketGenerator.apply(this); - namedSpawnUUID.set(packet, uuid); - FlatteningWrapper.impl.setNamedSpawnPacketDataWatcher(packet); - return packet; + return PacketConstructor.impl.createRPlayerSpawn(this); } } From e7454f6ce8fab1aad27961ad5003e2b73f1d1fda Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 16 May 2026 13:07:06 +0200 Subject: [PATCH 3/5] Fight FightWorld --- .../de/steamwar/misslewars/FightWorld.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/MissileWars/src/de/steamwar/misslewars/FightWorld.java b/MissileWars/src/de/steamwar/misslewars/FightWorld.java index 1187d840..501c18a2 100644 --- a/MissileWars/src/de/steamwar/misslewars/FightWorld.java +++ b/MissileWars/src/de/steamwar/misslewars/FightWorld.java @@ -20,15 +20,19 @@ package de.steamwar.misslewars; import de.steamwar.core.CraftbukkitWrapper; -import net.minecraft.world.level.chunk.Chunk; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; -import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import java.util.HashSet; +import java.util.Set; import java.util.function.ObjIntConsumer; public class FightWorld { @@ -71,10 +75,14 @@ public class FightWorld { } private static void resetChunk(World world, World backup, int x, int z) { - Chunk chunk = ((CraftWorld) world).getHandle().d(x, z); - Chunk backupChunk = ((CraftWorld) backup).getHandle().d(x, z); - - System.arraycopy(backupChunk.d(), 0, chunk.d(), 0, chunk.d().length); + LevelChunk worldChunk = ((CraftWorld) world).getHandle().getChunk(x, z); + LevelChunk backupChunk = ((CraftWorld) backup).getHandle().getChunk(x, z); + LevelChunkSection[] sections = worldChunk.getSections(); + System.arraycopy(backupChunk.getSections(), 0, sections, 0, sections.length); + Set blocks = new HashSet<>(worldChunk.blockEntities.keySet()); + blocks.stream().filter(key -> !backupChunk.blockEntities.containsKey(key)).forEach(worldChunk::removeBlockEntity); + worldChunk.heightmaps.clear(); + worldChunk.heightmaps.putAll(backupChunk.heightmaps); for(Player p : Bukkit.getOnlinePlayers()) CraftbukkitWrapper.impl.sendChunk(p, x, z); From 9e4c9ce04ae193404a7421f3511f74f9dcf75285 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 16 May 2026 13:38:10 +0200 Subject: [PATCH 4/5] Remove more reflection --- .../de/steamwar/fightsystem/ai/AIManager.java | 11 ++++--- .../fightsystem/listener/Recording.java | 3 +- .../fightsystem/utils/BlockIdWrapper.java | 10 ------ .../fightsystem/utils/CraftbukkitWrapper.java | 20 ++---------- .../fightsystem/utils/HullHiderWrapper.java | 4 +-- .../src/de/steamwar/Reflection.java | 28 ++--------------- .../de/steamwar/core/BountifulWrapper.java | 8 ++--- .../de/steamwar/core/CheckpointUtilsJ9.java | 3 +- .../de/steamwar/core/FlatteningWrapper.java | 31 +++++-------------- .../src/de/steamwar/core/TPSWatcher.java | 6 +--- .../src/de/steamwar/entity/RBlockDisplay.java | 8 ++--- .../src/de/steamwar/entity/REntity.java | 4 +-- .../src/de/steamwar/entity/REntityServer.java | 12 +++---- .../src/de/steamwar/entity/RItemDisplay.java | 8 ++--- .../src/de/steamwar/techhider/BlockIds.java | 4 +-- .../src/de/steamwar/techhider/ChunkHider.java | 10 +----- .../src/de/steamwar/techhider/TechHider.java | 16 ++-------- 17 files changed, 42 insertions(+), 144 deletions(-) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java index 1ed59d98..9f8383cf 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java @@ -19,7 +19,6 @@ package de.steamwar.fightsystem.ai; -import de.steamwar.Reflection; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.FightTeam; @@ -30,28 +29,30 @@ import org.bukkit.Material; import java.util.Arrays; import java.util.List; import java.util.function.BooleanSupplier; +import java.util.function.Function; import java.util.stream.Collectors; @AllArgsConstructor public class AIManager { private static final List AIs = Arrays.asList( - new AIManager(DummyAI.class, Material.STONE, () -> ArenaMode.Test.contains(Config.mode)) + new AIManager("DummyAI", DummyAI::new, Material.STONE, () -> ArenaMode.Test.contains(Config.mode)) ); public static List availableAIs() { return AIs.stream().filter(manager -> manager.available.getAsBoolean()).collect(Collectors.toList()); } - private final Class aiClass; + private final String name; + private final Function constructor; @Getter private final Material icon; private final BooleanSupplier available; public String name() { - return aiClass.getSimpleName(); + return name; } public void join(FightTeam team) { - Reflection.getConstructor(aiClass, FightTeam.class).invoke(team); + constructor.apply(team); } } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index 24735f58..2a7fdcae 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -83,9 +83,8 @@ public class Recording implements Listener { } public static final Class primedTnt = PrimedTnt.class; - private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(net.minecraft.world.entity.Entity.class, "getBukkitEntity", null); public static void iterateOverEntities(Predicate filter, Consumer consumer) { - CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(consumer); + CraftbukkitWrapper.impl.entityIterator().filter(filter).map(net.minecraft.world.entity.Entity::getBukkitEntity).forEach(consumer); } public Recording() { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index b6c3fd56..a91de770 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -21,12 +21,10 @@ package de.steamwar.fightsystem.utils; import com.comphenix.tinyprotocol.TinyProtocol; import com.mojang.authlib.GameProfile; -import de.steamwar.Reflection; import de.steamwar.core.ProtocolWrapper; import de.steamwar.fightsystem.FightSystem; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.GameMode; import org.bukkit.Material; @@ -34,19 +32,11 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.block.CraftBlockState; -import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; public class BlockIdWrapper { - public static final Class worldServer = ServerLevel.class; - public static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(CraftWorld.class, "getHandle", worldServer); - - public static final Class craftPlayer = CraftPlayer.class; - public static final Class entityPlayer = ServerPlayer.class; - public static final Reflection.Method getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer); - public static final BlockIdWrapper impl = new BlockIdWrapper(); public Material idToMaterial(int blockState) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java index 3a9dbbe7..6a4518c8 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java @@ -19,14 +19,10 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunkSection; -import net.minecraft.world.level.entity.LevelEntityGetter; -import org.bukkit.Chunk; import org.bukkit.GameRule; import org.bukkit.World; import org.bukkit.craftbukkit.CraftWorld; @@ -41,26 +37,16 @@ import java.util.stream.StreamSupport; public class CraftbukkitWrapper { public static final CraftbukkitWrapper impl = new CraftbukkitWrapper(); - private static final Reflection.Method getWorld = Reflection.getMethod(CraftWorld.class, "getHandle"); - private static final Reflection.Method getChunk = Reflection.getTypedMethod(ServerLevel.class, null, LevelChunk.class, int.class, int.class); - private static final Reflection.Method getChunkSections = Reflection.getTypedMethod(LevelChunk.class, null, LevelChunkSection[].class); - private LevelChunkSection[] getChunkSections(World world, int x, int z) { - return (LevelChunkSection[]) getChunkSections.invoke(getChunk.invoke(getWorld.invoke(world), x, z)); - } - - private static final Reflection.Method getEntity = Reflection.getTypedMethod(CraftEntity.class, "getHandle", net.minecraft.world.entity.Entity.class); protected net.minecraft.world.entity.Entity getEntity(Entity e) { - return (net.minecraft.world.entity.Entity) getEntity.invoke(e); + return ((CraftEntity) e).getHandle(); } public float headRotation(Entity e) { return getEntity(e).getYHeadRot(); } - private static final Reflection.Method getWorldEntities = Reflection.getTypedMethod(ServerLevel.class, null, LevelEntityGetter.class); - private static final Reflection.Method getIterable = Reflection.getTypedMethod(LevelEntityGetter.class, null, Iterable.class); - public Stream entityIterator() { - return StreamSupport.stream(((Iterable) getIterable.invoke(getWorldEntities.invoke(getWorld.invoke(Config.world)))).spliterator(), false); + public Stream entityIterator() { + return StreamSupport.stream(((CraftWorld) Config.world).getHandle().getEntities().getAll().spliterator(), false); } public void setupGamerule() { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java index 35203a20..378c3efc 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHiderWrapper.java @@ -19,7 +19,6 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap; import net.minecraft.core.BlockPos; @@ -34,12 +33,11 @@ import java.util.List; public class HullHiderWrapper { public static final HullHiderWrapper impl = new HullHiderWrapper(); - private static final Reflection.Method getState = Reflection.getTypedMethod(CraftBlockData.class, "getState", BlockState.class); public Object generateBlockChangePacket(List changes) { Object[] blockdata = new Object[changes.size()]; for(int i = 0; i < blockdata.length; i++) { Hull.IntVector change = changes.get(i); - blockdata[i] = getState.invoke(Config.world.getBlockData(change.getX(), change.getY(), change.getZ())); + blockdata[i] = ((CraftBlockData) Config.world.getBlockData(change.getX(), change.getY(), change.getZ())).getState(); } return generateBlockChangePacket(changes, blockdata); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java index 5b5d88d2..3230e84e 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -206,18 +206,10 @@ public final class Reflection { return getField(target, name, fieldType, 0); } - public static Field getField(String className, String name, Class fieldType) { - return getField(getClass(className), name, fieldType, 0); - } - public static Field getField(Class target, Class fieldType, int index) { return getField(target, null, fieldType, index); } - public static Field getField(String className, Class fieldType, int index) { - return getField(getClass(className), fieldType, index); - } - public static Field getField(Class target, Class fieldType, int index, Class... parameters) { return getField(target, null, fieldType, index, parameters); } @@ -268,14 +260,6 @@ public final class Reflection { } } - public static Method getMethod(String className, String methodName, Class... params) { - return getTypedMethod(getClass(className), methodName, null, params); - } - - public static Method getMethod(Class clazz, String methodName, Class... params) { - return getTypedMethod(clazz, methodName, null, params); - } - public static Method getTypedMethod(Class clazz, String methodName, Class returnType, Class... params) { for (final java.lang.reflect.Method method : clazz.getDeclaredMethods()) { if ((methodName == null || method.getName().equals(methodName)) @@ -306,10 +290,6 @@ public final class Reflection { } } - public static Constructor getConstructor(String className, Class... params) { - return getConstructor(getClass(className), params); - } - public static Constructor getConstructor(Class clazz, Class... params) { for (final java.lang.reflect.Constructor constructor : clazz.getDeclaredConstructors()) { if (Arrays.equals(constructor.getParameterTypes(), params)) { @@ -323,12 +303,8 @@ public final class Reflection { public static Object newInstance(Class clazz) { try { - if (Core.getVersion() > 15) { - return Unsafe.getUnsafe().allocateInstance(clazz); - } else { - return clazz.newInstance(); - } - } catch (InstantiationException | IllegalAccessException e) { + return Unsafe.getUnsafe().allocateInstance(clazz); + } catch (InstantiationException e) { throw new SecurityException("Could not create object", e); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java index 2803cf87..713de0eb 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java @@ -47,18 +47,14 @@ public class BountifulWrapper { player.spigot().sendMessage(type, msg); } - private static final Class dataWatcherObject = EntityDataAccessor.class; private static final Class dataWatcherRegistry = EntityDataSerializers.class; private static final Class dataWatcherSerializer = EntityDataSerializer.class; - private static final Reflection.Constructor dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); public Object getDataWatcherObject(int index, Class type) { - return dataWatcherObjectConstructor.invoke(index, Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null)); + return new EntityDataAccessor<>(index, (EntityDataSerializer) Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null)); } - private static final Class item = SynchedEntityData.DataItem.class; - private static final Reflection.Constructor itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class); public Object getDataWatcherItem(Object dwo, Object value) { - return itemConstructor.invoke(dwo, value); + return new SynchedEntityData.DataItem<>((EntityDataAccessor) dwo, value); } public BountifulWrapper.PositionSetter getPositionSetter(Class packetClass, int fieldOffset) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index 31577e6e..04890d42 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -93,7 +93,6 @@ class CheckpointUtilsJ9 { private static final Reflection.Field channelFutures = Reflection.getField(ServerConnectionListener.class, List.class, 0, ChannelFuture.class); - private static final Reflection.Method bind = Reflection.getMethod(ServerConnectionListener.class, null, InetAddress.class, int.class); private static void freezeInternal(Path path) throws Exception { Bukkit.getPluginManager().callEvent(new CRIUSleepEvent()); @@ -137,7 +136,7 @@ class CheckpointUtilsJ9 { } // Reopen socket - bind.invoke(serverConnection, InetAddress.getLoopbackAddress(), port); + serverConnection.startTcpServerListener(InetAddress.getLoopbackAddress(), port); if(Core.getVersion() > 12) { for(Object future : channels) { ((ChannelFuture) future).channel().config().setAutoRead(true); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java index b214330f..a9375b7a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java @@ -21,15 +21,15 @@ package de.steamwar.core; import com.destroystokyo.paper.profile.PlayerProfile; import de.steamwar.Reflection; -import net.minecraft.core.DefaultedRegistry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundSetObjectivePacket; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.ProgressListener; import net.minecraft.world.entity.Pose; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.EntityType; @@ -337,33 +337,18 @@ public class FlatteningWrapper { return displayName != null ? Optional.of(ChatWrapper.impl.stringToChatComponent(displayName)) : Optional.empty(); } - private static final Class registryBlocks = DefaultedRegistry.class; - private static final Class entityTypes = net.minecraft.world.entity.EntityType.class; - private static final Object entityTypesRegistry = Reflection.getField(BuiltInRegistries.class, registryBlocks, 0, entityTypes).get(null); - private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, ResourceLocation.class); - private static final Reflection.Field spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); - private static final Reflection.Field spawnLivingType = spawnType; - private static final Reflection.Method toMinecraft = Reflection.getMethod(CraftNamespacedKey.class, "toMinecraft", NamespacedKey.class); - private static final Map types = new HashMap<>(); - static { - types.put(EntityType.ARMOR_STAND, 1); - } + private static final Reflection.Field spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, net.minecraft.world.entity.EntityType.class, 0); public void setSpawnPacketType(Object packet, EntityType type) { - if(type.isAlive()) { - spawnLivingType.set(packet, Core.getVersion() > 18 ? get.invoke(entityTypesRegistry, toMinecraft.invoke(null, type.getKey())) : types.get(type)); - } else { - spawnType.set(packet, get.invoke(entityTypesRegistry, toMinecraft.invoke(null, type.getKey()))); - } + ResourceLocation key = CraftNamespacedKey.toMinecraft(type.getKey()); + spawnType.set(packet, BuiltInRegistries.ENTITY_TYPE.get(key)); } public int getViewDistance(Player player) { return player.getClientViewDistance(); } - private static final Reflection.Method getHandle = Reflection.getMethod(CraftWorld.class, "getHandle"); - private static final Reflection.Method save = Reflection.getMethod(ServerLevel.class, null, ProgressListener.class, boolean.class, boolean.class); public void syncSave(World world) { - save.invoke(getHandle.invoke(world), null, true, false); + ((CraftWorld) world).getHandle().save(null, true, false); } public enum EntityPose { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index f4acdad5..63aed6a1 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -19,7 +19,6 @@ package de.steamwar.core; -import de.steamwar.Reflection; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; @@ -80,11 +79,8 @@ public class TPSWatcher { } } - private static final Class minecraftServer = MinecraftServer.class; - private static final Reflection.Method getServer = Reflection.getTypedMethod(minecraftServer, "getServer", minecraftServer); - private static final Reflection.Field recentTps = Reflection.getField(minecraftServer, "recentTps", double[].class); private static double[] getSpigotTPS() { - return recentTps.get(getServer.invoke(null)); + return MinecraftServer.getServer().recentTps; } private static double round(double d) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java index cf6ab36a..8f87f63c 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RBlockDisplay.java @@ -19,9 +19,7 @@ package de.steamwar.entity; -import de.steamwar.Reflection; import de.steamwar.core.BountifulWrapper; -import de.steamwar.core.Core; import lombok.Getter; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Location; @@ -60,12 +58,10 @@ public class RBlockDisplay extends RDisplay { sendPacket(updatePacketSink, this::getBlock); } - private static final Class iBlockDataClass = BlockState.class; - private static final Reflection.Method getState = Reflection.getTypedMethod(CraftBlockData.class, "getState", iBlockDataClass); - private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, iBlockDataClass); + private static final Object blockWatcher = BountifulWrapper.impl.getDataWatcherObject(23, BlockState.class); private void getBlock(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || !block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) { - packetSink.accept(blockWatcher, getState.invoke(block)); + packetSink.accept(blockWatcher, ((CraftBlockData) block).getState()); } } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 38184d28..e675a6be 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -449,13 +449,11 @@ public class REntity { private static final Reflection.Field equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0); private static final Reflection.Field equipmentSlots = Reflection.getField(ProtocolWrapper.equipmentPacket, List.class, 0); - private static final Class craftItemStack = CraftItemStack.class; - protected static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class); protected Object getEquipmentPacket(Object slot, ItemStack stack){ Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket); equipmentEntity.set(packet, entityId); equipmentSlots.set(packet, new ArrayList<>()); - ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, asNMSCopy.invoke(null, stack)); + ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, CraftItemStack.asNMSCopy(stack)); return packet; } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 00ce14b7..33d36170 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -19,8 +19,8 @@ package de.steamwar.entity; -import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.Reflection; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; import net.minecraft.network.protocol.game.ServerboundInteractPacket; @@ -54,13 +54,9 @@ public class REntityServer implements Listener { private static final Reflection.Field useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); private static final Function getEntityAction; static { - if(Core.getVersion() > 15) { - Class useEntityEnumActionType = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType"); - Reflection.Method useEntityGetAction = Reflection.getTypedMethod(useEntityEnumAction, null, useEntityEnumActionType); - getEntityAction = value -> ((Enum) useEntityGetAction.invoke(value)).ordinal(); - } else { - getEntityAction = value -> ((Enum) value).ordinal(); - } + Class useEntityEnumActionType = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType"); + Reflection.Method useEntityGetAction = Reflection.getTypedMethod(useEntityEnumAction, null, useEntityEnumActionType); + getEntityAction = value -> ((Enum) useEntityGetAction.invoke(value)).ordinal(); } private final ConcurrentHashMap entityMap = new ConcurrentHashMap<>(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java index 894ba21c..1d78cb8d 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RItemDisplay.java @@ -20,11 +20,11 @@ package de.steamwar.entity; import de.steamwar.core.BountifulWrapper; -import de.steamwar.core.Core; import de.steamwar.core.ProtocolWrapper; import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.EntityType; import org.bukkit.entity.ItemDisplay; import org.bukkit.inventory.ItemStack; @@ -61,14 +61,14 @@ public class RItemDisplay extends RDisplay { sendPacket(updatePacketSink, this::getItemStack); } - private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, ProtocolWrapper.itemStack); + private static final Object itemStackWatcher = BountifulWrapper.impl.getDataWatcherObject(23, ProtocolWrapper.itemStack); private void getItemStack(boolean ignoreDefault, BiConsumer packetSink) { if (ignoreDefault || !itemStack.equals(DEFAULT_ITEM_STACK)) { - packetSink.accept(itemStackWatcher, asNMSCopy.invoke(null, itemStack)); + packetSink.accept(itemStackWatcher, CraftItemStack.asNMSCopy(itemStack)); } } - private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 24 : 23, Byte.class); + private static final Object itemDisplayTransformWatcher = BountifulWrapper.impl.getDataWatcherObject(24, Byte.class); public void setItemDisplayTransform(ItemDisplay.ItemDisplayTransform itemDisplayTransform) { this.itemDisplayTransform = itemDisplayTransform; sendPacket(updatePacketSink, this::getItemDisplayTransform); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java index 4cbee1d6..b5cc352c 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java @@ -27,6 +27,7 @@ import net.minecraft.world.level.material.FlowingFluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; import org.bukkit.Material; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; import java.util.HashSet; import java.util.Set; @@ -67,9 +68,8 @@ public class BlockIds { return ids; } - private static final Reflection.Method getBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getBlock", TechHider.block, Material.class); private Object getBlock(Material material) { - return getBlock.invoke(null, material); + return CraftMagicNumbers.getBlock(material); } public int getCombinedId(Object blockData) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java index 7fc7c439..112970cf 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ChunkHider.java @@ -23,11 +23,9 @@ import de.steamwar.Reflection; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import lombok.Getter; -import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; -import net.minecraft.resources.ResourceLocation; import net.minecraft.util.SimpleBitStorage; import net.minecraft.world.level.block.entity.BlockEntityType; import org.bukkit.entity.Player; @@ -94,14 +92,8 @@ public class ChunkHider { public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo"); protected static final Reflection.Field entityType = Reflection.getField(tileEntity, BlockEntityType.class, 0); - private static final Class builtInRegestries = BuiltInRegistries.class; - private static final Class registry = Registry.class; - private static final Reflection.Field nameField = Reflection.getField(builtInRegestries, "BLOCK_ENTITY_TYPE", registry); - private static final Class resourceLocation = ResourceLocation.class; - private static final Reflection.Method getKey = Reflection.getTypedMethod(registry, "getKey", resourceLocation, Object.class); - private static final Reflection.Method getName = Reflection.getTypedMethod(resourceLocation, "getPath", String.class); protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { - return !hiddenBlockEntities.contains(getName.invoke(getKey.invoke(nameField.get(null), entityType.get(tile)))); + return !hiddenBlockEntities.contains(BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(entityType.get(tile)).getPath()); } private void blocks(SectionHider section) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 4bac686e..b7c64954 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -25,13 +25,7 @@ import de.steamwar.core.Core; import lombok.Getter; import net.minecraft.core.BlockPos; import net.minecraft.core.Vec3i; -import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; -import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundBlockEventPacket; -import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; -import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket; -import net.minecraft.network.protocol.game.ServerboundInteractPacket; -import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; +import net.minecraft.network.protocol.game.*; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Material; @@ -56,16 +50,12 @@ public class TechHider { public static final Class iBlockData = BlockState.class; public static final Class block = Block.class; - private static final Reflection.Method getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); - - public static final Class craftMagicNumbers = CraftMagicNumbers.class; - private static final Reflection.Method getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); public boolean iBlockDataHidden(Object iBlockData) { return obfuscateIds.contains(BlockIds.impl.getCombinedId(iBlockData)); } - public static final Object AIR = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, Material.AIR)); + public static final Object AIR = CraftMagicNumbers.getBlock(Material.AIR).defaultBlockState(); public static final int AIR_ID = BlockIds.impl.materialToId(Material.AIR); private final Map, BiFunction> techhiders = new HashMap<>(); @@ -84,7 +74,7 @@ public class TechHider { this.locationEvaluator = locationEvaluator; this.obfuscateIds = obfuscate.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()); this.hiddenBlockEntities = hiddenBlockEntities; - this.obfuscationTarget = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, obfuscationTarget)); + this.obfuscationTarget = CraftMagicNumbers.getBlock(obfuscationTarget).defaultBlockState(); this.obfuscationTargetId = BlockIds.impl.materialToId(obfuscationTarget); techhiders.put(blockActionPacket, this::blockActionHider); From ab3970981d28201b018163a9ba6edb68f751bbb4 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 16 May 2026 13:46:42 +0200 Subject: [PATCH 5/5] Remove more reflection --- .../src/de/steamwar/techhider/BlockIds.java | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java index b5cc352c..93ac2bda 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java @@ -19,9 +19,10 @@ package de.steamwar.techhider; -import com.google.common.collect.ImmutableList; import de.steamwar.Reflection; import net.minecraft.core.IdMapper; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.material.FlowingFluid; import net.minecraft.world.level.material.FluidState; @@ -35,31 +36,21 @@ import java.util.Set; public class BlockIds { public static final BlockIds impl = new BlockIds(); - Reflection.Method getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); - - private static final Class blockStateList = StateDefinition.class; - private static final Class fluidTypeFlowing = FlowingFluid.class; - private static final Class fluid = FluidState.class; - - private static final Reflection.Method getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); public int materialToId(Material material) { - return getCombinedId(getBlockData.invoke(getBlock(material))); + return getCombinedId(getBlock(material).defaultBlockState()); } - private static final Reflection.Method getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList); - private static final Reflection.Method getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); - private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Fluids.class, fluidTypeFlowing, 1).get(null), false); - private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, IdMapper.class, 0).get(null); - private static final Reflection.Method getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid); + private static final FluidState water = Fluids.WATER.getSource(false); + private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, IdMapper.class, 0).get(null); public Set materialToAllIds(Material material) { Set ids = new HashSet<>(); - for(Object data : (ImmutableList) getStateList.invoke(getStates.invoke(getBlock(material)))) { + for(BlockState data : getBlock(material).getStateDefinition().getPossibleStates()) { ids.add(getCombinedId(data)); } if(material == Material.WATER) { - for(Object data : registryBlockId) { - if(getFluid.invoke(data) == water) { + for(BlockState data : registryBlockId) { + if (data.getFluidState() == water) { ids.add(getCombinedId(data)); } } @@ -68,11 +59,11 @@ public class BlockIds { return ids; } - private Object getBlock(Material material) { + private Block getBlock(Material material) { return CraftMagicNumbers.getBlock(material); } - public int getCombinedId(Object blockData) { - return (int) getCombinedId.invoke(null, blockData); + public int getCombinedId(BlockState blockData) { + return Block.getId(blockData); } }