SteamWar/SpigotCore
Archiviert
13
0

Merge pull request '1.19.3 compatibility' (#226) from 1.19.3 into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #226
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2023-03-03 16:18:37 +01:00
Commit 258d72b6f8
8 geänderte Dateien mit 84 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -328,7 +328,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
private static final Class<?> registryBlocks = Reflection.getClass("{nms.core}.RegistryBlocks"); private static final Class<?> registryBlocks = Reflection.getClass("{nms.core}.RegistryBlocks");
private static final Class<?> entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes"); 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.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<?> spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0);
private static final Reflection.FieldAccessor<?> spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); private static final Reflection.FieldAccessor<?> spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1);

Datei anzeigen

@ -22,16 +22,19 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol; import com.comphenix.tinyprotocol.TinyProtocol;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; 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.chunk.Chunk;
import net.minecraft.world.level.lighting.LightEngine;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper { public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper {
private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); 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 @Override
public void sendChunk(Player p, int chunkX, int chunkZ) { public void sendChunk(Player p, int chunkX, int chunkZ) {
Chunk chunk = (Chunk) getHandle.invoke(p.getWorld().getChunkAt(chunkX, 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));
} }
} }

Datei anzeigen

@ -22,8 +22,10 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import org.bukkit.GameMode;
import java.util.Collections; import java.util.Collections;
import java.util.EnumMap;
import java.util.List; import java.util.List;
public class ProtocolWrapper18 implements ProtocolWrapper { public class ProtocolWrapper18 implements ProtocolWrapper {
@ -34,9 +36,26 @@ public class ProtocolWrapper18 implements ProtocolWrapper {
equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); 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<List> playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0);
private static final EnumMap<PlayerInfoAction, Object> 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 @Override
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { @SuppressWarnings("deprecation")
return playerInfoDataConstructor.invoke(profile, 0, mode, null); 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;
} }
} }

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.techhider; package de.steamwar.techhider;
import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.core.Core;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator; import io.netty.buffer.UnpooledByteBufAllocator;
import net.minecraft.core.IRegistry; 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"); public static final Class<?> tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a");
protected static final Reflection.FieldAccessor<TileEntityTypes> entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); protected static final Reflection.FieldAccessor<TileEntityTypes> 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 getKey = Reflection.getTypedMethod(IRegistry.class, null, MinecraftKey.class, Object.class);
private static final Reflection.MethodInvoker getName = Reflection.getTypedMethod(MinecraftKey.class, null, String.class); private static final Reflection.MethodInvoker getName = Reflection.getTypedMethod(MinecraftKey.class, null, String.class);
protected boolean tileEntityVisible(Set<String> hiddenBlockEntities, Object tile) { protected boolean tileEntityVisible(Set<String> hiddenBlockEntities, Object tile) {

Datei anzeigen

@ -22,8 +22,13 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Pair; 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.Collections;
import java.util.EnumSet;
import java.util.List; import java.util.List;
public class ProtocolWrapper19 implements ProtocolWrapper { public class ProtocolWrapper19 implements ProtocolWrapper {
@ -34,9 +39,19 @@ public class ProtocolWrapper19 implements ProtocolWrapper {
equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); 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<EnumSet> updateActions = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, EnumSet.class, 0);
private static final Reflection.FieldAccessor<List> updatePlayers = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, List.class, 0);
@Override @Override
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { @SuppressWarnings("deprecation")
return playerInfoDataConstructor.invoke(profile, 0, mode, null, null); 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;
} }
} }

Datei anzeigen

@ -21,6 +21,11 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile; 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 { public class ProtocolWrapper8 implements ProtocolWrapper {
@ -41,9 +46,26 @@ public class ProtocolWrapper8 implements ProtocolWrapper {
equipmentStack.set(packet, stack); 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<List> playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0);
private static final EnumMap<PlayerInfoAction, Object> 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 @Override
public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { @SuppressWarnings("deprecation")
return playerInfoDataConstructor.invoke(packet, profile, 0, mode, null); 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;
} }
} }

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import org.bukkit.GameMode;
public interface ProtocolWrapper { public interface ProtocolWrapper {
@ -28,10 +29,9 @@ public interface ProtocolWrapper {
Class<?> spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity"); Class<?> spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity");
Class<?> spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntityLiving"); Class<?> spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntityLiving");
Class<?> equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment"); 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<?> 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 // 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}; 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); 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
}
} }

Datei anzeigen

@ -25,12 +25,11 @@ import de.steamwar.core.BountifulWrapper;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.core.FlatteningWrapper; import de.steamwar.core.FlatteningWrapper;
import de.steamwar.core.ProtocolWrapper; import de.steamwar.core.ProtocolWrapper;
import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -84,7 +83,7 @@ public class RPlayer extends REntity {
@Override @Override
void spawn(Consumer<Object> packetSink) { void spawn(Consumer<Object> packetSink) {
packetSink.accept(getPlayerInfoPacket(addPlayer)); packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, new GameProfile(uuid, name), GameMode.CREATIVE));
packetSink.accept(getNamedSpawnPacket()); packetSink.accept(getNamedSpawnPacket());
packetSink.accept(getDataWatcherPacket(skinPartsDataWatcher, (byte) 0x7F)); packetSink.accept(getDataWatcherPacket(skinPartsDataWatcher, (byte) 0x7F));
@ -99,20 +98,7 @@ public class RPlayer extends REntity {
void despawn(Consumer<Object> packetSink) { void despawn(Consumer<Object> packetSink) {
//team.removeEntry(name); //team.removeEntry(name);
super.despawn(packetSink); super.despawn(packetSink);
packetSink.accept(getPlayerInfoPacket(removePlayer)); packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, new GameProfile(uuid, name), GameMode.CREATIVE));
}
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<List> 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;
} }
private static final Class<?> namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn"); private static final Class<?> namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn");