Move and rename Reflection fields

This commit is contained in:
Lixfel
2024-12-26 19:11:01 +01:00
parent bd87221198
commit 0f73939bf0
80 changed files with 547 additions and 805 deletions
@@ -19,13 +19,12 @@
package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.Reflection;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.minecraft.server.v1_8_R3.ChatComponentText;
import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
@@ -51,7 +50,7 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
}
private static final Class<?> watchableObject = Reflection.getClass("{nms}.DataWatcher$WatchableObject");
private static final Reflection.ConstructorInvoker watchableObjectConstructor = Reflection.getConstructor(watchableObject, int.class, int.class, Object.class);
private static final Reflection.Constructor watchableObjectConstructor = Reflection.getConstructor(watchableObject, int.class, int.class, Object.class);
private static final Map<Class<?>, Integer> watchableDatatypes = new HashMap<>();
static {
watchableDatatypes.put(byte.class, 0);
@@ -68,11 +67,11 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
@Override
public BountifulWrapper.PositionSetter getPositionSetter(Class<?> packetClass, int fieldOffset) {
Reflection.FieldAccessor<Integer> posX = Reflection.getField(packetClass, int.class, fieldOffset);
Reflection.FieldAccessor<Integer> posY = Reflection.getField(packetClass, int.class, fieldOffset +1);
Reflection.FieldAccessor<Integer> posZ = Reflection.getField(packetClass, int.class, fieldOffset +2);
Reflection.FieldAccessor<Byte> lookPitch = Reflection.getField(packetClass, byte.class, 0);
Reflection.FieldAccessor<Byte> lookYaw = Reflection.getField(packetClass, byte.class, 1);
Reflection.Field<Integer> posX = Reflection.getField(packetClass, int.class, fieldOffset);
Reflection.Field<Integer> posY = Reflection.getField(packetClass, int.class, fieldOffset +1);
Reflection.Field<Integer> posZ = Reflection.getField(packetClass, int.class, fieldOffset +2);
Reflection.Field<Byte> lookPitch = Reflection.getField(packetClass, byte.class, 0);
Reflection.Field<Byte> lookYaw = Reflection.getField(packetClass, byte.class, 1);
return (packet, x, y, z, pitch, yaw) -> {
posX.set(packet, MathHelper.floor(x * 32));
@@ -85,11 +84,11 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
@Override
public BountifulWrapper.PositionSetter getRelMoveSetter(Class<?> packetClass) {
Reflection.FieldAccessor<?> moveX = Reflection.getField(packetClass, "b", byte.class);
Reflection.FieldAccessor<?> moveY = Reflection.getField(packetClass, "c", byte.class);
Reflection.FieldAccessor<?> moveZ = Reflection.getField(packetClass, "d", byte.class);
Reflection.FieldAccessor<Byte> lookYaw = Reflection.getField(packetClass, "e", byte.class);
Reflection.FieldAccessor<Byte> lookPitch = Reflection.getField(packetClass, "f", byte.class);
Reflection.Field<?> moveX = Reflection.getField(packetClass, "b", byte.class);
Reflection.Field<?> moveY = Reflection.getField(packetClass, "c", byte.class);
Reflection.Field<?> moveZ = Reflection.getField(packetClass, "d", byte.class);
Reflection.Field<Byte> lookYaw = Reflection.getField(packetClass, "e", byte.class);
Reflection.Field<Byte> lookPitch = Reflection.getField(packetClass, "f", byte.class);
return (packet, x, y, z, pitch, yaw) -> {
moveX.set(packet, (byte)(x*32));
@@ -19,22 +19,22 @@
package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.Reflection;
import java.util.ArrayList;
import java.util.List;
public class ChatWrapper8 implements ChatWrapper {
private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class);
private static final Reflection.Constructor chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class);
@Override
public Object stringToChatComponent(String text) {
return chatComponentConstructor.invoke(text);
}
private static final Class<?> metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata");
private static final Reflection.FieldAccessor<Integer> metadataEntity = Reflection.getField(metadataPacket, int.class, 0);
private static final Reflection.FieldAccessor<List> metadataMetadata = Reflection.getField(metadataPacket, List.class, 0);
private static final Reflection.Field<Integer> metadataEntity = Reflection.getField(metadataPacket, int.class, 0);
private static final Reflection.Field<List> metadataMetadata = Reflection.getField(metadataPacket, List.class, 0);
@Override
public Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues) {
Object packet = Reflection.newInstance(metadataPacket);
@@ -19,7 +19,7 @@
package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.Reflection;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
@@ -32,9 +32,9 @@ import java.util.Map;
public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper {
private static final Reflection.FieldAccessor<String> scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 1);
private static final Reflection.Field<String> scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 1);
private static final Class<?> scoreActionEnum = Reflection.getClass("{nms}.PacketPlayOutScoreboardScore$EnumScoreboardAction");
private static final Reflection.FieldAccessor<?> scoreAction = Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0);
private static final Reflection.Field<?> scoreAction = Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0);
private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0];
@Override
@@ -78,9 +78,9 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper
private static final Class<?> dataWatcher = Reflection.getClass("{nms}.DataWatcher");
private static final Class<?> namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn");
private static final Reflection.FieldAccessor<?> namedSpawnDataWatcher = Reflection.getField(namedSpawnPacket, dataWatcher, 0);
private static final Reflection.Field<?> namedSpawnDataWatcher = Reflection.getField(namedSpawnPacket, dataWatcher, 0);
private static final Class<?> entity = Reflection.getClass("{nms}.Entity");
private static final Reflection.ConstructorInvoker dataWatcherConstructor = Reflection.getConstructor(dataWatcher, entity);
private static final Reflection.Constructor dataWatcherConstructor = Reflection.getConstructor(dataWatcher, entity);
@Override
public void setNamedSpawnPacketDataWatcher(Object packet) {
namedSpawnDataWatcher.set(packet, dataWatcherConstructor.invoke((Object) null));
@@ -92,8 +92,8 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper
}
private static final Reflection.FieldAccessor<?> spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9);
private static final Reflection.FieldAccessor<Integer> spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1);
private static final Reflection.Field<?> spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9);
private static final Reflection.Field<Integer> spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1);
private static final Map<EntityType, Object> types = new HashMap<>();
static {
types.put(TrickyTrialsWrapper.impl.getTntEntityType(), 50);
@@ -113,7 +113,7 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper
return 10;
}
private static final Reflection.MethodInvoker save = Reflection.getMethod("{obc}.CraftWorld", "save", boolean.class);
private static final Reflection.Method save = Reflection.getMethod("{obc}.CraftWorld", "save", boolean.class);
@Override
public void syncSave(World world) {
save.invoke(world, true);
@@ -19,7 +19,7 @@
package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.Reflection;
import com.mojang.authlib.GameProfile;
import org.bukkit.GameMode;
@@ -29,7 +29,7 @@ import java.util.List;
public class ProtocolWrapper8 implements ProtocolWrapper {
private static final Reflection.FieldAccessor<?> equipmentSlot;
private static final Reflection.Field<?> equipmentSlot;
static {
if(Core.getVersion() == 8) {
equipmentSlot = Reflection.getField(equipmentPacket, int.class, 1);
@@ -39,7 +39,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper {
}
}
private static final Reflection.FieldAccessor<?> equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0);
private static final Reflection.Field<?> equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0);
@Override
public void setEquipmentPacketStack(Object packet, Object slot, Object stack) {
equipmentSlot.set(packet, slot);
@@ -48,8 +48,8 @@ public class ProtocolWrapper8 implements ProtocolWrapper {
private static final Class<?> playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo");
private static final Class<?> playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction");
private static final Reflection.FieldAccessor<?> playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0);
private static final Reflection.FieldAccessor<List> playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0);
private static final Reflection.Field<?> playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0);
private static final Reflection.Field<List> playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0);
private static final EnumMap<PlayerInfoAction, Object> actions = new EnumMap<>(PlayerInfoAction.class);
static {
Object[] nativeActions = playerInfoActionClass.getEnumConstants();
@@ -58,7 +58,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper {
actions.put(PlayerInfoAction.REMOVE, nativeActions[4]);
}
private static final Class<?> iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent");
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData", playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent);
private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData", playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent);
@Override
@SuppressWarnings("deprecation")
@@ -19,7 +19,7 @@
package de.steamwar.scoreboard;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.core.Core;
import de.steamwar.core.FlatteningWrapper;
@@ -30,15 +30,15 @@ import java.util.HashMap;
import java.util.Map;
public class SWScoreboard8 implements SWScoreboard {
private static final Reflection.FieldAccessor<String> scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 0);
private static final Reflection.FieldAccessor<Integer> scoreboardAction = Reflection.getField(FlatteningWrapper.scoreboardObjective, int.class, Core.getVersion() > 15 ? 3 : 0);
private static final Reflection.Field<String> scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 0);
private static final Reflection.Field<Integer> scoreboardAction = Reflection.getField(FlatteningWrapper.scoreboardObjective, int.class, Core.getVersion() > 15 ? 3 : 0);
private static final Class<?> scoreboardDisplayEnum = Reflection.getClass("{nms.world.scores.criteria}.IScoreboardCriteria$EnumScoreboardHealthDisplay");
private static final Reflection.FieldAccessor<?> scoreboardDisplayType = Reflection.getField(FlatteningWrapper.scoreboardObjective, scoreboardDisplayEnum, 0);
private static final Reflection.Field<?> scoreboardDisplayType = Reflection.getField(FlatteningWrapper.scoreboardObjective, scoreboardDisplayEnum, 0);
private static final Object displayTypeIntegers = scoreboardDisplayEnum.getEnumConstants()[0];
private static final Reflection.FieldAccessor<String> scoreName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 0);
private static final Reflection.FieldAccessor<String> scoreScoreboardName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 1);
private static final Reflection.FieldAccessor<Integer> scoreValue = Reflection.getField(FlatteningWrapper.scoreboardScore, int.class, 0);
private static final Reflection.Field<String> scoreName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 0);
private static final Reflection.Field<String> scoreScoreboardName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 1);
private static final Reflection.Field<Integer> scoreValue = Reflection.getField(FlatteningWrapper.scoreboardScore, int.class, 0);
private static final HashMap<Player, ScoreboardCallback> playerBoards = new HashMap<>(); //Object -> Scoreboard | Alle Versionen in der Map!
private static int toggle = 0; // Scoreboard 0 updates while scoreboard 1 is presenting. toggle marks the current active scoreboard
@@ -49,8 +49,8 @@ public class SWScoreboard8 implements SWScoreboard {
static {
Class<?> scoreboardDisplayObjective = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardDisplayObjective");
Reflection.FieldAccessor<String> scoreboardDisplayName = Reflection.getField(scoreboardDisplayObjective, String.class, 0);
Reflection.FieldAccessor<Integer> scoreboardDisplaySlot = Reflection.getField(scoreboardDisplayObjective, int.class, 0);
Reflection.Field<String> scoreboardDisplayName = Reflection.getField(scoreboardDisplayObjective, String.class, 0);
Reflection.Field<Integer> scoreboardDisplaySlot = Reflection.getField(scoreboardDisplayObjective, int.class, 0);
for(int id = 0; id < 2; id++) {
DELETE_SCOREBOARD[id] = Reflection.newInstance(FlatteningWrapper.scoreboardObjective);
scoreboardName.set(DELETE_SCOREBOARD[id], SIDEBAR + id);
@@ -19,7 +19,7 @@
package de.steamwar.techhider;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.Reflection;
import org.bukkit.entity.Player;
import java.util.function.BiFunction;
@@ -19,7 +19,7 @@
package de.steamwar.techhider;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.Reflection;
import org.bukkit.entity.Player;
import java.lang.reflect.Array;
@@ -28,15 +28,15 @@ import java.util.function.BiFunction;
public class ProtocolWrapper8 implements ProtocolWrapper {
private static final Class<?> chunkCoordinateIntPair = Reflection.getClass("{nms}.ChunkCoordIntPair");
private static final Reflection.FieldAccessor<?> multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, chunkCoordinateIntPair, 0);
private static final Reflection.FieldAccessor<Integer> chunkCoordinateX = Reflection.getField(chunkCoordinateIntPair, int.class, 0);
private static final Reflection.FieldAccessor<Integer> chunkCoordinateZ = Reflection.getField(chunkCoordinateIntPair, int.class, 1);
private static final Reflection.Field<?> multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, chunkCoordinateIntPair, 0);
private static final Reflection.Field<Integer> chunkCoordinateX = Reflection.getField(chunkCoordinateIntPair, int.class, 0);
private static final Reflection.Field<Integer> chunkCoordinateZ = Reflection.getField(chunkCoordinateIntPair, int.class, 1);
private static final Class<?> multiBlockChangeInfo = Reflection.getClass("{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo");
private static final Reflection.ConstructorInvoker multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData);
private static final Reflection.FieldAccessor<?> multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0);
private static final Reflection.FieldAccessor<?> multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0);
private static final Reflection.Constructor multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData);
private static final Reflection.Field<?> multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0);
private static final Reflection.Field<?> multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0);
private static final Class<?> multiBlockChangeInfoArray = Reflection.getClass("[L{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;");
private static final Reflection.FieldAccessor<?> multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0);
private static final Reflection.Field<?> multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0);
@Override
public BiFunction<Player, Object, Object> multiBlockChangeGenerator(TechHider techHider) {
return (p, packet) -> {
@@ -72,7 +72,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper {
};
}
private static final Reflection.FieldAccessor<Integer> tileEntityDataAction = Reflection.getField(TechHider.tileEntityDataPacket, int.class, 0);
private static final Reflection.Field<Integer> tileEntityDataAction = Reflection.getField(TechHider.tileEntityDataPacket, int.class, 0);
@Override
public boolean unfilteredTileEntityDataAction(Object packet) {
return tileEntityDataAction.get(packet) != 9;