SteamWar/FightSystem
Archiviert
13
1

WIP 1.18 support
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2022-01-14 21:42:18 +01:00
Ursprung 6c0c6a7ae1
Commit 411e1ae539
9 geänderte Dateien mit 125 neuen und 67 gelöschten Zeilen

Datei anzeigen

@ -120,9 +120,9 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
// field not present // field not present
} }
private static final Class<?> entityTypes = Reflection.getClass("{nms}.EntityTypes"); private static final Class<?> entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes");
private static final Reflection.FieldAccessor<?> spawnType = Reflection.getField(REntity.spawnPacket, entityTypes, 0); private static final Reflection.FieldAccessor<?> spawnType = Reflection.getField(REntity.spawnPacket, entityTypes, 0);
private static final Object tnt = Reflection.getField(entityTypes, "TNT", entityTypes).get(null); private static final Object tnt = Reflection.getField(entityTypes, "TNT", entityTypes).get(null); //TODO: Names not usable in 1.18
private static final Object arrow = Reflection.getField(entityTypes, "ARROW", entityTypes).get(null); private static final Object arrow = Reflection.getField(entityTypes, "ARROW", entityTypes).get(null);
private static final Object fireball = Reflection.getField(entityTypes, "FIREBALL", entityTypes).get(null); private static final Object fireball = Reflection.getField(entityTypes, "FIREBALL", entityTypes).get(null);
@Override @Override

Datei anzeigen

@ -36,6 +36,44 @@
<artifactId>FightSystem_18</artifactId> <artifactId>FightSystem_18</artifactId>
<version>1.0</version> <version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
@ -43,6 +81,12 @@
<version>1.18-R0.1-SNAPSHOT</version> <version>1.18-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>datafixerupper</artifactId>
<version>4.0.26</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>steamwar</groupId> <groupId>steamwar</groupId>
<artifactId>Spigot</artifactId> <artifactId>Spigot</artifactId>

Datei anzeigen

@ -19,15 +19,15 @@
package de.steamwar.fightsystem.utils; package de.steamwar.fightsystem.utils;
import com.sk89q.worldedit.world.fluid.FluidTypes;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import net.minecraft.core.BlockPosition; import net.minecraft.core.BlockPos;
import net.minecraft.core.IRegistry; import net.minecraft.core.Registry;
import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.WorldServer; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityPose; import net.minecraft.world.entity.Pose;
import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
@ -38,35 +38,36 @@ import java.util.Objects;
import java.util.Set; import java.util.Set;
public class BlockIdWrapper18 implements BlockIdWrapper.IBlockIdWrapper { public class BlockIdWrapper18 implements BlockIdWrapper.IBlockIdWrapper {
@Override @Override
public int blockToId(Block block) { public int blockToId(Block block) {
return net.minecraft.world.level.block.Block.p.a(((CraftBlock)block).getNMS()); return net.minecraft.world.level.block.Block.getId(((CraftBlock)block).getNMS());
} }
@Override @Override
public void setBlock(World world, int x, int y, int z, int blockState) { public void setBlock(World world, int x, int y, int z, int blockState) {
IBlockData blockData = Objects.requireNonNull(net.minecraft.world.level.block.Block.a(blockState)); BlockState blockData = Objects.requireNonNull(net.minecraft.world.level.block.Block.stateById(blockState));
WorldServer cworld = ((CraftWorld)world).getHandle(); ServerLevel cworld = ((CraftWorld)world).getHandle();
BlockPosition pos = new BlockPosition(x, y, z); BlockPos pos = new BlockPos(x, y, z);
cworld.removeTileEntity(pos); cworld.removeBlockEntity(pos);
cworld.setTypeAndData(pos, blockData, 1042); cworld.setBlock(pos, blockData, 1042);
cworld.getChunkProvider().flagDirty(pos); cworld.getChunkSource().blockChanged(pos);
} }
@Override @Override
public Set<Integer> getHiddenBlockIds() { public Set<Integer> getHiddenBlockIds() {
Set<Integer> hiddenBlockIds = new HashSet<>(); Set<Integer> hiddenBlockIds = new HashSet<>();
for(String tag : Config.HiddenBlocks){ for(String tag : Config.HiddenBlocks){
for(IBlockData data : IRegistry.k.get(new MinecraftKey(tag)).getStates().a()){ for(BlockState data : Registry.BLOCK.get(new ResourceLocation(tag)).getStateDefinition().getPossibleStates()){
hiddenBlockIds.add(net.minecraft.world.level.block.Block.getCombinedId(data)); hiddenBlockIds.add(net.minecraft.world.level.block.Block.getId(data));
} }
} }
if(Config.HiddenBlocks.contains("water")){ if(Config.HiddenBlocks.contains("water")){
Fluid water = FluidTypes.WATER.a(false); FluidState water = Fluids.WATER.defaultFluidState();
for(IBlockData data : net.minecraft.world.level.block.Block.p){ for(BlockState data : net.minecraft.world.level.block.Block.BLOCK_STATE_REGISTRY) {
if(data.getFluid() == water){ if(data.getFluidState() == water) {
hiddenBlockIds.add(net.minecraft.world.level.block.Block.getCombinedId(data)); hiddenBlockIds.add(net.minecraft.world.level.block.Block.getId(data));
} }
} }
} }
@ -76,11 +77,11 @@ public class BlockIdWrapper18 implements BlockIdWrapper.IBlockIdWrapper {
@Override @Override
public int getObfuscateWith() { public int getObfuscateWith() {
return net.minecraft.world.level.block.Block.i(IRegistry.k.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); return net.minecraft.world.level.block.Block.getId(Registry.BLOCK.get(new ResourceLocation(Config.ObfuscateWith)).defaultBlockState());
} }
@Override @Override
public Object getPose(boolean sneaking) { public Object getPose(boolean sneaking) {
return sneaking ? EntityPose.f : EntityPose.a; return sneaking ? Pose.CROUCHING : Pose.STANDING;
} }
} }

Datei anzeigen

@ -19,8 +19,7 @@
package de.steamwar.fightsystem.utils; package de.steamwar.fightsystem.utils;
import de.steamwar.fightsystem.fight.FightWorld; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity;
@ -37,34 +36,33 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrap
@Override @Override
public void resetChunk(World world, World backup, int x, int z) { public void resetChunk(World world, World backup, int x, int z) {
net.minecraft.world.level.World w = ((CraftWorld) world).getHandle(); net.minecraft.world.level.Level w = ((CraftWorld) world).getHandle();
Chunk chunk = w.d(x, z); LevelChunk chunk = w.getChunk(x, z);
Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); LevelChunk backupChunk = ((CraftWorld) backup).getHandle().getChunk(x, z);
System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length);
w.tileEntityListTick.removeAll(chunk.tileEntities.values());
if (!FightWorld.isPaper()) { //w.blockEntityTickers.removeAll(chunk.tickersInLevel.values());
w.tileEntityList.removeAll(chunk.tileEntities.values()); //if (!FightWorld.isPaper()) {
} // w.blockEntityTickersPending.removeAll(chunk.tickersInLevel.values());
chunk.tileEntities.clear(); //}
chunk.tileEntities.putAll(backupChunk.tileEntities); //chunk.tickersInLevel.clear();
chunk.heightMap.clear(); //chunk.tickersInLevel.putAll(backupChunk.tickersInLevel);
chunk.heightMap.putAll(backupChunk.heightMap);
} }
@Override @Override
public void sendResourcePack(Player player, String pack, String sha1) { public void sendResourcePack(Player player, String pack, String sha1) {
((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); ((CraftPlayer)player).getHandle().sendTexturePack(pack, sha1, true, null);
} }
@Override @Override
public float headRotation(Entity e) { public float headRotation(Entity e) {
return ((CraftEntity)e).getHandle().getHeadRotation(); return ((CraftEntity)e).getHandle().getYHeadRot();
} }
@Override @Override
public boolean hasItems(ItemStack stack) { public boolean hasItems(ItemStack stack) {
Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).s().d()); Set<String> keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getAllKeys());
keys.remove("Enchantments"); keys.remove("Enchantments");
keys.remove("Damage"); keys.remove("Damage");
return !keys.isEmpty(); return !keys.isEmpty();

Datei anzeigen

@ -46,7 +46,7 @@ import java.util.UUID;
public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
private static final Class<?> enumHand = Reflection.getClass("{nms}.EnumHand"); private static final Class<?> enumHand = Reflection.getClass("{nms.world}.EnumHand");
private static final Object mainHand = enumHand.getEnumConstants()[0]; private static final Object mainHand = enumHand.getEnumConstants()[0];
private static final Reflection.FieldAccessor<?> blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0); private static final Reflection.FieldAccessor<?> blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0);
@ -118,9 +118,9 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
} }
private static final Class<?> dataWatcherObject = Reflection.getClass("{nms}.DataWatcherObject"); private static final Class<?> dataWatcherObject = Reflection.getClass("{nms.network.syncher}.DataWatcherObject");
private static final Class<?> dataWatcherRegistry = Reflection.getClass("{nms}.DataWatcherRegistry"); private static final Class<?> dataWatcherRegistry = Reflection.getClass("{nms.network.syncher}.DataWatcherRegistry");
private static final Class<?> dataWatcherSerializer = Reflection.getClass("{nms}.DataWatcherSerializer"); private static final Class<?> dataWatcherSerializer = Reflection.getClass("{nms.network.syncher}.DataWatcherSerializer");
private static final Reflection.ConstructorInvoker dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); private static final Reflection.ConstructorInvoker dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer);
@Override @Override
public Object getDataWatcherObject(int index, Class<?> type) { public Object getDataWatcherObject(int index, Class<?> type) {
@ -136,7 +136,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
throw new SecurityException("Could not find Serializer for " + type.getName()); throw new SecurityException("Could not find Serializer for " + type.getName());
} }
private static final Class<?> item = Reflection.getClass("{nms}.DataWatcher$Item"); private static final Class<?> item = Reflection.getClass("{nms.network.syncher}.DataWatcher$Item");
private static final Reflection.ConstructorInvoker itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class); private static final Reflection.ConstructorInvoker itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class);
@Override @Override
public Object getDataWatcherItem(Object dwo, Object value) { public Object getDataWatcherItem(Object dwo, Object value) {
@ -159,7 +159,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
spawnUUID.set(packet, uuid); spawnUUID.set(packet, uuid);
} }
private static final Class<?> enumItemSlot = Reflection.getClass("{nms}.EnumItemSlot"); private static final Class<?> enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot");
private static final Reflection.FieldAccessor<?> equipmentSlot = Reflection.getField(REntity.equipmentPacket, enumItemSlot, 0); private static final Reflection.FieldAccessor<?> equipmentSlot = Reflection.getField(REntity.equipmentPacket, enumItemSlot, 0);
private static final Object[] itemSlots = enumItemSlot.getEnumConstants(); private static final Object[] itemSlots = enumItemSlot.getEnumConstants();
@Override @Override

Datei anzeigen

@ -24,6 +24,12 @@
<version>1.18-R0.1-SNAPSHOT</version> <version>1.18-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>8.5.6</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
<artifactId>netty-all</artifactId> <artifactId>netty-all</artifactId>

Datei anzeigen

@ -130,19 +130,19 @@ public class Fight {
} }
} }
private static final Class<?> playerInfoPacket = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo"); private static final Class<?> playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo");
private static final Reflection.ConstructorInvoker playerInfoConstructor = Reflection.getConstructor(playerInfoPacket); private static final Reflection.ConstructorInvoker playerInfoConstructor = Reflection.getConstructor(playerInfoPacket);
private static final Class<?> playerInfoActionClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); private static final Class<?> playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction");
public static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0]; public static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0];
private static final Reflection.FieldAccessor<?> playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); private static final Reflection.FieldAccessor<?> playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0);
private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1]; private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1];
public static final Object removePlayer = playerInfoActionClass.getEnumConstants()[4]; public static final Object removePlayer = playerInfoActionClass.getEnumConstants()[4];
private static final Reflection.FieldAccessor<List> playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); private static final Reflection.FieldAccessor<List> playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0);
private static final Class<?> playerInfoDataClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$PlayerInfoData"); private static final Class<?> playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData");
private static final Class<?> enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); private static final Class<?> enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode");
public static final Object creative = enumGamemode.getEnumConstants()[2]; public static final Object creative = enumGamemode.getEnumConstants()[2];
private static final Object spectator = enumGamemode.getEnumConstants()[4]; private static final Object spectator = enumGamemode.getEnumConstants()[4];
private static final Class<?> iChatBaseComponent = Reflection.getClass("{nms}.IChatBaseComponent"); private static final Class<?> iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent");
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent);
public static void pseudoSpectator(Player player, boolean enable) { public static void pseudoSpectator(Player player, boolean enable) {

Datei anzeigen

@ -115,7 +115,7 @@ public class Recording implements Listener {
}, 1, 1); }, 1, 1);
} }
private static final Class<?> blockDigPacket = Reflection.getClass("{nms}.PacketPlayInBlockDig"); private static final Class<?> blockDigPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig");
private static final Class<?> playerDigType = blockDigPacket.getDeclaredClasses()[0]; private static final Class<?> playerDigType = blockDigPacket.getDeclaredClasses()[0];
private static final Reflection.FieldAccessor<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0); private static final Reflection.FieldAccessor<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0);
private static final Object releaseUseItem = playerDigType.getEnumConstants()[5]; private static final Object releaseUseItem = playerDigType.getEnumConstants()[5];
@ -125,7 +125,7 @@ public class Recording implements Listener {
return packet; return packet;
} }
public static final Class<?> blockPlacePacket = Reflection.getClass("{nms}.PacketPlayInBlockPlace"); public static final Class<?> blockPlacePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockPlace");
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(BountifulWrapper.impl.bowInHand(mainHand, p)) if(BountifulWrapper.impl.bowInHand(mainHand, p))

Datei anzeigen

@ -31,6 +31,8 @@ import de.steamwar.fightsystem.utils.BountifulWrapper;
import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.fightsystem.utils.ProtocolAPI; import de.steamwar.fightsystem.utils.ProtocolAPI;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -174,7 +176,7 @@ public class REntity {
ProtocolAPI.broadcastPacket(getHeadRotationPacket()); ProtocolAPI.broadcastPacket(getHeadRotationPacket());
} }
private static final Class<?> animationPacket = Reflection.getClass("{nms}.PacketPlayOutAnimation"); private static final Class<?> animationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutAnimation");
private static final Reflection.ConstructorInvoker animationConstructor = Reflection.getConstructor(animationPacket); private static final Reflection.ConstructorInvoker animationConstructor = Reflection.getConstructor(animationPacket);
private static final Reflection.FieldAccessor<Integer> animationEntity = Reflection.getField(animationPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> animationEntity = Reflection.getField(animationPacket, int.class, 0);
private static final Reflection.FieldAccessor<Integer> animationAnimation = Reflection.getField(animationPacket, int.class, 1); private static final Reflection.FieldAccessor<Integer> animationAnimation = Reflection.getField(animationPacket, int.class, 1);
@ -185,7 +187,7 @@ public class REntity {
ProtocolAPI.broadcastPacket(packet); ProtocolAPI.broadcastPacket(packet);
} }
private static final Class<?> velocityPacket = Reflection.getClass("{nms}.PacketPlayOutEntityVelocity"); private static final Class<?> velocityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity");
private static final Reflection.ConstructorInvoker velocityConstructor = Reflection.getConstructor(velocityPacket); private static final Reflection.ConstructorInvoker velocityConstructor = Reflection.getConstructor(velocityPacket);
private static final Reflection.FieldAccessor<Integer> velocityEntity = Reflection.getField(velocityPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> velocityEntity = Reflection.getField(velocityPacket, int.class, 0);
private static final Reflection.FieldAccessor<Integer> velocityX = Reflection.getField(velocityPacket, int.class, 1); private static final Reflection.FieldAccessor<Integer> velocityX = Reflection.getField(velocityPacket, int.class, 1);
@ -200,7 +202,7 @@ public class REntity {
ProtocolAPI.broadcastPacket(packet); ProtocolAPI.broadcastPacket(packet);
} }
private static final Class<?> statusPacket = Reflection.getClass("{nms}.PacketPlayOutEntityStatus"); private static final Class<?> statusPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityStatus");
private static final Reflection.ConstructorInvoker statusConstructor = Reflection.getConstructor(statusPacket); private static final Reflection.ConstructorInvoker statusConstructor = Reflection.getConstructor(statusPacket);
private static final Reflection.FieldAccessor<Integer> statusEntity = Reflection.getField(statusPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> statusEntity = Reflection.getField(statusPacket, int.class, 0);
private static final Reflection.FieldAccessor<Byte> statusStatus = Reflection.getField(statusPacket, byte.class, 0); private static final Reflection.FieldAccessor<Byte> statusStatus = Reflection.getField(statusPacket, byte.class, 0);
@ -248,9 +250,16 @@ public class REntity {
entities.remove(internalId); entities.remove(internalId);
} }
private static final Class<?> destroyPacket = Reflection.getClass("{nms}.PacketPlayOutEntityDestroy"); private static final Class<?> destroyPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityDestroy");
private static final Reflection.ConstructorInvoker destroyConstructor = Reflection.getConstructor(destroyPacket); private static final Reflection.ConstructorInvoker destroyConstructor = Reflection.getConstructor(destroyPacket);
private static final Reflection.FieldAccessor<int[]> destroyEntities = Reflection.getField(destroyPacket, int[].class, 0); private static final Reflection.FieldAccessor<?> destroyEntities;
static {
if(Core.getVersion() > 15)
destroyEntities = Reflection.getField(destroyPacket, IntList.class, 0);
else
destroyEntities = Reflection.getField(destroyPacket, int[].class, 0);
}
private void broadcastDeath(){ private void broadcastDeath(){
if(entityType == EntityType.PLAYER){ if(entityType == EntityType.PLAYER){
ProtocolAPI.broadcastPacket(Fight.playerInfoPacket(Fight.removePlayer, new GameProfile(uuid, name), Fight.creative)); ProtocolAPI.broadcastPacket(Fight.playerInfoPacket(Fight.removePlayer, new GameProfile(uuid, name), Fight.creative));
@ -258,7 +267,7 @@ public class REntity {
} }
Object packet = destroyConstructor.invoke(); Object packet = destroyConstructor.invoke();
destroyEntities.set(packet, new int[]{entityId}); destroyEntities.set(packet, Core.getVersion() > 15 ? new IntArrayList(new int[]{entityId}) : new int[]{entityId});
ProtocolAPI.broadcastPacket(packet); ProtocolAPI.broadcastPacket(packet);
} }
@ -266,7 +275,7 @@ public class REntity {
return (int)(Math.max(-3.9, Math.min(value, 3.9)) * 8000); return (int)(Math.max(-3.9, Math.min(value, 3.9)) * 8000);
} }
private static final Class<?> metadataPacket = Reflection.getClass("{nms}.PacketPlayOutEntityMetadata"); private static final Class<?> metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata");
private static final Reflection.ConstructorInvoker metadataConstructor = Reflection.getConstructor(metadataPacket); private static final Reflection.ConstructorInvoker metadataConstructor = Reflection.getConstructor(metadataPacket);
private static final Reflection.FieldAccessor<Integer> metadataEntity = Reflection.getField(metadataPacket, int.class, 0); 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.FieldAccessor<List> metadataMetadata = Reflection.getField(metadataPacket, List.class, 0);
@ -277,7 +286,7 @@ public class REntity {
return packet; return packet;
} }
public static final Class<?> teleportPacket = Reflection.getClass("{nms}.PacketPlayOutEntityTeleport"); public static final Class<?> teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport");
private static final Reflection.ConstructorInvoker teleportConstructor = Reflection.getConstructor(teleportPacket); private static final Reflection.ConstructorInvoker teleportConstructor = Reflection.getConstructor(teleportPacket);
private static final Reflection.FieldAccessor<Integer> teleportEntity = Reflection.getField(teleportPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> teleportEntity = Reflection.getField(teleportPacket, int.class, 0);
private static final Reflection.FieldAccessor<Byte> teleportYaw = Reflection.getField(teleportPacket, byte.class, 0); private static final Reflection.FieldAccessor<Byte> teleportYaw = Reflection.getField(teleportPacket, byte.class, 0);
@ -291,7 +300,7 @@ public class REntity {
return packet; return packet;
} }
private static final Class<?> headRotationPacket = Reflection.getClass("{nms}.PacketPlayOutEntityHeadRotation"); private static final Class<?> headRotationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityHeadRotation");
private static final Reflection.ConstructorInvoker headRotationConstructor = Reflection.getConstructor(headRotationPacket); private static final Reflection.ConstructorInvoker headRotationConstructor = Reflection.getConstructor(headRotationPacket);
private static final Reflection.FieldAccessor<Integer> headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0);
private static final Reflection.FieldAccessor<Byte> headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); private static final Reflection.FieldAccessor<Byte> headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0);
@ -302,7 +311,7 @@ public class REntity {
return packet; return packet;
} }
public static final Class<?> spawnPacket = Reflection.getClass("{nms}.PacketPlayOutSpawnEntity"); public static final Class<?> spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity");
private static final Reflection.ConstructorInvoker spawnConstructor = Reflection.getConstructor(spawnPacket); private static final Reflection.ConstructorInvoker spawnConstructor = Reflection.getConstructor(spawnPacket);
private static final Reflection.FieldAccessor<Integer> spawnEntity = Reflection.getField(spawnPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> spawnEntity = Reflection.getField(spawnPacket, int.class, 0);
private Object getSpawnEntityPacket(){ private Object getSpawnEntityPacket(){
@ -313,11 +322,11 @@ public class REntity {
return packet; return packet;
} }
public static final Class<?> equipmentPacket = Reflection.getClass("{nms}.PacketPlayOutEntityEquipment"); public static final Class<?> equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment");
private static final Reflection.ConstructorInvoker equipmentConstructor = Reflection.getConstructor(equipmentPacket); private static final Reflection.ConstructorInvoker equipmentConstructor = Reflection.getConstructor(equipmentPacket);
private static final Reflection.FieldAccessor<Integer> equipmentEntity = Reflection.getField(equipmentPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> equipmentEntity = Reflection.getField(equipmentPacket, int.class, 0);
private static final Class<?> itemStack = Reflection.getClass("{nms}.ItemStack"); private static final Class<?> itemStack = Reflection.getClass("{nms}.ItemStack");
private static final Reflection.FieldAccessor<?> equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0); private static final Reflection.FieldAccessor<?> equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0); //TODO: Changed in 1.18
private static final Class<?> craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack"); private static final Class<?> craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack");
private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(craftItemStack, "asNMSCopy", itemStack, ItemStack.class); private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(craftItemStack, "asNMSCopy", itemStack, ItemStack.class);
private Object getEquipmentPacket(String slot, ItemStack stack){ private Object getEquipmentPacket(String slot, ItemStack stack){
@ -332,7 +341,7 @@ public class REntity {
return Fight.playerInfoPacket(Fight.addPlayer, new GameProfile(uuid, name), Fight.creative); return Fight.playerInfoPacket(Fight.addPlayer, new GameProfile(uuid, name), Fight.creative);
} }
public static final Class<?> namedSpawnPacket = Reflection.getClass("{nms}.PacketPlayOutNamedEntitySpawn"); public static final Class<?> namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn");
private static final Reflection.ConstructorInvoker namedSpawnConstructor = Reflection.getConstructor(namedSpawnPacket); private static final Reflection.ConstructorInvoker namedSpawnConstructor = Reflection.getConstructor(namedSpawnPacket);
private static final Reflection.FieldAccessor<Integer> namedSpawnEntity = Reflection.getField(namedSpawnPacket, int.class, 0); private static final Reflection.FieldAccessor<Integer> namedSpawnEntity = Reflection.getField(namedSpawnPacket, int.class, 0);
private static final Reflection.FieldAccessor<UUID> namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); private static final Reflection.FieldAccessor<UUID> namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0);