SteamWar/FightSystem
Archiviert
13
1

TinyProtocol #290

Zusammengeführt
Lixfel hat 10 Commits von tinyProtocol nach master 2021-09-30 13:29:16 +02:00 zusammengeführt
7 geänderte Dateien mit 33 neuen und 29 gelöschten Zeilen
Nur Änderungen aus Commit b0cbf622df werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -54,6 +54,6 @@ public class BlockIdWrapper8 implements BlockIdWrapper.IBlockIdWrapper {
@Override @Override
public Object getPose(boolean sneaking) { public Object getPose(boolean sneaking) {
return sneaking ? (byte) 2 : (byte) 0; return Byte.valueOf((byte)(sneaking ? 2 : 0));
} }
} }

Datei anzeigen

@ -132,8 +132,8 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
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) {
for(Field field : dataWatcherSerializer.getFields()) { for(Field field : dataWatcherRegistry.getFields()) {
if(type.isAssignableFrom(field.getType()) && type.equals(((ParameterizedType) field.getType().getGenericSuperclass()).getActualTypeArguments()[0])) { if(dataWatcherSerializer.isAssignableFrom(field.getType()) && type.equals(((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0])) {
try { try {
return dataWatcherObjectConstructor.invoke(index, field.get(null)); return dataWatcherObjectConstructor.invoke(index, field.get(null));
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -144,7 +144,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}.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) {
@ -168,7 +168,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
} }
private static final Class<?> enumItemSlot = Reflection.getClass("{nms}.EnumItemSlot"); private static final Class<?> enumItemSlot = Reflection.getClass("{nms}.EnumItemSlot");
private static final Reflection.FieldAccessor<?> equipmentSlot = Reflection.getField(REntity.equipmentPacket, enumItemSlot, 1); 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
public void setEquipmentPacketSlot(Object packet, String slot) { public void setEquipmentPacketSlot(Object packet, String slot) {

Datei anzeigen

@ -140,6 +140,8 @@ public class FightSystem extends JavaPlugin {
getLogger().log(Level.SEVERE, "Failed to replace commands", e); getLogger().log(Level.SEVERE, "Failed to replace commands", e);
} }
REntity.initWatchers();
if(Config.mode == ArenaMode.EVENT) { if(Config.mode == ArenaMode.EVENT) {
setPreSchemState(); setPreSchemState();
}else if(Config.mode == ArenaMode.CHECK){ }else if(Config.mode == ArenaMode.CHECK){

Datei anzeigen

@ -132,30 +132,27 @@ public class Fight {
private static final Class<?> playerInfoPacket = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo"); private static final Class<?> playerInfoPacket = Reflection.getClass("{nms}.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.PlayerInfoAction"); private static final Class<?> playerInfoActionClass = Reflection.getClass("{nms}.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}.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}.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}.IChatBaseComponent");
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, 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) {
ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoPacket(updateGamemode, playerInfoData(new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator))); ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator));
} }
public static Object playerInfoData(GameProfile profile, Object mode) { public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) {
return playerInfoDataConstructor.invoke(profile, 0, mode, null);
}
public static Object playerInfoPacket(Object action, Object info) {
Object packet = playerInfoConstructor.invoke(); Object packet = playerInfoConstructor.invoke();
playerInfoAction.set(packet, action); playerInfoAction.set(packet, action);
playerInfoData.set(packet, Collections.singletonList(info)); playerInfoData.set(packet, Collections.singletonList(playerInfoDataConstructor.invoke(packet, profile, 0, mode, null)));
return packet; return packet;
} }

Datei anzeigen

@ -47,7 +47,17 @@ public class REntity {
return entities.get(internalId); return entities.get(internalId);
} }
private static final Object entityStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(0, byte.class); private static Object entityStatusWatcher;
private static Object sneakingDataWatcher;
private static Object bowDrawnWatcher;
public static void initWatchers() {
// not during <clinit> to prevent cyclic class init.
entityStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(0, Byte.class);
sneakingDataWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 6 : 0, BlockIdWrapper.impl.getPose(true).getClass());
bowDrawnWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 7 : 6, Byte.class);
}
public static void tickFire() { public static void tickFire() {
entities.forEach((integer, entity) -> { entities.forEach((integer, entity) -> {
if(entity.fireTick > 0) { if(entity.fireTick > 0) {
@ -59,7 +69,6 @@ public class REntity {
}); });
} }
private static final Object sneakingDataWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 6 : 0, BlockIdWrapper.impl.getPose(true).getClass());
public static void playerJoins(Player player) { public static void playerJoins(Player player) {
for(REntity entity : entities.values()){ for(REntity entity : entities.values()){
if(entity.entityType == EntityType.PLAYER){ if(entity.entityType == EntityType.PLAYER){
@ -106,7 +115,6 @@ public class REntity {
private final int entityId; private final int entityId;
private final UUID uuid; private final UUID uuid;
private final EntityType entityType; private final EntityType entityType;
private final Object playerInfoData;
private final String name; private final String name;
private final Map<String, ItemStack> itemSlots = new HashMap<>(); private final Map<String, ItemStack> itemSlots = new HashMap<>();
@ -127,7 +135,6 @@ public class REntity {
SteamwarUser user = SteamwarUser.get(userId); SteamwarUser user = SteamwarUser.get(userId);
this.uuid = user.getUUID(); this.uuid = user.getUUID();
this.name = user.getUserName(); this.name = user.getUserName();
this.playerInfoData = Fight.playerInfoData(new GameProfile(uuid, name), Fight.creative);
entities.put(internalId, this); entities.put(internalId, this);
ProtocolAPI.broadcastPacket(getPlayerInfoPacket()); ProtocolAPI.broadcastPacket(getPlayerInfoPacket());
@ -140,7 +147,6 @@ public class REntity {
this.entityType = entityType; this.entityType = entityType;
this.entityId = entityCount--; this.entityId = entityCount--;
this.name = null; this.name = null;
this.playerInfoData = null;
this.uuid = new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L); this.uuid = new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L);
entities.put(internalId, this); entities.put(internalId, this);
@ -210,7 +216,6 @@ public class REntity {
ProtocolAPI.broadcastPacket(getDataWatcherPacket(entityStatusWatcher, (byte) 1)); ProtocolAPI.broadcastPacket(getDataWatcherPacket(entityStatusWatcher, (byte) 1));
} }
private static final Object bowDrawnWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 7 : 6, byte.class);
public void setBowDrawn(boolean drawn, boolean offHand) { public void setBowDrawn(boolean drawn, boolean offHand) {
if(Core.getVersion() > 8){ if(Core.getVersion() > 8){
ProtocolAPI.broadcastPacket(getDataWatcherPacket(bowDrawnWatcher, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0)))); ProtocolAPI.broadcastPacket(getDataWatcherPacket(bowDrawnWatcher, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))));
@ -238,7 +243,7 @@ public class REntity {
private static final Reflection.FieldAccessor<int[]> destroyEntities = Reflection.getField(destroyPacket, int[].class, 0); private static final Reflection.FieldAccessor<int[]> 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, playerInfoData)); ProtocolAPI.broadcastPacket(Fight.playerInfoPacket(Fight.removePlayer, new GameProfile(uuid, name), Fight.creative));
team.removeEntry(name); team.removeEntry(name);
} }
@ -303,8 +308,8 @@ public class REntity {
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);
private static final Class<?> craftItemStack = Reflection.getClass("{obc}.CraftItemStack"); private static final Class<?> craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack");
private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(craftItemStack, "asNMSCopy", itemStack, craftItemStack); 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){
Object packet = equipmentConstructor.invoke(); Object packet = equipmentConstructor.invoke();
equipmentEntity.set(0, entityId); equipmentEntity.set(0, entityId);
@ -314,7 +319,7 @@ public class REntity {
} }
private Object getPlayerInfoPacket(){ private Object getPlayerInfoPacket(){
return Fight.playerInfoPacket(Fight.addPlayer, playerInfoData); 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}.PacketPlayOutNamedEntitySpawn");

Datei anzeigen

@ -145,11 +145,11 @@ public class TechHider extends StateDependent {
private static final Reflection.FieldAccessor<?> multiBlockChangeChunk = Reflection.getField(multiBlockChangePacket, chunkCoordinateIntPair, 0); private static final Reflection.FieldAccessor<?> multiBlockChangeChunk = Reflection.getField(multiBlockChangePacket, chunkCoordinateIntPair, 0);
private static final Reflection.FieldAccessor<Integer> chunkCoordinateX = Reflection.getField(baseBlockPosition, int.class, 0); private static final Reflection.FieldAccessor<Integer> chunkCoordinateX = Reflection.getField(baseBlockPosition, int.class, 0);
private static final Reflection.FieldAccessor<Integer> chunkCoordinateZ = Reflection.getField(baseBlockPosition, int.class, 1); private static final Reflection.FieldAccessor<Integer> chunkCoordinateZ = Reflection.getField(baseBlockPosition, int.class, 1);
private static final Class<?> multiBlockChangeInfo = Reflection.getClass("{nms}.PacketPlayOutMultiBlockChange.MultiBlockChangeInfo"); private static final Class<?> multiBlockChangeInfo = Reflection.getClass("{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo");
private static final UnaryOperator<Object> multiBlockChangeInfoCloner = ProtocolAPI.shallowCloneGenerator(multiBlockChangeInfo); private static final UnaryOperator<Object> multiBlockChangeInfoCloner = ProtocolAPI.shallowCloneGenerator(multiBlockChangeInfo);
private static final BiFunction<Object, UnaryOperator<Object>, Object> multiBlockChangeInfoArrayCloner = ProtocolAPI.arrayCloneGenerator(multiBlockChangeInfo); private static final BiFunction<Object, UnaryOperator<Object>, Object> multiBlockChangeInfoArrayCloner = ProtocolAPI.arrayCloneGenerator(multiBlockChangeInfo);
private static final Reflection.FieldAccessor<?> multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, iBlockData, 0); private static final Reflection.FieldAccessor<?> multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, iBlockData, 0);
private static final Class<?> multiBlockChangeInfoArray = Reflection.getClass("[L{nms}.PacketPlayOutMultiBlockChange.MultiBlockChangeInfo;"); private static final Class<?> multiBlockChangeInfoArray = Reflection.getClass("[L{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;");
private static final Reflection.FieldAccessor<?> multiBlockChangeInfos = Reflection.getField(multiBlockChangePacket, multiBlockChangeInfoArray, 0); private static final Reflection.FieldAccessor<?> multiBlockChangeInfos = Reflection.getField(multiBlockChangePacket, multiBlockChangeInfoArray, 0);
private Object multiBlockChangeHider(Player p, Object packet) { private Object multiBlockChangeHider(Player p, Object packet) {
Object chunkCoords = multiBlockChangeChunk.get(packet); Object chunkCoords = multiBlockChangeChunk.get(packet);

Datei anzeigen

@ -4,7 +4,7 @@ authors:
- Yaruma3341 - Yaruma3341
- Lixfel - Lixfel
main: de.steamwar.fightsystem.FightSystem main: de.steamwar.fightsystem.FightSystem
depend: [SpigotCore, WorldEdit, ProtocolLib] depend: [SpigotCore, WorldEdit]
api-version: "1.13" api-version: "1.13"
commands: commands: