Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
735c2004f2
Commit
84f0ccee81
@ -27,7 +27,6 @@ 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 de.steamwar.fightsystem.utils.ProtocolWrapper;
|
import de.steamwar.fightsystem.utils.ProtocolWrapper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -150,7 +149,7 @@ public class Fight {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) {
|
public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) {
|
||||||
Object packet = ProtocolAPI.construct(playerInfoPacket);
|
Object packet = Reflection.newInstance(playerInfoPacket);
|
||||||
playerInfoAction.set(packet, action);
|
playerInfoAction.set(packet, action);
|
||||||
playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, profile, mode)));
|
playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, profile, mode)));
|
||||||
return packet;
|
return packet;
|
||||||
|
@ -177,7 +177,7 @@ public class REntity {
|
|||||||
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);
|
||||||
public void animation(byte animation) {
|
public void animation(byte animation) {
|
||||||
Object packet = ProtocolAPI.construct(animationPacket);
|
Object packet = Reflection.newInstance(animationPacket);
|
||||||
animationEntity.set(packet, entityId);
|
animationEntity.set(packet, entityId);
|
||||||
animationAnimation.set(packet, (int) animation);
|
animationAnimation.set(packet, (int) animation);
|
||||||
ProtocolAPI.broadcastPacket(packet);
|
ProtocolAPI.broadcastPacket(packet);
|
||||||
@ -189,7 +189,7 @@ public class REntity {
|
|||||||
private static final Reflection.FieldAccessor<Integer> velocityY = Reflection.getField(velocityPacket, int.class, 2);
|
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);
|
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) {
|
||||||
Object packet = ProtocolAPI.construct(velocityPacket);
|
Object packet = Reflection.newInstance(velocityPacket);
|
||||||
velocityEntity.set(packet, entityId);
|
velocityEntity.set(packet, entityId);
|
||||||
velocityX.set(packet, calcVelocity(dX));
|
velocityX.set(packet, calcVelocity(dX));
|
||||||
velocityY.set(packet, calcVelocity(dY));
|
velocityY.set(packet, calcVelocity(dY));
|
||||||
@ -201,7 +201,7 @@ public class REntity {
|
|||||||
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);
|
||||||
public void damage() {
|
public void damage() {
|
||||||
Object packet = ProtocolAPI.construct(statusPacket);
|
Object packet = Reflection.newInstance(statusPacket);
|
||||||
statusEntity.set(packet, entityId);
|
statusEntity.set(packet, entityId);
|
||||||
statusStatus.set(packet, (byte) 2);
|
statusStatus.set(packet, (byte) 2);
|
||||||
ProtocolAPI.broadcastPacket(packet);
|
ProtocolAPI.broadcastPacket(packet);
|
||||||
@ -259,7 +259,7 @@ public class REntity {
|
|||||||
team.removeEntry(name);
|
team.removeEntry(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object packet = ProtocolAPI.construct(destroyPacket);
|
Object packet = Reflection.newInstance(destroyPacket);
|
||||||
destroyEntities.set(packet, Core.getVersion() > 15 ? new IntArrayList(new int[]{entityId}) : new int[]{entityId});
|
destroyEntities.set(packet, Core.getVersion() > 15 ? new IntArrayList(new int[]{entityId}) : new int[]{entityId});
|
||||||
ProtocolAPI.broadcastPacket(packet);
|
ProtocolAPI.broadcastPacket(packet);
|
||||||
}
|
}
|
||||||
@ -272,7 +272,7 @@ public class REntity {
|
|||||||
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);
|
||||||
private Object getDataWatcherPacket(Object dataWatcherObject, Object value) {
|
private Object getDataWatcherPacket(Object dataWatcherObject, Object value) {
|
||||||
Object packet = ProtocolAPI.construct(metadataPacket);
|
Object packet = Reflection.newInstance(metadataPacket);
|
||||||
metadataEntity.set(packet, entityId);
|
metadataEntity.set(packet, entityId);
|
||||||
metadataMetadata.set(packet, Collections.singletonList(BountifulWrapper.impl.getDataWatcherItem(dataWatcherObject, value)));
|
metadataMetadata.set(packet, Collections.singletonList(BountifulWrapper.impl.getDataWatcherItem(dataWatcherObject, value)));
|
||||||
return packet;
|
return packet;
|
||||||
@ -283,7 +283,7 @@ public class REntity {
|
|||||||
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);
|
||||||
private static final Reflection.FieldAccessor<Byte> teleportPitch = Reflection.getField(teleportPacket, byte.class, 1);
|
private static final Reflection.FieldAccessor<Byte> teleportPitch = Reflection.getField(teleportPacket, byte.class, 1);
|
||||||
private Object getTeleportPacket(){
|
private Object getTeleportPacket(){
|
||||||
Object packet = ProtocolAPI.construct(teleportPacket);
|
Object packet = Reflection.newInstance(teleportPacket);
|
||||||
teleportEntity.set(packet, entityId);
|
teleportEntity.set(packet, entityId);
|
||||||
BountifulWrapper.impl.setTeleportPacketPosition(packet, locX, locY, locZ);
|
BountifulWrapper.impl.setTeleportPacketPosition(packet, locX, locY, locZ);
|
||||||
teleportYaw.set(packet, yaw);
|
teleportYaw.set(packet, yaw);
|
||||||
@ -295,7 +295,7 @@ public class REntity {
|
|||||||
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);
|
||||||
private Object getHeadRotationPacket(){
|
private Object getHeadRotationPacket(){
|
||||||
Object packet = ProtocolAPI.construct(headRotationPacket);
|
Object packet = Reflection.newInstance(headRotationPacket);
|
||||||
headRotationEntity.set(packet, entityId);
|
headRotationEntity.set(packet, entityId);
|
||||||
headRotationYaw.set(packet, headYaw);
|
headRotationYaw.set(packet, headYaw);
|
||||||
return packet;
|
return packet;
|
||||||
@ -304,7 +304,7 @@ public class REntity {
|
|||||||
public static final Class<?> spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity");
|
public static final Class<?> spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity");
|
||||||
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(){
|
||||||
Object packet = ProtocolAPI.construct(spawnPacket);
|
Object packet = Reflection.newInstance(spawnPacket);
|
||||||
spawnEntity.set(packet, entityId);
|
spawnEntity.set(packet, entityId);
|
||||||
BountifulWrapper.impl.setSpawnPacketUUID(packet, uuid);
|
BountifulWrapper.impl.setSpawnPacketUUID(packet, uuid);
|
||||||
ProtocolWrapper.impl.setSpawnPacketType(packet, entityType);
|
ProtocolWrapper.impl.setSpawnPacketType(packet, entityType);
|
||||||
@ -318,7 +318,7 @@ public class REntity {
|
|||||||
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(REntity.craftItemStack, "asNMSCopy", REntity.itemStack, ItemStack.class);
|
private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", REntity.itemStack, ItemStack.class);
|
||||||
private Object getEquipmentPacket(String slot, ItemStack stack){
|
private Object getEquipmentPacket(String slot, ItemStack stack){
|
||||||
Object packet = ProtocolAPI.construct(equipmentPacket);
|
Object packet = Reflection.newInstance(equipmentPacket);
|
||||||
equipmentEntity.set(packet, entityId);
|
equipmentEntity.set(packet, entityId);
|
||||||
ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, asNMSCopy.invoke(null, stack));
|
ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, asNMSCopy.invoke(null, stack));
|
||||||
return packet;
|
return packet;
|
||||||
@ -332,7 +332,7 @@ public class REntity {
|
|||||||
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);
|
||||||
private Object getNamedSpawnPacket(){
|
private Object getNamedSpawnPacket(){
|
||||||
Object packet = ProtocolAPI.construct(namedSpawnPacket);
|
Object packet = Reflection.newInstance(namedSpawnPacket);
|
||||||
namedSpawnEntity.set(packet, entityId);
|
namedSpawnEntity.set(packet, entityId);
|
||||||
namedSpawnUUID.set(packet, uuid);
|
namedSpawnUUID.set(packet, uuid);
|
||||||
FlatteningWrapper.impl.setNamedSpawnPacketDataWatcher(packet);
|
FlatteningWrapper.impl.setNamedSpawnPacketDataWatcher(packet);
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.utils;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import jdk.internal.misc.Unsafe;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -88,19 +88,11 @@ public class ProtocolAPI {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T construct(Class<T> clazz) {
|
|
||||||
try {
|
|
||||||
return (T) Unsafe.getUnsafe().allocateInstance(clazz);
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UnaryOperator<Object> shallowCloneGenerator(Class<?> clazz) {
|
public static UnaryOperator<Object> shallowCloneGenerator(Class<?> clazz) {
|
||||||
BiConsumer<Object, Object> filler = shallowFill(clazz);
|
BiConsumer<Object, Object> filler = shallowFill(clazz);
|
||||||
|
|
||||||
return source -> {
|
return source -> {
|
||||||
Object clone = construct(clazz);
|
Object clone = Reflection.newInstance(clazz);
|
||||||
filler.accept(source, clone);
|
filler.accept(source, clone);
|
||||||
return clone;
|
return clone;
|
||||||
};
|
};
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren