diff --git a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index e0eb2ea..5ed2b45 100644 --- a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -328,7 +328,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper private static final Class registryBlocks = Reflection.getClass("{nms.core}.RegistryBlocks"); private static final Class entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes"); - private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass("{nms.core}.IRegistry"), registryBlocks, 0, entityTypes).get(null); + private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass(Core.getVersion() > 18 ? "net.minecraft.core.registries.BuiltInRegistries" : "{nms.core}.IRegistry"), registryBlocks, 0, entityTypes).get(null); private static final Reflection.MethodInvoker get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("{nms.resources}.MinecraftKey")); private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); private static final Reflection.FieldAccessor spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); diff --git a/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java b/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java index e3d4ea7..1627791 100644 --- a/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java +++ b/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java @@ -22,16 +22,19 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; +import net.minecraft.world.level.World; import net.minecraft.world.level.chunk.Chunk; +import net.minecraft.world.level.lighting.LightEngine; import org.bukkit.entity.Player; public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper { private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + private static final Reflection.MethodInvoker getLightEngine = Reflection.getTypedMethod(World.class, null, LightEngine.class); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { Chunk chunk = (Chunk) getHandle.invoke(p.getWorld().getChunkAt(chunkX, chunkZ)); - TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, chunk.q.l_(), null, null, false)); + TinyProtocol.instance.sendPacket(p, new ClientboundLevelChunkWithLightPacket(chunk, (LightEngine) getLightEngine.invoke(chunk.q), null, null, false, true)); } } diff --git a/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java b/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java index 94f6131..54cc303 100644 --- a/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java +++ b/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java @@ -22,8 +22,10 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; +import org.bukkit.GameMode; import java.util.Collections; +import java.util.EnumMap; import java.util.List; public class ProtocolWrapper18 implements ProtocolWrapper { @@ -34,9 +36,26 @@ public class ProtocolWrapper18 implements ProtocolWrapper { equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); } - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); + 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 playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); + private static final EnumMap actions = new EnumMap<>(PlayerInfoAction.class); + static { + Object[] nativeActions = playerInfoActionClass.getEnumConstants(); + actions.put(PlayerInfoAction.ADD, nativeActions[0]); + actions.put(PlayerInfoAction.GAMEMODE, nativeActions[1]); + 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", GameProfile.class, int.class, enumGamemode, iChatBaseComponent); + @Override - public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { - return playerInfoDataConstructor.invoke(profile, 0, mode, null); + @SuppressWarnings("deprecation") + public Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode) { + Object packet = Reflection.newInstance(playerInfoPacket); + playerInfoAction.set(packet, actions.get(action)); + playerInfoData.set(packet, Collections.singletonList(playerInfoDataConstructor.invoke(profile, 0, ProtocolWrapper.getGameModeById.invoke(null, mode.getValue()), null))); + return packet; } } diff --git a/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java b/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java index 9dde1ad..b847d1b 100644 --- a/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java +++ b/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java @@ -20,6 +20,7 @@ package de.steamwar.techhider; import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.core.Core; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import net.minecraft.core.IRegistry; @@ -77,7 +78,7 @@ public class ChunkHider18 implements ChunkHider { public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a"); protected static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); - private static final IRegistry tileEntityTypes = Reflection.getField(IRegistry.class, IRegistry.class, 0, TileEntityTypes.class).get(null); + private static final IRegistry tileEntityTypes = Reflection.getField(Core.getVersion() > 18 ? Reflection.getClass("net.minecraft.core.registries.BuiltInRegistries") : IRegistry.class, IRegistry.class, 0, TileEntityTypes.class).get(null); private static final Reflection.MethodInvoker getKey = Reflection.getTypedMethod(IRegistry.class, null, MinecraftKey.class, Object.class); private static final Reflection.MethodInvoker getName = Reflection.getTypedMethod(MinecraftKey.class, null, String.class); protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { diff --git a/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java b/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java index 86c23fb..b4b0f8f 100644 --- a/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java +++ b/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java @@ -22,8 +22,13 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; +import net.minecraft.world.level.EnumGamemode; +import org.bukkit.GameMode; import java.util.Collections; +import java.util.EnumSet; import java.util.List; public class ProtocolWrapper19 implements ProtocolWrapper { @@ -34,9 +39,19 @@ public class ProtocolWrapper19 implements ProtocolWrapper { equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); } - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, GameProfile.class, int.class, enumGamemode, iChatBaseComponent, Reflection.getClass("net.minecraft.world.entity.player.ProfilePublicKey$a")); + private static final Reflection.ConstructorInvoker removePacketConstructor = Reflection.getConstructor(ClientboundPlayerInfoRemovePacket.class, List.class); + private static final Reflection.FieldAccessor updateActions = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, EnumSet.class, 0); + private static final Reflection.FieldAccessor updatePlayers = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, List.class, 0); + @Override - public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { - return playerInfoDataConstructor.invoke(profile, 0, mode, null, null); + @SuppressWarnings("deprecation") + public Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode) { + if(action == PlayerInfoAction.REMOVE) + return removePacketConstructor.invoke(Collections.singletonList(profile.getId())); + + Object packet = Reflection.newInstance(ClientboundPlayerInfoUpdatePacket.class); + updateActions.set(packet, action == PlayerInfoAction.ADD ? EnumSet.of(ClientboundPlayerInfoUpdatePacket.a.a, ClientboundPlayerInfoUpdatePacket.a.c) : EnumSet.of(ClientboundPlayerInfoUpdatePacket.a.c)); + updatePlayers.set(packet, Collections.singletonList(new ClientboundPlayerInfoUpdatePacket.b(profile.getId(), profile, false, 0, EnumGamemode.a(mode.getValue()), null, null))); + return packet; } } diff --git a/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java b/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java index 98aa0a2..9f0b234 100644 --- a/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java @@ -21,6 +21,11 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; +import org.bukkit.GameMode; + +import java.util.Collections; +import java.util.EnumMap; +import java.util.List; public class ProtocolWrapper8 implements ProtocolWrapper { @@ -41,9 +46,26 @@ public class ProtocolWrapper8 implements ProtocolWrapper { equipmentStack.set(packet, stack); } - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); + 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 playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); + private static final EnumMap actions = new EnumMap<>(PlayerInfoAction.class); + static { + Object[] nativeActions = playerInfoActionClass.getEnumConstants(); + actions.put(PlayerInfoAction.ADD, nativeActions[0]); + actions.put(PlayerInfoAction.GAMEMODE, nativeActions[1]); + 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); + @Override - public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { - return playerInfoDataConstructor.invoke(packet, profile, 0, mode, null); + @SuppressWarnings("deprecation") + public Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode) { + Object packet = Reflection.newInstance(playerInfoPacket); + playerInfoAction.set(packet, actions.get(action)); + playerInfoData.set(packet, Collections.singletonList(playerInfoDataConstructor.invoke(packet, profile, 0, ProtocolWrapper.getGameModeById.invoke(null, mode.getValue()), null))); + return packet; } } diff --git a/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java b/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java index ca02e58..6d140ca 100644 --- a/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java +++ b/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java @@ -21,6 +21,7 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; +import org.bukkit.GameMode; public interface ProtocolWrapper { @@ -28,10 +29,9 @@ public interface ProtocolWrapper { Class spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity"); Class spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntityLiving"); Class equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment"); - Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); - Class playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData"); + Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); - Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); + Reflection.MethodInvoker getGameModeById = Reflection.getTypedMethod(enumGamemode, null, enumGamemode, int.class); // 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head Object[] itemSlots = Core.getVersion() > 8 ? Reflection.getClass("{nms.world.entity}.EnumItemSlot").getEnumConstants() : new Integer[]{0, 0, 1, 2, 3, 4}; @@ -40,6 +40,11 @@ public interface ProtocolWrapper { void setEquipmentPacketStack(Object packet, Object slot, Object stack); - Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode); + Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode); + enum PlayerInfoAction { + ADD, + GAMEMODE, + REMOVE + } } diff --git a/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index c862db6..dde86cb 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -25,12 +25,11 @@ import de.steamwar.core.BountifulWrapper; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; import de.steamwar.core.ProtocolWrapper; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; -import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.UUID; import java.util.function.Consumer; @@ -84,7 +83,7 @@ public class RPlayer extends REntity { @Override void spawn(Consumer packetSink) { - packetSink.accept(getPlayerInfoPacket(addPlayer)); + packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, new GameProfile(uuid, name), GameMode.CREATIVE)); packetSink.accept(getNamedSpawnPacket()); packetSink.accept(getDataWatcherPacket(skinPartsDataWatcher, (byte) 0x7F)); @@ -99,20 +98,7 @@ public class RPlayer extends REntity { void despawn(Consumer packetSink) { //team.removeEntry(name); super.despawn(packetSink); - packetSink.accept(getPlayerInfoPacket(removePlayer)); - } - - private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); - private static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0]; - private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(ProtocolWrapper.playerInfoPacket, playerInfoActionClass, 0); - private static final Object removePlayer = playerInfoActionClass.getEnumConstants()[4]; - private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(ProtocolWrapper.playerInfoPacket, List.class, 0); - private static final Object creative = ProtocolWrapper.enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 1 : 2]; - private Object getPlayerInfoPacket(Object action){ - Object packet = Reflection.newInstance(ProtocolWrapper.playerInfoPacket); - playerInfoAction.set(packet, action); - playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, new GameProfile(uuid, name), creative))); - return packet; + packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, new GameProfile(uuid, name), GameMode.CREATIVE)); } private static final Class namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn");