Fight + partial REntity -> TinyProtocol
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
8ce5e7f7f8
Commit
bc82b18fc6
@ -19,26 +19,21 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.fight;
|
package de.steamwar.fightsystem.fight;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import de.steamwar.core.Core;
|
||||||
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 de.steamwar.fightsystem.ArenaMode;
|
import de.steamwar.fightsystem.ArenaMode;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.record.GlobalRecorder;
|
import de.steamwar.fightsystem.record.GlobalRecorder;
|
||||||
|
import de.steamwar.fightsystem.utils.ProtocolAPI;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.util.Collections;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class Fight {
|
public class Fight {
|
||||||
private Fight(){}
|
private Fight(){}
|
||||||
@ -105,6 +100,7 @@ public class Fight {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public static void setPlayerGamemode(Player player, GameMode gameMode) {
|
public static void setPlayerGamemode(Player player, GameMode gameMode) {
|
||||||
player.setGameMode(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) {
|
public static void pseudoSpectator(Player player, boolean enable) {
|
||||||
PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
|
ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoPacket(updateGamemode, playerInfoData(new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator)));
|
||||||
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())));
|
public static Object playerInfoData(GameProfile profile, Object mode) {
|
||||||
gm1packet.getPlayerInfoDataLists().write(0, playerInfoActions);
|
return playerInfoDataConstructor.invoke(profile, 0, mode, null);
|
||||||
try {
|
}
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet);
|
|
||||||
} catch (InvocationTargetException e) {
|
public static Object playerInfoPacket(Object action, Object info) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e);
|
Object packet = playerInfoConstructor.invoke();
|
||||||
}
|
playerInfoAction.set(packet, action);
|
||||||
|
playerInfoData.set(packet, Collections.singletonList(info));
|
||||||
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxRank(){
|
public static int getMaxRank(){
|
||||||
|
@ -19,18 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.record;
|
package de.steamwar.fightsystem.record;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
|
||||||
import com.comphenix.protocol.wrappers.*;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.listener.FightScoreboard;
|
import de.steamwar.fightsystem.listener.FightScoreboard;
|
||||||
import de.steamwar.fightsystem.utils.BlockIdWrapper;
|
import de.steamwar.fightsystem.utils.BlockIdWrapper;
|
||||||
|
import de.steamwar.fightsystem.utils.ProtocolAPI;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import net.royawesome.jlibnoise.MathHelper;
|
import net.royawesome.jlibnoise.MathHelper;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
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;
|
||||||
@ -39,9 +36,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.scoreboard.NameTagVisibility;
|
import org.bukkit.scoreboard.NameTagVisibility;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class REntity {
|
public class REntity {
|
||||||
|
|
||||||
@ -56,38 +51,34 @@ public class REntity {
|
|||||||
if(entity.fireTick > 0) {
|
if(entity.fireTick > 0) {
|
||||||
entity.fireTick--;
|
entity.fireTick--;
|
||||||
if(entity.fireTick == 0) {
|
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) {
|
public static void playerJoins(Player player) {
|
||||||
try{
|
for(REntity entity : entities.values()){
|
||||||
for(REntity entity : entities.values()){
|
if(entity.entityType == EntityType.PLAYER){
|
||||||
if(entity.entityType == EntityType.PLAYER){
|
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getPlayerInfoPacket());
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getPlayerInfoPacket());
|
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getNamedSpawnPacket());
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getNamedSpawnPacket());
|
for (Map.Entry<String, ItemStack> entry : entity.itemSlots.entrySet()) {
|
||||||
for (Map.Entry<String, ItemStack> entry : entity.itemSlots.entrySet()) {
|
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getEquipmentPacket(entry.getKey(), entry.getValue()));
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getEquipmentPacket(entry.getKey(), entry.getValue()));
|
}
|
||||||
}
|
}else{
|
||||||
|
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getSpawnEntityPacket());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entity.fireTick != 0) {
|
||||||
|
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getDataWatcherPacket(0, (byte) 1));
|
||||||
|
}
|
||||||
|
if(entity.sneaks) {
|
||||||
|
if(Core.getVersion() > 12){
|
||||||
|
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getDataWatcherPacket(6, BlockIdWrapper.impl.getPose(true)));
|
||||||
}else{
|
}else{
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getSpawnEntityPacket());
|
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getDataWatcherPacket(0, (byte) 2));
|
||||||
}
|
|
||||||
//ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getTeleportPacket()); Sollte nicht nötig sein?
|
|
||||||
if(entity.fireTick != 0) {
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 1));
|
|
||||||
}
|
|
||||||
if(entity.sneaks) {
|
|
||||||
if(Core.getVersion() > 12){
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(6, BlockIdWrapper.impl.getPose(true)));
|
|
||||||
}else{
|
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, entity.getDataWatcherPacket(0, (byte) 2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(InvocationTargetException e){
|
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not sync player", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +105,8 @@ 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 PlayerInfoData playerInfoData;
|
private final Object playerInfoData;
|
||||||
|
private final String name;
|
||||||
private final Map<String, ItemStack> itemSlots = new HashMap<>();
|
private final Map<String, ItemStack> itemSlots = new HashMap<>();
|
||||||
|
|
||||||
private double locX;
|
private double locX;
|
||||||
@ -133,23 +125,25 @@ public class REntity {
|
|||||||
|
|
||||||
SteamwarUser user = SteamwarUser.get(userId);
|
SteamwarUser user = SteamwarUser.get(userId);
|
||||||
this.uuid = user.getUUID();
|
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);
|
entities.put(internalId, this);
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getPlayerInfoPacket());
|
ProtocolAPI.broadcastPacket(getPlayerInfoPacket());
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getNamedSpawnPacket());
|
ProtocolAPI.broadcastPacket(getNamedSpawnPacket());
|
||||||
team.addEntry(user.getUserName());
|
team.addEntry(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public REntity(int internalId, EntityType entityType){
|
public REntity(int internalId, EntityType entityType){
|
||||||
this.internalId = internalId;
|
this.internalId = internalId;
|
||||||
this.entityType = entityType;
|
this.entityType = entityType;
|
||||||
this.entityId = entityCount--;
|
this.entityId = entityCount--;
|
||||||
|
this.name = null;
|
||||||
this.playerInfoData = 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);
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getSpawnEntityPacket());
|
ProtocolAPI.broadcastPacket(getSpawnEntityPacket());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void move(double locX, double locY, double locZ, float pitch, float yaw, byte headYaw){
|
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.yaw = (byte)((int)(yaw * 256.0F / 360.0F));
|
||||||
this.pitch = (byte)((int)(pitch * 256.0F / 360.0F));
|
this.pitch = (byte)((int)(pitch * 256.0F / 360.0F));
|
||||||
this.headYaw = headYaw;
|
this.headYaw = headYaw;
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getTeleportPacket());
|
ProtocolAPI.broadcastPacket(getTeleportPacket());
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHeadRotationPacket());
|
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) {
|
public void animation(byte animation) {
|
||||||
PacketContainer animationPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ANIMATION);
|
Object packet = animationConstructor.invoke();
|
||||||
StructureModifier<Integer> ints = animationPacket.getIntegers();
|
animationEntity.set(packet, entityId);
|
||||||
ints.write(0, entityId);
|
animationAnimation.set(packet, (int) animation);
|
||||||
ints.write(1, (int) animation);
|
ProtocolAPI.broadcastPacket(packet);
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(animationPacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
public void setVelocity(double dX, double dY, double dZ) {
|
||||||
PacketContainer velocityPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_VELOCITY);
|
Object packet = velocityConstructor.invoke();
|
||||||
StructureModifier<Integer> ints = velocityPacket.getIntegers();
|
velocityEntity.set(packet, entityId);
|
||||||
ints.write(0, entityId);
|
velocityX.set(packet, calcVelocity(dX));
|
||||||
ints.write(1, calcVelocity(dX));
|
velocityY.set(packet, calcVelocity(dY));
|
||||||
ints.write(2, calcVelocity(dY));
|
velocityZ.set(packet, calcVelocity(dZ));
|
||||||
ints.write(3, calcVelocity(dZ));
|
ProtocolAPI.broadcastPacket(packet);
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(velocityPacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
public void damage() {
|
||||||
PacketContainer statusPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_STATUS);
|
Object packet = statusConstructor.invoke();
|
||||||
statusPacket.getIntegers().write(0, entityId);
|
statusEntity.set(packet, entityId);
|
||||||
statusPacket.getBytes().write(0, (byte) 2);
|
statusStatus.set(packet, (byte) 2);
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(statusPacket);
|
ProtocolAPI.broadcastPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sneak(boolean sneaking) {
|
public void sneak(boolean sneaking) {
|
||||||
sneaks = sneaking;
|
sneaks = sneaking;
|
||||||
|
|
||||||
if(Core.getVersion() > 12){
|
if(Core.getVersion() > 12){
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(6, BlockIdWrapper.impl.getPose(sneaking)));
|
ProtocolAPI.broadcastPacket(getDataWatcherPacket(6, BlockIdWrapper.impl.getPose(sneaking)));
|
||||||
}else{
|
}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;
|
fireTick = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getDataWatcherPacket(0, (byte) 1));
|
ProtocolAPI.broadcastPacket(getDataWatcherPacket(0, (byte) 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBowDrawn(boolean drawn, boolean offHand) {
|
public void setBowDrawn(boolean drawn, boolean offHand) {
|
||||||
if(Core.getVersion() > 8){
|
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{
|
}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);
|
stack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
|
||||||
itemSlots.put(slot, stack);
|
itemSlots.put(slot, stack);
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getEquipmentPacket(slot, stack));
|
ProtocolAPI.broadcastPacket(getEquipmentPacket(slot, stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void die(){
|
public void die(){
|
||||||
@ -230,25 +236,47 @@ public class REntity {
|
|||||||
entities.remove(internalId);
|
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(){
|
private void broadcastDeath(){
|
||||||
if(entityType == EntityType.PLAYER){
|
if(entityType == EntityType.PLAYER){
|
||||||
PacketContainer infoPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
|
ProtocolAPI.broadcastPacket(Fight.playerInfoPacket(Fight.removePlayer, playerInfoData));
|
||||||
infoPacket.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
|
team.removeEntry(name);
|
||||||
infoPacket.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData));
|
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(infoPacket);
|
|
||||||
team.removeEntry(playerInfoData.getProfile().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketContainer destroyPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_DESTROY);
|
Object packet = destroyConstructor.invoke();
|
||||||
destroyPacket.getIntegerArrays().write(0, new int[]{entityId});
|
destroyEntities.set(packet, new int[]{entityId});
|
||||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(destroyPacket);
|
ProtocolAPI.broadcastPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calcVelocity(double value) {
|
private int calcVelocity(double value) {
|
||||||
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 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);
|
ints.write(0, entityId);
|
||||||
if(Core.getVersion() > 8){
|
if(Core.getVersion() > 8){
|
||||||
StructureModifier<Double> doubles = packet.getDoubles();
|
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();
|
StructureModifier<Byte> bytes = packet.getBytes();
|
||||||
bytes.write(0, yaw);
|
bytes.write(0, yaw);
|
||||||
bytes.write(1, pitch);
|
bytes.write(1, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketContainer getDataWatcherPacket(int index, Object value) {
|
private static final Class<?> headRotationPacket = Reflection.getClass("{nms}.PacketPlayOutEntityHeadRotation");
|
||||||
PacketContainer metadataPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
|
private static final Reflection.ConstructorInvoker headRotationConstructor = Reflection.getConstructor(headRotationPacket);
|
||||||
metadataPacket.getIntegers().write(0, entityId);
|
private static final Reflection.FieldAccessor<Integer> headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0);
|
||||||
WrappedWatchableObject watchable = new WrappedWatchableObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, WrappedDataWatcher.Registry.get(value.getClass())), value);
|
private static final Reflection.FieldAccessor<Byte> headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0);
|
||||||
watchable.setDirtyState(true);
|
private Object getHeadRotationPacket(){
|
||||||
metadataPacket.getWatchableCollectionModifier().write(0, Collections.singletonList(watchable));
|
Object packet = headRotationConstructor.invoke();
|
||||||
return metadataPacket;
|
headRotationEntity.set(packet, entityId);
|
||||||
|
headRotationYaw.set(packet, headYaw);
|
||||||
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketContainer getTeleportPacket(){
|
private Object getSpawnEntityPacket(){
|
||||||
PacketContainer teleportPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_TELEPORT);
|
Object packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY);
|
||||||
fillPositioningPacket(teleportPacket, teleportPacket.getIntegers());
|
StructureModifier<Integer> ints = packet.getIntegers();
|
||||||
fillByteRotation(teleportPacket);
|
fillPositioningPacket(packet, ints);
|
||||||
return teleportPacket;
|
packet.getUUIDs().write(0, uuid);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
if(Core.getVersion() > 8){
|
if(Core.getVersion() > 8){
|
||||||
spawnPacket.getUUIDs().write(0, uuid);
|
packet.getUUIDs().write(0, uuid);
|
||||||
ints.write(1, 0); // dX
|
ints.write(1, 0); // dX
|
||||||
ints.write(2, 0); // dY
|
ints.write(2, 0); // dY
|
||||||
ints.write(3, 0); // dZ
|
ints.write(3, 0); // dZ
|
||||||
@ -305,7 +321,7 @@ public class REntity {
|
|||||||
ints.write(4, (int)pitch);
|
ints.write(4, (int)pitch);
|
||||||
ints.write(5, (int)yaw);
|
ints.write(5, (int)yaw);
|
||||||
if(Core.getVersion() > 12){
|
if(Core.getVersion() > 12){
|
||||||
spawnPacket.getEntityTypeModifier().write(0, entityType);
|
packet.getEntityTypeModifier().write(0, entityType);
|
||||||
}else{
|
}else{
|
||||||
switch(entityType){
|
switch(entityType){
|
||||||
case PRIMED_TNT:
|
case PRIMED_TNT:
|
||||||
@ -319,12 +335,13 @@ public class REntity {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return spawnPacket;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketContainer getEquipmentPacket(String slot, ItemStack stack){
|
|
||||||
PacketContainer equipmentPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT);
|
private Object getEquipmentPacket(String slot, ItemStack stack){
|
||||||
StructureModifier<Integer> ints = equipmentPacket.getIntegers();
|
Object packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT);
|
||||||
|
StructureModifier<Integer> ints = packet.getIntegers();
|
||||||
ints.write(0, entityId);
|
ints.write(0, entityId);
|
||||||
if(Core.getVersion() == 8){
|
if(Core.getVersion() == 8){
|
||||||
switch(slot){
|
switch(slot){
|
||||||
@ -346,28 +363,25 @@ public class REntity {
|
|||||||
ints.write(1, 1);
|
ints.write(1, 1);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
equipmentPacket.getItemSlots().write(0, EnumWrappers.ItemSlot.valueOf(slot));
|
packet.getItemSlots().write(0, EnumWrappers.ItemSlot.valueOf(slot));
|
||||||
}
|
}
|
||||||
equipmentPacket.getItemModifier().write(0, stack);
|
packet.getItemModifier().write(0, stack);
|
||||||
return equipmentPacket;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketContainer getPlayerInfoPacket(){
|
private Object getPlayerInfoPacket(){
|
||||||
PacketContainer infoPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
|
return Fight.playerInfoPacket(Fight.addPlayer, playerInfoData);
|
||||||
infoPacket.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);
|
|
||||||
infoPacket.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData));
|
|
||||||
return infoPacket;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketContainer getNamedSpawnPacket(){
|
private Object getNamedSpawnPacket(){
|
||||||
PacketContainer namedSpawnPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
Object packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
||||||
StructureModifier<Integer> ints = namedSpawnPacket.getIntegers();
|
StructureModifier<Integer> ints = packet.getIntegers();
|
||||||
fillPositioningPacket(namedSpawnPacket, ints);
|
fillPositioningPacket(packet, ints);
|
||||||
namedSpawnPacket.getUUIDs().write(0, uuid);
|
packet.getUUIDs().write(0, uuid);
|
||||||
fillByteRotation(namedSpawnPacket);
|
fillByteRotation(packet);
|
||||||
if(Core.getVersion() < 13){
|
if(Core.getVersion() < 13){
|
||||||
namedSpawnPacket.getDataWatcherModifier().write(0, new WrappedDataWatcher());
|
packet.getDataWatcherModifier().write(0, new WrappedDataWatcher());
|
||||||
}
|
}
|
||||||
return namedSpawnPacket;
|
return packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ package de.steamwar.fightsystem.utils;
|
|||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
@ -75,6 +76,9 @@ public class ProtocolAPI {
|
|||||||
incomingHandler.remove(packetClass);
|
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) {
|
public static BiFunction<Object, UnaryOperator<Object>, Object> arrayCloneGenerator(Class<?> elementClass) {
|
||||||
return (array, worker) -> {
|
return (array, worker) -> {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren