Remove most calls to Reflection.getClass

This commit is contained in:
2026-05-15 20:33:14 +02:00
parent 2b3c79fcab
commit 3c48e7c02d
23 changed files with 141 additions and 91 deletions
@@ -19,7 +19,6 @@
package de.steamwar.fightsystem.commands; package de.steamwar.fightsystem.commands;
import de.steamwar.Reflection;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
@@ -33,15 +32,14 @@ import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@UtilityClass @UtilityClass
public class Commands { public class Commands {
private static final Reflection.Field<SimpleCommandMap> commandMap = Reflection.getField("org.bukkit.craftbukkit.CraftServer", "commandMap", SimpleCommandMap.class);
public static void injectCommand(Command cmd) { 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){ private static void errNoTeam(Player p){
@@ -25,6 +25,7 @@ import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.fightsystem.utils.WorldOfColorWrapper; import de.steamwar.fightsystem.utils.WorldOfColorWrapper;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import net.minecraft.world.entity.projectile.AbstractArrow;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@@ -43,9 +44,8 @@ public class ArrowStopper {
new StateDependentTask(Config.GameModeConfig.Techhider.Active, FightState.Running, this::run, 1, 1); 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() { private void run() {
Recording.iterateOverEntities(entityArrow::isInstance, entity -> { Recording.iterateOverEntities(AbstractArrow.class::isInstance, entity -> {
Projectile arrow = (Projectile) entity; Projectile arrow = (Projectile) entity;
if (invalidEntity(arrow)) if (invalidEntity(arrow))
return; return;
@@ -20,11 +20,11 @@
package de.steamwar.fightsystem.listener; package de.steamwar.fightsystem.listener;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.Reflection;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.utils.CraftbukkitWrapper; import de.steamwar.fightsystem.utils.CraftbukkitWrapper;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.*; import java.io.*;
@@ -45,7 +45,7 @@ public class ClickAnalyzer {
public ClickAnalyzer() { public ClickAnalyzer() {
TinyProtocol.instance.addFilter(Recording.blockPlacePacket, this::onBlockPlace); TinyProtocol.instance.addFilter(Recording.blockPlacePacket, this::onBlockPlace);
if(Core.getVersion() > 8) 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) { public Object onBlockPlace(Player player, Object packet) {
@@ -40,6 +40,9 @@ import de.steamwar.fightsystem.utils.CraftbukkitWrapper;
import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.utils.SWSound;
import de.steamwar.linkage.Linked; 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.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@@ -79,8 +82,8 @@ public class Recording implements Listener {
return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE; return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE;
} }
public static final Class<?> primedTnt = Reflection.getClass("net.minecraft.world.entity.item.PrimedTnt"); public static final Class<?> primedTnt = PrimedTnt.class;
private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("net.minecraft.world.entity.Entity"), "getBukkitEntity", null); private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(net.minecraft.world.entity.Entity.class, "getBukkitEntity", null);
public static void iterateOverEntities(Predicate<Object> filter, Consumer<Entity> consumer) { public static void iterateOverEntities(Predicate<Object> filter, Consumer<Entity> consumer) {
CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(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); 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 Class<?> playerDigType = blockDigPacket.getDeclaredClasses()[0];
private static final Reflection.Field<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0); private static final Reflection.Field<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0);
private static final Object releaseUseItem = playerDigType.getEnumConstants()[5]; private static final Object releaseUseItem = playerDigType.getEnumConstants()[5];
@@ -141,7 +144,7 @@ public class Recording implements Listener {
return packet; 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) { private Object blockPlace(Player p, Object packet) {
boolean mainHand = BountifulWrapper.impl.mainHand(packet); boolean mainHand = BountifulWrapper.impl.mainHand(packet);
if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p)) if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p))
@@ -26,6 +26,7 @@ import de.steamwar.core.ProtocolWrapper;
import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.FightSystem;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
@@ -33,16 +34,17 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlockState; import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class BlockIdWrapper { public class BlockIdWrapper {
public static final Class<?> worldServer = Reflection.getClass("net.minecraft.server.level.ServerLevel"); public static final Class<?> worldServer = ServerLevel.class;
public static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", worldServer); 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<?> craftPlayer = CraftPlayer.class;
public static final Class<?> entityPlayer = Reflection.getClass("net.minecraft.server.level.ServerPlayer"); public static final Class<?> entityPlayer = ServerPlayer.class;
public static final Reflection.Method getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer); public static final Reflection.Method getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer);
public static final BlockIdWrapper impl = new BlockIdWrapper(); public static final BlockIdWrapper impl = new BlockIdWrapper();
@@ -24,6 +24,7 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.listener.Recording; import de.steamwar.fightsystem.listener.Recording;
import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.record.GlobalRecorder;
import net.minecraft.world.InteractionHand;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeInstance;
@@ -44,7 +45,7 @@ import java.util.Map;
public class BountifulWrapper { public class BountifulWrapper {
public static final BountifulWrapper impl = new 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 Object mainHand = enumHand.getEnumConstants()[0];
private static final Reflection.Field<?> blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0); private static final Reflection.Field<?> blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0);
@@ -30,6 +30,7 @@ import org.bukkit.Chunk;
import org.bukkit.GameRule; import org.bukkit.GameRule;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import java.util.HashSet; import java.util.HashSet;
@@ -40,14 +41,14 @@ import java.util.stream.StreamSupport;
public class CraftbukkitWrapper { public class CraftbukkitWrapper {
public static final CraftbukkitWrapper impl = new 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 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 static final Reflection.Method getChunkSections = Reflection.getTypedMethod(LevelChunk.class, null, LevelChunkSection[].class);
private LevelChunkSection[] getChunkSections(World world, int x, int z) { private LevelChunkSection[] getChunkSections(World world, int x, int z) {
return (LevelChunkSection[]) getChunkSections.invoke(getChunk.invoke(getWorld.invoke(world), x, 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) { protected net.minecraft.world.entity.Entity getEntity(Entity e) {
return (net.minecraft.world.entity.Entity) getEntity.invoke(e); return (net.minecraft.world.entity.Entity) getEntity.invoke(e);
} }
@@ -34,6 +34,9 @@ import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.techhider.TechHider; import de.steamwar.techhider.TechHider;
import lombok.Getter; 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.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@@ -61,7 +64,7 @@ public class HullHider implements Listener {
private final Hull[] hulls; private final Hull[] hulls;
private final Map<Class<?>, BiFunction<Player, Object, Object>> packetHiders = new HashMap<>(); private final Map<Class<?>, BiFunction<Player, Object, Object>> 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() { public HullHider() {
if(!TechHiderWrapper.ENABLED) { if(!TechHiderWrapper.ENABLED) {
hulls = new Hull[0]; 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); private static final Reflection.Field<?> worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0);
public static final Reflection.Field<Integer> blockPositionY = Reflection.getField("net.minecraft.core.Vec3i", int.class, 1); public static final Reflection.Field<Integer> blockPositionY = Reflection.getField(Vec3i.class, int.class, 1);
private Object worldEventHider(Player player, Object packet) { private Object worldEventHider(Player player, Object packet) {
Object baseBlock = worldEventPosition.get(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))); return packetHider(player, packet, new Location(Config.world, TechHider.blockPositionX.get(baseBlock), blockPositionY.get(baseBlock), TechHider.blockPositionZ.get(baseBlock)));
@@ -27,13 +27,14 @@ import net.minecraft.core.SectionPos;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket; import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import java.util.List; import java.util.List;
public class HullHiderWrapper { public class HullHiderWrapper {
public static final HullHiderWrapper impl = new 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<Hull.IntVector> changes) { public Object generateBlockChangePacket(List<Hull.IntVector> changes) {
Object[] blockdata = new Object[changes.size()]; Object[] blockdata = new Object[changes.size()];
for(int i = 0; i < blockdata.length; i++) { for(int i = 0; i < blockdata.length; i++) {
@@ -22,6 +22,10 @@ package de.steamwar.core;
import de.steamwar.Reflection; import de.steamwar.Reflection;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent; 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.entity.PositionMoveRotation;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.bukkit.Sound; import org.bukkit.Sound;
@@ -43,15 +47,15 @@ public class BountifulWrapper {
player.spigot().sendMessage(type, msg); player.spigot().sendMessage(type, msg);
} }
private static final Class<?> dataWatcherObject = Reflection.getClass("net.minecraft.network.syncher.EntityDataAccessor"); private static final Class<?> dataWatcherObject = EntityDataAccessor.class;
private static final Class<?> dataWatcherRegistry = Reflection.getClass("net.minecraft.network.syncher.EntityDataSerializers"); private static final Class<?> dataWatcherRegistry = EntityDataSerializers.class;
private static final Class<?> dataWatcherSerializer = Reflection.getClass("net.minecraft.network.syncher.EntityDataSerializer"); private static final Class<?> dataWatcherSerializer = EntityDataSerializer.class;
private static final Reflection.Constructor dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); private static final Reflection.Constructor dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer);
public Object getDataWatcherObject(int index, Class<?> type) { public Object getDataWatcherObject(int index, Class<?> type) {
return dataWatcherObjectConstructor.invoke(index, Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null)); 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); private static final Reflection.Constructor itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class);
public Object getDataWatcherItem(Object dwo, Object value) { public Object getDataWatcherItem(Object dwo, Object value) {
return itemConstructor.invoke(dwo, value); return itemConstructor.invoke(dwo, value);
@@ -21,9 +21,17 @@ package de.steamwar.core;
import com.destroystokyo.paper.profile.PlayerProfile; import com.destroystokyo.paper.profile.PlayerProfile;
import de.steamwar.Reflection; 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.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.*;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -229,14 +237,14 @@ public class FlatteningWrapper {
renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT); 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) { public void setScoreboardTitle(Object packet, String title) {
scoreboardName.set(packet, ChatWrapper.impl.stringToChatComponent(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 Class<?> scoreActionEnum = null;
private static final Reflection.Field<?> scoreAction = Core.getVersion() < 21 ? Reflection.getField(ClientboundSetScorePacket.class, scoreActionEnum, 0) : null; private static final Reflection.Field<?> scoreAction = null;
private static final Object scoreActionChange = Core.getVersion() < 21 ? scoreActionEnum.getEnumConstants()[0] : null; private static final Object scoreActionChange = null;
public void setScoreAction(Object packet) { public void setScoreAction(Object packet) {
scoreAction.set(packet, scoreActionChange); scoreAction.set(packet, scoreActionChange);
@@ -302,7 +310,7 @@ public class FlatteningWrapper {
return head; 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 shooting = entityPose.getEnumConstants()[16];
protected static final Object standing = entityPose.getEnumConstants()[0]; protected static final Object standing = entityPose.getEnumConstants()[0];
protected static final Object swimming = entityPose.getEnumConstants()[3]; 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(); 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<?> registryBlocks = DefaultedRegistry.class;
private static final Class<?> entityTypes = Reflection.getClass("net.minecraft.world.entity.EntityType"); private static final Class<?> entityTypes = net.minecraft.world.entity.EntityType.class;
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 Object entityTypesRegistry = Reflection.getField(BuiltInRegistries.class, registryBlocks, 0, entityTypes).get(null);
private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("net.minecraft.resources.ResourceLocation")); 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<?> 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.Field<?> spawnLivingType = spawnType;
private static final Reflection.Method toMinecraft = Reflection.getMethod("org.bukkit.craftbukkit.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); private static final Reflection.Method toMinecraft = Reflection.getMethod(CraftNamespacedKey.class, "toMinecraft", NamespacedKey.class);
private static final Map<EntityType, Object> types = new HashMap<>(); private static final Map<EntityType, Object> types = new HashMap<>();
static { static {
types.put(EntityType.ARMOR_STAND, 1); types.put(EntityType.ARMOR_STAND, 1);
@@ -352,8 +360,8 @@ public class FlatteningWrapper {
return player.getClientViewDistance(); return player.getClientViewDistance();
} }
private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftWorld", "getHandle"); private static final Reflection.Method getHandle = Reflection.getMethod(CraftWorld.class, "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 save = Reflection.getMethod(ServerLevel.class, null, ProgressListener.class, boolean.class, boolean.class);
public void syncSave(World world) { public void syncSave(World world) {
save.invoke(getHandle.invoke(world), null, true, false); save.invoke(getHandle.invoke(world), null, true, false);
} }
@@ -22,6 +22,7 @@ package de.steamwar.core;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import de.steamwar.Reflection; import de.steamwar.Reflection;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
@@ -35,13 +36,10 @@ import java.util.EnumSet;
public class ProtocolWrapper { public class ProtocolWrapper {
public static final Class<?> itemStack = Reflection.getClass("net.minecraft.world.item.ItemStack"); public static final Class<?> itemStack = ItemStack.class;
public static final Class<?> spawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddEntityPacket"); public static final Class<?> spawnPacket = ClientboundAddEntityPacket.class;
public static final Class<?> spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving"); public static final Class<?> spawnLivingPacket = ProtocolWrapper.spawnPacket;
public static final Class<?> equipmentPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket"); public static final Class<?> equipmentPacket = ClientboundSetEquipmentPacket.class;
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);
// 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head // 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 Object[] itemSlots = Core.getVersion() > 8 ? Reflection.getClass("net.minecraft.world.entity.EnumItemSlot").getEnumConstants() : new Integer[]{0, 0, 1, 2, 3, 4};
@@ -20,6 +20,7 @@
package de.steamwar.core; package de.steamwar.core;
import de.steamwar.Reflection; import de.steamwar.Reflection;
import net.minecraft.server.MinecraftServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
public class TPSWatcher { 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.Method getServer = Reflection.getTypedMethod(minecraftServer, "getServer", minecraftServer);
private static final Reflection.Field<double[]> recentTps = Reflection.getField(minecraftServer, "recentTps", double[].class); private static final Reflection.Field<double[]> recentTps = Reflection.getField(minecraftServer, "recentTps", double[].class);
private static double[] getSpigotTPS() { private static double[] getSpigotTPS() {
@@ -32,7 +32,7 @@ public class WorldIdentifier {
private static ResourceKey<Level> resourceKey = null; private static ResourceKey<Level> 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 Class<?> minecraftKeyClass = Reflection.getClass("net.minecraft.resources.MinecraftKey");
private static final Reflection.Constructor resourceKeyConstructor = Reflection.getConstructor(resourceKeyClass, minecraftKeyClass, minecraftKeyClass); private static final Reflection.Constructor resourceKeyConstructor = Reflection.getConstructor(resourceKeyClass, minecraftKeyClass, minecraftKeyClass);
private static final Reflection.Constructor minecraftKeyConstructor = Reflection.getConstructor(minecraftKeyClass, String.class, String.class); private static final Reflection.Constructor minecraftKeyConstructor = Reflection.getConstructor(minecraftKeyClass, String.class, String.class);
@@ -26,6 +26,9 @@ import de.steamwar.linkage.Linked;
import de.steamwar.sql.SWException; import de.steamwar.sql.SWException;
import de.steamwar.techhider.ProtocolUtils; import de.steamwar.techhider.ProtocolUtils;
import de.steamwar.techhider.TechHider; 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.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -54,11 +57,11 @@ public class AntiNocom implements Listener {
} }
private void registerUseItem() { private void registerUseItem() {
Class<?> useItem = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"); Class<?> useItem = ServerboundUseItemOnPacket.class;
Function<Object, Object> getPosition; Function<Object, Object> getPosition;
if(Core.getVersion() > 12) { 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<?> useItemPosition = Reflection.getField(useItem, movingObjectPositionBlock, 0);
Reflection.Field<?> movingBlockPosition = Reflection.getField(movingObjectPositionBlock, TechHider.blockPosition, 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 static final Reflection.Field<?> digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0);
private Object onDig(Player player, Object packet) { private Object onDig(Player player, Object packet) {
Object pos = digPosition.get(packet); Object pos = digPosition.get(packet);
@@ -23,9 +23,11 @@ import de.steamwar.Reflection;
import de.steamwar.core.BountifulWrapper; import de.steamwar.core.BountifulWrapper;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import lombok.Getter; import lombok.Getter;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@@ -58,8 +60,8 @@ public class RBlockDisplay extends RDisplay {
sendPacket(updatePacketSink, this::getBlock); sendPacket(updatePacketSink, this::getBlock);
} }
private static final Class<?> iBlockDataClass = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); private static final Class<?> iBlockDataClass = BlockState.class;
private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", iBlockDataClass); 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(Core.getVersion() >= 21 ? 23 : 22, iBlockDataClass);
private void getBlock(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) { private void getBlock(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
if (ignoreDefault || !block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) { if (ignoreDefault || !block.getAsString(true).equals(DEFAULT_BLOCK.getAsString(true))) {
@@ -24,7 +24,9 @@ import de.steamwar.core.*;
import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntList;
import lombok.Getter; import lombok.Getter;
import net.minecraft.network.protocol.game.*;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -160,7 +162,7 @@ public class REntity {
server.postEntityMove(this, fromX, fromZ); 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<Integer> animationEntity = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 5 : 6) : 0); private static final Reflection.Field<Integer> animationEntity = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 5 : 6) : 0);
private static final Reflection.Field<Integer> animationAnimation = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 6 : 7) : 1); private static final Reflection.Field<Integer> animationAnimation = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 6 : 7) : 1);
public void showAnimation(byte animation) { public void showAnimation(byte animation) {
@@ -170,7 +172,7 @@ public class REntity {
server.updateEntity(this, packet); 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<Integer> velocityEntity = Reflection.getField(velocityPacket, int.class, 0); private static final Reflection.Field<Integer> velocityEntity = Reflection.getField(velocityPacket, int.class, 0);
private static final Reflection.Field<Integer> velocityX = Reflection.getField(velocityPacket, int.class, 1); private static final Reflection.Field<Integer> velocityX = Reflection.getField(velocityPacket, int.class, 1);
private static final Reflection.Field<Integer> velocityY = Reflection.getField(velocityPacket, int.class, 2); private static final Reflection.Field<Integer> velocityY = Reflection.getField(velocityPacket, int.class, 2);
@@ -184,7 +186,7 @@ public class REntity {
server.updateEntity(this, packet); 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<Integer> statusEntity = Reflection.getField(statusPacket, int.class, 0); private static final Reflection.Field<Integer> statusEntity = Reflection.getField(statusPacket, int.class, 0);
private static final Reflection.Field<Byte> statusStatus = Reflection.getField(statusPacket, byte.class, 0); private static final Reflection.Field<Byte> statusStatus = Reflection.getField(statusPacket, byte.class, 0);
public void showDamage() { 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; private static final Reflection.Field<?> destroyEntities;
static { static {
if(Core.getVersion() > 15) if(Core.getVersion() > 15)
@@ -395,7 +397,7 @@ public class REntity {
return ChatWrapper.impl.getDataWatcherPacket(entityId, dataWatcherKeyValues); 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<Integer> teleportEntity = Reflection.getField(teleportPacket, int.class, 0); public static final Reflection.Field<Integer> teleportEntity = Reflection.getField(teleportPacket, int.class, 0);
public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0); public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0);
private Object getTeleportPacket(){ private Object getTeleportPacket(){
@@ -409,12 +411,12 @@ public class REntity {
return packet; 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<Integer> moveEntityId = Reflection.getField(entityPacket, int.class, 0); private static final Reflection.Field<Integer> moveEntityId = Reflection.getField(entityPacket, int.class, 0);
private static final BountifulWrapper.PositionSetter movePosition = BountifulWrapper.impl.getRelMoveSetter(entityPacket); 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<?> lookPacket = ClientboundMoveEntityPacket.Rot.class;
private static final Class<?> movePacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Pos"); private static final Class<?> movePacket = ClientboundMoveEntityPacket.Pos.class;
private static final Class<?> moveLookPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$PosRot"); private static final Class<?> moveLookPacket = ClientboundMoveEntityPacket.PosRot.class;
private Object getMoveLookPacket(double diffX, double diffY, double diffZ, boolean rotEq) { private Object getMoveLookPacket(double diffX, double diffY, double diffZ, boolean rotEq) {
Class<?> clazz; Class<?> clazz;
if(diffX == 0 && diffY == 0 && diffZ == 0) { if(diffX == 0 && diffY == 0 && diffZ == 0) {
@@ -434,7 +436,7 @@ public class REntity {
return packet; 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<Integer> headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); private static final Reflection.Field<Integer> headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0);
private static final Reflection.Field<Byte> headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); private static final Reflection.Field<Byte> headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0);
private Object getHeadRotationPacket(){ private Object getHeadRotationPacket(){
@@ -447,7 +449,7 @@ public class REntity {
private static final Reflection.Field<Integer> equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0); private static final Reflection.Field<Integer> equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0);
private static final Reflection.Field<List> equipmentSlots = Reflection.getField(ProtocolWrapper.equipmentPacket, List.class, 0); private static final Reflection.Field<List> 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 static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class);
protected Object getEquipmentPacket(Object slot, ItemStack stack){ protected Object getEquipmentPacket(Object slot, ItemStack stack){
Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket); Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket);
@@ -23,6 +23,7 @@ import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.core.FlatteningWrapper; import de.steamwar.core.FlatteningWrapper;
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -47,7 +48,7 @@ public class REntityServer implements Listener {
private static final HashSet<REntity> emptyEntities = new HashSet<>(0); private static final HashSet<REntity> emptyEntities = new HashSet<>(0);
private static final HashSet<Player> emptyPlayers = new HashSet<>(0); private static final HashSet<Player> 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<Integer> useEntityTarget = Reflection.getField(useEntity, int.class, 0); private static final Reflection.Field<Integer> useEntityTarget = Reflection.getField(useEntity, int.class, 0);
private static final Class<?> useEntityEnumAction = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action"); 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); private static final Reflection.Field<?> useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0);
@@ -24,6 +24,7 @@ import de.steamwar.core.BountifulWrapper;
import de.steamwar.core.ChatWrapper; import de.steamwar.core.ChatWrapper;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import lombok.Getter; import lombok.Getter;
import net.minecraft.network.chat.Component;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.TextDisplay; import org.bukkit.entity.TextDisplay;
@@ -74,7 +75,7 @@ public class RTextDisplay extends RDisplay {
sendPacket(updatePacketSink, this::getText); 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 static final Object textWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() >= 21 ? 23 : 22, iChatBaseComponent);
private void getText(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) { private void getText(boolean ignoreDefault, BiConsumer<Object, Object> packetSink) {
if (ignoreDefault || !text.isEmpty()) { if (ignoreDefault || !text.isEmpty()) {
@@ -19,17 +19,18 @@
package de.steamwar.network.handlers; package de.steamwar.network.handlers;
import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import de.steamwar.linkage.MinVersion; import de.steamwar.linkage.MinVersion;
import net.minecraft.network.protocol.game.ClientboundServerDataPacket;
import net.minecraft.network.protocol.game.ServerboundChatSessionUpdatePacket;
@Linked @Linked
@MinVersion(19) @MinVersion(19)
public class ServerDataHandler { public class ServerDataHandler {
public ServerDataHandler() { public ServerDataHandler() {
TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ClientboundServerDataPacket"), (p, o) -> null); TinyProtocol.instance.addFilter(ClientboundServerDataPacket.class, (p, o) -> null);
TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundChatSessionUpdatePacket"), (player, packet) -> null); TinyProtocol.instance.addFilter(ServerboundChatSessionUpdatePacket.class, (player, packet) -> null);
} }
} }
@@ -21,6 +21,11 @@ package de.steamwar.techhider;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import de.steamwar.Reflection; 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 org.bukkit.Material;
import java.util.HashSet; import java.util.HashSet;
@@ -31,9 +36,9 @@ public class BlockIds {
Reflection.Method getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); 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<?> blockStateList = StateDefinition.class;
private static final Class<?> fluidTypeFlowing = Reflection.getClass("net.minecraft.world.level.material.FlowingFluid"); private static final Class<?> fluidTypeFlowing = FlowingFluid.class;
private static final Class<?> fluid = Reflection.getClass("net.minecraft.world.level.material.FluidState"); private static final Class<?> fluid = FluidState.class;
private static final Reflection.Method getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); private static final Reflection.Method getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData);
public int materialToId(Material material) { 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 getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList);
private static final Reflection.Method getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); 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 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, Reflection.getClass("net.minecraft.core.IdMapper"), 0).get(null); 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 Reflection.Method getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid);
public Set<Integer> materialToAllIds(Material material) { public Set<Integer> materialToAllIds(Material material) {
Set<Integer> ids = new HashSet<>(); Set<Integer> ids = new HashSet<>();
@@ -23,8 +23,11 @@ import de.steamwar.Reflection;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import lombok.Getter; 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.ClientboundLevelChunkPacketData;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.SimpleBitStorage; import net.minecraft.util.SimpleBitStorage;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import org.bukkit.entity.Player; 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"); public static final Class<?> tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo");
protected static final Reflection.Field<BlockEntityType> entityType = Reflection.getField(tileEntity, BlockEntityType.class, 0); protected static final Reflection.Field<BlockEntityType> entityType = Reflection.getField(tileEntity, BlockEntityType.class, 0);
private static final Class<?> builtInRegestries = Reflection.getClass("net.minecraft.core.registries.BuiltInRegistries"); private static final Class<?> builtInRegestries = BuiltInRegistries.class;
private static final Class<?> registry = Reflection.getClass("net.minecraft.core.Registry"); private static final Class<?> registry = Registry.class;
private static final Reflection.Field<?> nameField = Reflection.getField(builtInRegestries, "BLOCK_ENTITY_TYPE", registry); 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 getKey = Reflection.getTypedMethod(registry, "getKey", resourceLocation, Object.class);
private static final Reflection.Method getName = Reflection.getTypedMethod(resourceLocation, "getPath", String.class); private static final Reflection.Method getName = Reflection.getTypedMethod(resourceLocation, "getPath", String.class);
protected boolean tileEntityVisible(Set<String> hiddenBlockEntities, Object tile) { protected boolean tileEntityVisible(Set<String> hiddenBlockEntities, Object tile) {
@@ -23,7 +23,19 @@ import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.Reflection; import de.steamwar.Reflection;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import lombok.Getter; 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.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.HashMap; import java.util.HashMap;
@@ -36,17 +48,17 @@ import java.util.stream.Collectors;
public class TechHider { public class TechHider {
public static final Class<?> blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); public static final Class<?> blockPosition = BlockPos.class;
private static final Class<?> baseBlockPosition = Reflection.getClass("net.minecraft.core.Vec3i"); private static final Class<?> baseBlockPosition = Vec3i.class;
public static final Reflection.Field<Integer> blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); public static final Reflection.Field<Integer> blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0);
public static final Reflection.Field<Integer> blockPositionY = Reflection.getField(baseBlockPosition, int.class, 1); public static final Reflection.Field<Integer> blockPositionY = Reflection.getField(baseBlockPosition, int.class, 1);
public static final Reflection.Field<Integer> blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); public static final Reflection.Field<Integer> 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<?> iBlockData = BlockState.class;
public static final Class<?> block = Reflection.getClass("net.minecraft.world.level.block.Block"); public static final Class<?> block = Block.class;
private static final Reflection.Method getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); 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); private static final Reflection.Method getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class);
public boolean iBlockDataHidden(Object iBlockData) { public boolean iBlockDataHidden(Object iBlockData) {
@@ -82,14 +94,14 @@ public class TechHider {
techhiders.put(ChunkHider.impl.mapChunkPacket(), ChunkHider.impl.chunkHiderGenerator(this)); techhiders.put(ChunkHider.impl.mapChunkPacket(), ChunkHider.impl.chunkHiderGenerator(this));
if(Core.getVersion() > 12 && Core.getVersion() < 19) { 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)); techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass, this));
} }
if(Core.getVersion() > 8){ 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); 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<Object> multiBlockChangeCloner = ProtocolUtils.shallowCloneGenerator(TechHider.multiBlockChangePacket); public static final UnaryOperator<Object> 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<Object, Object> blockChangeCloner = ProtocolUtils.shallowCloneGenerator(blockChangePacket); private static final Function<Object, Object> blockChangeCloner = ProtocolUtils.shallowCloneGenerator(blockChangePacket);
private static final Reflection.Field<?> blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); private static final Reflection.Field<?> blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0);
private static final Reflection.Field<?> blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 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 static final Reflection.Field<?> blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0);
private Object blockActionHider(Player p, Object packet) { private Object blockActionHider(Player p, Object packet) {
if (locationEvaluator.checkBlockPos(p, blockActionPosition.get(packet)) == State.SKIP) if (locationEvaluator.checkBlockPos(p, blockActionPosition.get(packet)) == State.SKIP)
@@ -135,7 +147,7 @@ public class TechHider {
return null; 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 static final Reflection.Field<?> tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0);
private Object tileEntityDataHider(Player p, Object packet) { private Object tileEntityDataHider(Player p, Object packet) {
switch (locationEvaluator.checkBlockPos(p, tileEntityDataPosition.get(packet))) { switch (locationEvaluator.checkBlockPos(p, tileEntityDataPosition.get(packet))) {