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
3 geänderte Dateien mit 169 neuen und 139 gelöschten Zeilen
Nur Änderungen aus Commit bc82b18fc6 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -19,26 +19,21 @@
package de.steamwar.fightsystem.fight;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.utils.ProtocolAPI;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
public class Fight {
private Fight(){}
@ -105,6 +100,7 @@ public class Fight {
return null;
}
@SuppressWarnings("deprecation")
public static void setPlayerGamemode(Player player, GameMode gameMode) {
player.setGameMode(gameMode);
@ -134,17 +130,33 @@ public class Fight {
}
}
private static final Class<?> playerInfoPacket = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo");
private static final Reflection.ConstructorInvoker playerInfoConstructor = Reflection.getConstructor(playerInfoPacket);
private static final Class<?> playerInfoActionClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo.PlayerInfoAction");
public static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0];
private static final Reflection.FieldAccessor<?> playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0);
private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1];
public static final Object removePlayer = playerInfoActionClass.getEnumConstants()[4];
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<?> enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms}.EnumGamemode" : "{nms}.WorldSettings.EnumGamemode");
public static final Object creative = enumGamemode.getEnumConstants()[2];
private static final Object spectator = enumGamemode.getEnumConstants()[4];
private static final Class<?> iChatBaseComponent = Reflection.getClass("{nms}.IChatBaseComponent");
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, GameProfile.class, int.class, enumGamemode, iChatBaseComponent);
public static void pseudoSpectator(Player player, boolean enable) {
PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
gm1packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE);
List<PlayerInfoData> playerInfoActions = new ArrayList<>();
playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, enable ? EnumWrappers.NativeGameMode.CREATIVE : EnumWrappers.NativeGameMode.SPECTATOR, WrappedChatComponent.fromText(player.getDisplayName())));
gm1packet.getPlayerInfoDataLists().write(0, playerInfoActions);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet);
} catch (InvocationTargetException e) {
Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e);
ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoPacket(updateGamemode, playerInfoData(new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator)));
}
public static Object playerInfoData(GameProfile profile, Object mode) {
return playerInfoDataConstructor.invoke(profile, 0, mode, null);
}
public static Object playerInfoPacket(Object action, Object info) {
Object packet = playerInfoConstructor.invoke();
playerInfoAction.set(packet, action);
playerInfoData.set(packet, Collections.singletonList(info));
return packet;
}
public static int getMaxRank(){

Datei anzeigen

@ -19,18 +19,15 @@
package de.steamwar.fightsystem.record;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.*;
import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.utils.BlockIdWrapper;
import de.steamwar.fightsystem.utils.ProtocolAPI;
import de.steamwar.sql.SteamwarUser;
import net.royawesome.jlibnoise.MathHelper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
@ -39,9 +36,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Team;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.logging.Level;
public class REntity {
@ -56,39 +51,35 @@ public class REntity {
if(entity.fireTick > 0) {
entity.fireTick--;
if(entity.fireTick == 0) {
ProtocolLibrary.getProtocolManager().broadcastServerPacket(entity.getDataWatcherPacket(0, (byte)0));
ProtocolAPI.broadcastPacket(entity.getDataWatcherPacket(0, (byte)0));
}
}
});
}
public static void playerJoins(Player player) {
try{
for(REntity entity : entities.values()){
if(entity.entityType == EntityType.PLAYER){
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getPlayerInfoPacket());
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getNamedSpawnPacket());
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getPlayerInfoPacket());
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getNamedSpawnPacket());
for (Map.Entry<String, ItemStack> entry : entity.itemSlots.entrySet()) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getEquipmentPacket(entry.getKey(), entry.getValue()));
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getEquipmentPacket(entry.getKey(), entry.getValue()));
}
}else{
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getSpawnEntityPacket());
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getSpawnEntityPacket());
}
//ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getTeleportPacket()); Sollte nicht nötig sein?
if(entity.fireTick != 0) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 1));
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getDataWatcherPacket(0, (byte) 1));
}
if(entity.sneaks) {
if(Core.getVersion() > 12){
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(6, BlockIdWrapper.impl.getPose(true)));
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getDataWatcherPacket(6, BlockIdWrapper.impl.getPose(true)));
}else{
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 2));
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getDataWatcherPacket(0, (byte) 2));
}
}
}
}catch(InvocationTargetException e){
Bukkit.getLogger().log(Level.SEVERE, "Could not sync player", e);
}
}
public static void dieAll(){
@ -114,7 +105,8 @@ public class REntity {
private final int entityId;
private final UUID uuid;
private final EntityType entityType;
private final PlayerInfoData playerInfoData;
private final Object playerInfoData;
private final String name;
private final Map<String, ItemStack> itemSlots = new HashMap<>();
private double locX;
@ -133,23 +125,25 @@ public class REntity {
SteamwarUser user = SteamwarUser.get(userId);
this.uuid = user.getUUID();
this.playerInfoData = new PlayerInfoData(WrappedGameProfile.fromHandle(new GameProfile(uuid, user.getUserName())), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(user.getUserName()));
this.name = user.getUserName();
this.playerInfoData = Fight.playerInfoData(new GameProfile(uuid, name), Fight.creative);
entities.put(internalId, this);
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getPlayerInfoPacket());
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getNamedSpawnPacket());
team.addEntry(user.getUserName());
ProtocolAPI.broadcastPacket(getPlayerInfoPacket());
ProtocolAPI.broadcastPacket(getNamedSpawnPacket());
team.addEntry(name);
}
public REntity(int internalId, EntityType entityType){
this.internalId = internalId;
this.entityType = entityType;
this.entityId = entityCount--;
this.name = null;
this.playerInfoData = null;
this.uuid = new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L);
entities.put(internalId, this);
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getSpawnEntityPacket());
ProtocolAPI.broadcastPacket(getSpawnEntityPacket());
}
public void move(double locX, double locY, double locZ, float pitch, float yaw, byte headYaw){
@ -159,42 +153,54 @@ public class REntity {
this.yaw = (byte)((int)(yaw * 256.0F / 360.0F));
this.pitch = (byte)((int)(pitch * 256.0F / 360.0F));
this.headYaw = headYaw;
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getTeleportPacket());
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHeadRotationPacket());
ProtocolAPI.broadcastPacket(getTeleportPacket());
ProtocolAPI.broadcastPacket(getHeadRotationPacket());
}
private static final Class<?> animationPacket = Reflection.getClass("{nms}.PacketPlayOutAnimation");
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> animationAnimation = Reflection.getField(animationPacket, int.class, 1);
public void animation(byte animation) {
PacketContainer animationPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ANIMATION);
StructureModifier<Integer> ints = animationPacket.getIntegers();
ints.write(0, entityId);
ints.write(1, (int) animation);
ProtocolLibrary.getProtocolManager().broadcastServerPacket(animationPacket);
Object packet = animationConstructor.invoke();
animationEntity.set(packet, entityId);
animationAnimation.set(packet, (int) animation);
ProtocolAPI.broadcastPacket(packet);
}
private static final Class<?> velocityPacket = Reflection.getClass("{nms}.PacketPlayOutEntityVelocity");
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> velocityX = Reflection.getField(velocityPacket, int.class, 1);
private static final Reflection.FieldAccessor<Integer> velocityY = Reflection.getField(velocityPacket, int.class, 2);
private static final Reflection.FieldAccessor<Integer> velocityZ = Reflection.getField(velocityPacket, int.class, 3);
public void setVelocity(double dX, double dY, double dZ) {
PacketContainer velocityPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_VELOCITY);
StructureModifier<Integer> ints = velocityPacket.getIntegers();
ints.write(0, entityId);
ints.write(1, calcVelocity(dX));
ints.write(2, calcVelocity(dY));
ints.write(3, calcVelocity(dZ));
ProtocolLibrary.getProtocolManager().broadcastServerPacket(velocityPacket);
Object packet = velocityConstructor.invoke();
velocityEntity.set(packet, entityId);
velocityX.set(packet, calcVelocity(dX));
velocityY.set(packet, calcVelocity(dY));
velocityZ.set(packet, calcVelocity(dZ));
ProtocolAPI.broadcastPacket(packet);
}
private static final Class<?> statusPacket = Reflection.getClass("{nms}.PacketPlayOutEntityStatus");
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<Byte> statusStatus = Reflection.getField(statusPacket, byte.class, 0);
public void damage() {
PacketContainer statusPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_STATUS);
statusPacket.getIntegers().write(0, entityId);
statusPacket.getBytes().write(0, (byte) 2);
ProtocolLibrary.getProtocolManager().broadcastServerPacket(statusPacket);
Object packet = statusConstructor.invoke();
statusEntity.set(packet, entityId);
statusStatus.set(packet, (byte) 2);
ProtocolAPI.broadcastPacket(packet);
}
public void sneak(boolean sneaking) {
sneaks = sneaking;
if(Core.getVersion() > 12){
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(6, BlockIdWrapper.impl.getPose(sneaking)));
ProtocolAPI.broadcastPacket(getDataWatcherPacket(6, BlockIdWrapper.impl.getPose(sneaking)));
}else{
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, sneaking ? (byte) 2 : (byte) 0));
ProtocolAPI.broadcastPacket(getDataWatcherPacket(0, sneaking ? (byte) 2 : (byte) 0));
}
}
@ -205,14 +211,14 @@ public class REntity {
fireTick = -1;
}
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, (byte) 1));
ProtocolAPI.broadcastPacket(getDataWatcherPacket(0, (byte) 1));
}
public void setBowDrawn(boolean drawn, boolean offHand) {
if(Core.getVersion() > 8){
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(Core.getVersion() > 12 ? 7 : 6, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))));
ProtocolAPI.broadcastPacket(getDataWatcherPacket(Core.getVersion() > 12 ? 7 : 6, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))));
}else{
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, (byte)0x10));
ProtocolAPI.broadcastPacket(getDataWatcherPacket(0, (byte)0x10));
}
}
@ -222,7 +228,7 @@ public class REntity {
stack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
itemSlots.put(slot, stack);
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getEquipmentPacket(slot, stack));
ProtocolAPI.broadcastPacket(getEquipmentPacket(slot, stack));
}
public void die(){
@ -230,25 +236,47 @@ public class REntity {
entities.remove(internalId);
}
private static final Class<?> destroyPacket = Reflection.getClass("{nms}.PacketPlayOutEntityDestroy");
private static final Reflection.ConstructorInvoker destroyConstructor = Reflection.getConstructor(destroyPacket);
private static final Reflection.FieldAccessor<int[]> destroyEntities = Reflection.getField(destroyPacket, int[].class, 0);
private void broadcastDeath(){
if(entityType == EntityType.PLAYER){
PacketContainer infoPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
infoPacket.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
infoPacket.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData));
ProtocolLibrary.getProtocolManager().broadcastServerPacket(infoPacket);
team.removeEntry(playerInfoData.getProfile().getName());
ProtocolAPI.broadcastPacket(Fight.playerInfoPacket(Fight.removePlayer, playerInfoData));
team.removeEntry(name);
}
PacketContainer destroyPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_DESTROY);
destroyPacket.getIntegerArrays().write(0, new int[]{entityId});
ProtocolLibrary.getProtocolManager().broadcastServerPacket(destroyPacket);
Object packet = destroyConstructor.invoke();
destroyEntities.set(packet, new int[]{entityId});
ProtocolAPI.broadcastPacket(packet);
}
private int calcVelocity(double value) {
return (int)(Math.max(-3.9, Math.min(value, 3.9)) * 8000);
}
private void fillPositioningPacket(PacketContainer packet, StructureModifier<Integer> ints){
private static final Class<?> metadataPacket = Reflection.getClass("{nms}.PacketPlayOutEntityMetadata");
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<List> metadataMetadata = Reflection.getField(metadataPacket, List.class, 0);
private Object getDataWatcherPacket(int index, Object value) {
Object packet = metadataConstructor.invoke();
metadataEntity.set(packet, entityId);
//TODO 1.9 change
WrappedWatchableObject watchable = new WrappedWatchableObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, WrappedDataWatcher.Registry.get(value.getClass())), value);
watchable.setDirtyState(true);
metadataMetadata.set(packet, Collections.singletonList(watchable));
return packet;
}
private Object getTeleportPacket(){
Object packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_TELEPORT);
fillPositioningPacket(packet, packet.getIntegers());
fillByteRotation(packet);
return packet;
}
private void fillPositioningPacket(Object packet, StructureModifier<Integer> ints){
ints.write(0, entityId);
if(Core.getVersion() > 8){
StructureModifier<Double> doubles = packet.getDoubles();
@ -262,42 +290,30 @@ public class REntity {
}
}
private void fillByteRotation(PacketContainer packet){
private void fillByteRotation(Object packet){
StructureModifier<Byte> bytes = packet.getBytes();
bytes.write(0, yaw);
bytes.write(1, pitch);
}
private PacketContainer getDataWatcherPacket(int index, Object value) {
PacketContainer metadataPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
metadataPacket.getIntegers().write(0, entityId);
WrappedWatchableObject watchable = new WrappedWatchableObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, WrappedDataWatcher.Registry.get(value.getClass())), value);
watchable.setDirtyState(true);
metadataPacket.getWatchableCollectionModifier().write(0, Collections.singletonList(watchable));
return metadataPacket;
private static final Class<?> headRotationPacket = Reflection.getClass("{nms}.PacketPlayOutEntityHeadRotation");
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<Byte> headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0);
private Object getHeadRotationPacket(){
Object packet = headRotationConstructor.invoke();
headRotationEntity.set(packet, entityId);
headRotationYaw.set(packet, headYaw);
return packet;
}
private PacketContainer getTeleportPacket(){
PacketContainer teleportPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_TELEPORT);
fillPositioningPacket(teleportPacket, teleportPacket.getIntegers());
fillByteRotation(teleportPacket);
return teleportPacket;
}
private PacketContainer getHeadRotationPacket(){
PacketContainer headRotation = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
headRotation.getIntegers().write(0, entityId);
headRotation.getBytes().write(0, headYaw);
return headRotation;
}
private PacketContainer getSpawnEntityPacket(){
PacketContainer spawnPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY);
StructureModifier<Integer> ints = spawnPacket.getIntegers();
fillPositioningPacket(spawnPacket, ints);
spawnPacket.getUUIDs().write(0, uuid);
private Object getSpawnEntityPacket(){
Object packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY);
StructureModifier<Integer> ints = packet.getIntegers();
fillPositioningPacket(packet, ints);
packet.getUUIDs().write(0, uuid);
if(Core.getVersion() > 8){
spawnPacket.getUUIDs().write(0, uuid);
packet.getUUIDs().write(0, uuid);
ints.write(1, 0); // dX
ints.write(2, 0); // dY
ints.write(3, 0); // dZ
@ -305,7 +321,7 @@ public class REntity {
ints.write(4, (int)pitch);
ints.write(5, (int)yaw);
if(Core.getVersion() > 12){
spawnPacket.getEntityTypeModifier().write(0, entityType);
packet.getEntityTypeModifier().write(0, entityType);
}else{
switch(entityType){
case PRIMED_TNT:
@ -319,12 +335,13 @@ public class REntity {
break;
}
}
return spawnPacket;
return packet;
}
private PacketContainer getEquipmentPacket(String slot, ItemStack stack){
PacketContainer equipmentPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT);
StructureModifier<Integer> ints = equipmentPacket.getIntegers();
private Object getEquipmentPacket(String slot, ItemStack stack){
Object packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT);
StructureModifier<Integer> ints = packet.getIntegers();
ints.write(0, entityId);
if(Core.getVersion() == 8){
switch(slot){
@ -346,28 +363,25 @@ public class REntity {
ints.write(1, 1);
}
}else{
equipmentPacket.getItemSlots().write(0, EnumWrappers.ItemSlot.valueOf(slot));
packet.getItemSlots().write(0, EnumWrappers.ItemSlot.valueOf(slot));
}
equipmentPacket.getItemModifier().write(0, stack);
return equipmentPacket;
packet.getItemModifier().write(0, stack);
return packet;
}
private PacketContainer getPlayerInfoPacket(){
PacketContainer infoPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
infoPacket.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);
infoPacket.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData));
return infoPacket;
private Object getPlayerInfoPacket(){
return Fight.playerInfoPacket(Fight.addPlayer, playerInfoData);
}
private PacketContainer getNamedSpawnPacket(){
PacketContainer namedSpawnPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
StructureModifier<Integer> ints = namedSpawnPacket.getIntegers();
fillPositioningPacket(namedSpawnPacket, ints);
namedSpawnPacket.getUUIDs().write(0, uuid);
fillByteRotation(namedSpawnPacket);
private Object getNamedSpawnPacket(){
Object packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
StructureModifier<Integer> ints = packet.getIntegers();
fillPositioningPacket(packet, ints);
packet.getUUIDs().write(0, uuid);
fillByteRotation(packet);
if(Core.getVersion() < 13){
namedSpawnPacket.getDataWatcherModifier().write(0, new WrappedDataWatcher());
packet.getDataWatcherModifier().write(0, new WrappedDataWatcher());
}
return namedSpawnPacket;
return packet;
}
}

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.fightsystem.FightSystem;
import io.netty.channel.Channel;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.lang.reflect.Array;
@ -75,6 +76,9 @@ public class ProtocolAPI {
incomingHandler.remove(packetClass);
}
public static void broadcastPacket(Object packet) {
Bukkit.getOnlinePlayers().stream().map(tinyProtocol::getChannel).filter(tinyProtocol::hasInjected).forEach(channel -> tinyProtocol.sendPacket(channel, packet));
}
public static BiFunction<Object, UnaryOperator<Object>, Object> arrayCloneGenerator(Class<?> elementClass) {
return (array, worker) -> {