mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-27 13:15:52 +01:00
parent
aebefded86
commit
df3b68df4c
@ -41,19 +41,19 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Handshake {
|
||||
private static final Protocol PROTOCOL = Protocol.HANDSHAKING;
|
||||
static final Protocol PROTOCOL = Protocol.HANDSHAKING;
|
||||
|
||||
/**
|
||||
* Incoming packets.
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Client extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.CLIENT;
|
||||
private static final Sender SENDER = Sender.CLIENT;
|
||||
|
||||
@ForceAsync
|
||||
public static final PacketType SET_PROTOCOL = new PacketType(PROTOCOL, SENDER, 0x00, "SetProtocol", "C00Handshake");
|
||||
|
||||
private final static Client INSTANCE = new Client();
|
||||
private static final Client INSTANCE = new Client();
|
||||
|
||||
// Prevent accidental construction
|
||||
private Client() { super(); }
|
||||
@ -71,8 +71,8 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Server extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.CLIENT;
|
||||
private final static Server INSTANCE = new Server();
|
||||
private static final Sender SENDER = Sender.CLIENT;
|
||||
private static final Server INSTANCE = new Server();
|
||||
private Server() { super(); }
|
||||
|
||||
public static Server getInstance() {
|
||||
@ -93,16 +93,16 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Play {
|
||||
private static final Protocol PROTOCOL = Protocol.PLAY;
|
||||
static final Protocol PROTOCOL = Protocol.PLAY;
|
||||
|
||||
/**
|
||||
* Outgoing packets.
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Server extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.SERVER;
|
||||
private static final Sender SENDER = Sender.SERVER;
|
||||
|
||||
public static final PacketType DELIMITER = new PacketType(PROTOCOL, SENDER, 0x00, "Delimiter", "BundleDelimiterPacket");
|
||||
public static final PacketType BUNDLE = new PacketType(PROTOCOL, SENDER, 0x00, "Delimiter", "BundleDelimiterPacket");
|
||||
public static final PacketType SPAWN_ENTITY = new PacketType(PROTOCOL, SENDER, 0x01, "SpawnEntity", "SPacketSpawnObject");
|
||||
public static final PacketType SPAWN_ENTITY_EXPERIENCE_ORB = new PacketType(PROTOCOL, SENDER, 0x02, "SpawnEntityExperienceOrb", "SPacketSpawnExperienceOrb");
|
||||
public static final PacketType NAMED_ENTITY_SPAWN = new PacketType(PROTOCOL, SENDER, 0x03, "NamedEntitySpawn", "SPacketSpawnPlayer");
|
||||
@ -367,7 +367,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
@Deprecated
|
||||
public static final PacketType CUSTOM_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x16, "CustomSoundEffect", "SPacketCustomSound");
|
||||
|
||||
private final static Server INSTANCE = new Server();
|
||||
private static final Server INSTANCE = new Server();
|
||||
|
||||
// Prevent accidental construction
|
||||
private Server() { super(); }
|
||||
@ -385,7 +385,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Client extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.CLIENT;
|
||||
private static final Sender SENDER = Sender.CLIENT;
|
||||
|
||||
public static final PacketType TELEPORT_ACCEPT = new PacketType(PROTOCOL, SENDER, 0x00, "TeleportAccept", "CPacketConfirmTeleport");
|
||||
public static final PacketType TILE_NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x01, "TileNBTQuery");
|
||||
@ -410,7 +410,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x14, "Flying$Position", "Flying$PacketPlayInPosition", "CPacketPlayer$Position");
|
||||
public static final PacketType POSITION_LOOK = new PacketType(PROTOCOL, SENDER, 0x15, "Flying$PositionLook", "Flying$PacketPlayInPositionLook", "CPacketPlayer$PositionRotation");
|
||||
public static final PacketType LOOK = new PacketType(PROTOCOL, SENDER, 0x16, "Flying$Look", "Flying$PacketPlayInLook", "CPacketPlayer$Rotation");
|
||||
public static final PacketType GROUND = new PacketType(PROTOCOL, SENDER, 0x17, "Flying$", "Flying$d");
|
||||
public static final PacketType GROUND = new PacketType(PROTOCOL, SENDER, 0x17, "Flying$d");
|
||||
public static final PacketType VEHICLE_MOVE = new PacketType(PROTOCOL, SENDER, 0x18, "VehicleMove", "CPacketVehicleMove");
|
||||
public static final PacketType BOAT_MOVE = new PacketType(PROTOCOL, SENDER, 0x19, "BoatMove", "CPacketSteerBoat");
|
||||
public static final PacketType PICK_ITEM = new PacketType(PROTOCOL, SENDER, 0x1A, "PickItem");
|
||||
@ -457,7 +457,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
@Deprecated
|
||||
public static final PacketType CHAT_PREVIEW = new PacketType(PROTOCOL, SENDER, 0x06, "ChatPreview");
|
||||
|
||||
private final static Client INSTANCE = new Client();
|
||||
private static final Client INSTANCE = new Client();
|
||||
|
||||
// Prevent accidental construction
|
||||
private Client() { super(); }
|
||||
@ -480,14 +480,14 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Status {
|
||||
private static final Protocol PROTOCOL = Protocol.STATUS;
|
||||
static final Protocol PROTOCOL = Protocol.STATUS;
|
||||
|
||||
/**
|
||||
* Outgoing packets.
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Server extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.SERVER;
|
||||
private static final Sender SENDER = Sender.SERVER;
|
||||
|
||||
@ForceAsync
|
||||
public static final PacketType SERVER_INFO = new PacketType(PROTOCOL, SENDER, 0x00, "ServerInfo", "SPacketServerInfo");
|
||||
@ -501,7 +501,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
@ForceAsync
|
||||
public static final PacketType OUT_SERVER_INFO = SERVER_INFO.clone();
|
||||
|
||||
private final static Server INSTANCE = new Server();
|
||||
private static final Server INSTANCE = new Server();
|
||||
|
||||
// Prevent accidental construction
|
||||
private Server() { super(); }
|
||||
@ -519,13 +519,13 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Client extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.CLIENT;
|
||||
private static final Sender SENDER = Sender.CLIENT;
|
||||
|
||||
public static final PacketType START = new PacketType(PROTOCOL, SENDER, 0x00, "Start", "CPacketServerQuery");
|
||||
@ForceAsync
|
||||
public static final PacketType PING = new PacketType(PROTOCOL, SENDER, 0x01, "Ping", "CPacketPing");
|
||||
|
||||
private final static Client INSTANCE = new Client();
|
||||
private static final Client INSTANCE = new Client();
|
||||
|
||||
// Prevent accidental construction
|
||||
private Client() { super(); }
|
||||
@ -548,14 +548,14 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Login {
|
||||
private static final Protocol PROTOCOL = Protocol.LOGIN;
|
||||
static final Protocol PROTOCOL = Protocol.LOGIN;
|
||||
|
||||
/**
|
||||
* Outgoing packets.
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Server extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.SERVER;
|
||||
private static final Sender SENDER = Sender.SERVER;
|
||||
|
||||
@ForceAsync
|
||||
public static final PacketType DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x00, "Disconnect", "SPacketDisconnect");
|
||||
@ -564,7 +564,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x03, "SetCompression", "SPacketEnableCompression");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x04, "CustomPayload", "SPacketCustomPayload");
|
||||
|
||||
private final static Server INSTANCE = new Server();
|
||||
private static final Server INSTANCE = new Server();
|
||||
|
||||
// Prevent accidental construction
|
||||
private Server() { super(); }
|
||||
@ -582,13 +582,13 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Client extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.CLIENT;
|
||||
private static final Sender SENDER = Sender.CLIENT;
|
||||
|
||||
public static final PacketType START = new PacketType(PROTOCOL, SENDER, 0x00, "Start", "CPacketLoginStart");
|
||||
public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, "EncryptionBegin", "CPacketEncryptionResponse");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x02, "CustomPayload", "CPacketCustomPayload");
|
||||
|
||||
private final static Client INSTANCE = new Client();
|
||||
private static final Client INSTANCE = new Client();
|
||||
|
||||
// Prevent accidental construction
|
||||
private Client() { super(); }
|
||||
|
@ -121,9 +121,7 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
|
||||
event.setReadOnly(element.getPriority() == ListenerPriority.MONITOR);
|
||||
element.getListener().onPacketReceiving(event);
|
||||
|
||||
} catch (OutOfMemoryError e) {
|
||||
throw e;
|
||||
} catch (ThreadDeath e) {
|
||||
} catch (OutOfMemoryError | ThreadDeath e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
// Minecraft doesn't want your Exception.
|
||||
@ -149,22 +147,25 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
|
||||
*/
|
||||
public void invokePacketSending(ErrorReporter reporter, PacketEvent event, @Nullable ListenerPriority priorityFilter) {
|
||||
invokeUnpackedPacketSending(reporter, event, priorityFilter);
|
||||
if(event.getPacketType() == PacketType.Play.Server.DELIMITER && !event.isCancelled()) {
|
||||
if (event.getPacketType() == PacketType.Play.Server.BUNDLE && !event.isCancelled()) {
|
||||
// unpack the bundle and invoke for each packet in the bundle
|
||||
Iterable<PacketContainer> packets = event.getPacket().getPacketBundles().read(0);
|
||||
List<PacketContainer> outPackets = new ArrayList<>();
|
||||
for(PacketContainer subPacket : packets) {
|
||||
for (PacketContainer subPacket : packets) {
|
||||
PacketEvent subPacketEvent = PacketEvent.fromServer(this, subPacket, event.getNetworkMarker(), event.getPlayer());
|
||||
invokeUnpackedPacketSending(reporter, subPacketEvent, priorityFilter);
|
||||
|
||||
if(!subPacketEvent.isCancelled()) {
|
||||
outPackets.add(subPacketEvent.getPacket()); // if the packet event has been cancelled, the packet will be removed from the bundle.
|
||||
if (!subPacketEvent.isCancelled()) {
|
||||
// if the packet event has been cancelled, the packet will be removed from the bundle
|
||||
outPackets.add(subPacketEvent.getPacket());
|
||||
}
|
||||
}
|
||||
if(packets.iterator().hasNext()) { // are there still packets in this bundle?
|
||||
|
||||
if (packets.iterator().hasNext()) {
|
||||
event.getPacket().getPacketBundles().write(0, outPackets);
|
||||
} else {
|
||||
event.setCancelled(true); // cancel packet if each individual packet has been canceled
|
||||
// cancel entire packet if each individual packet has been cancelled
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -201,14 +202,12 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu
|
||||
* @param event - the related packet event.
|
||||
* @param element - the listener to invoke.
|
||||
*/
|
||||
private final void invokeSendingListener(ErrorReporter reporter, PacketEvent event, PrioritizedListener<PacketListener> element) {
|
||||
private void invokeSendingListener(ErrorReporter reporter, PacketEvent event, PrioritizedListener<PacketListener> element) {
|
||||
try {
|
||||
event.setReadOnly(element.getPriority() == ListenerPriority.MONITOR);
|
||||
element.getListener().onPacketSending(event);
|
||||
|
||||
} catch (OutOfMemoryError e) {
|
||||
throw e;
|
||||
} catch (ThreadDeath e) {
|
||||
} catch (OutOfMemoryError | ThreadDeath e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
// Minecraft doesn't want your Exception.
|
||||
|
@ -137,9 +137,10 @@ public class StructureCache {
|
||||
Class<?> packetClass = PacketRegistry.getPacketClassFromType(type);
|
||||
|
||||
// We need to map the Bundle Delimiter to the synthetic bundle packet which contains a list of all packets in a bundle
|
||||
if(MinecraftVersion.atOrAbove(MinecraftVersion.FEATURE_PREVIEW_2) && packetClass.equals(MinecraftReflection.getBundleDelimiterClass())) {
|
||||
if (MinecraftVersion.atOrAbove(MinecraftVersion.FEATURE_PREVIEW_2) && packetClass.equals(MinecraftReflection.getBundleDelimiterClass())) {
|
||||
packetClass = MinecraftReflection.getPackedBundlePacketClass();
|
||||
}
|
||||
|
||||
return new StructureModifier<>(packetClass, MinecraftReflection.getPacketClass(), true);
|
||||
});
|
||||
}
|
||||
|
@ -553,7 +553,7 @@ public class NettyChannelInjector implements Injector {
|
||||
}
|
||||
|
||||
// no listener and no marker - no magic :)
|
||||
if (!this.channelListener.hasListener(packet.getClass()) && marker == null && !Util.isBundlePacket(packet.getClass())) {
|
||||
if (!this.channelListener.hasListener(packet.getClass()) && marker == null && !MinecraftReflection.isBundlePacket(packet.getClass())) {
|
||||
return action;
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class NetworkManagerInjector implements ChannelListener {
|
||||
public PacketEvent onPacketSending(Injector injector, Object packet, NetworkMarker marker) {
|
||||
// check if we need to intercept the packet
|
||||
Class<?> packetClass = packet.getClass();
|
||||
if (this.outboundListeners.contains(packetClass) || marker != null || Util.isBundlePacket(packetClass)) {
|
||||
if (marker != null || MinecraftReflection.isBundlePacket(packetClass) || outboundListeners.contains(packetClass)) {
|
||||
// wrap packet and construct the event
|
||||
PacketContainer container = new PacketContainer(PacketRegistry.getPacketType(packetClass), packet);
|
||||
PacketEvent packetEvent = PacketEvent.fromServer(this, container, marker, injector.getPlayer());
|
||||
@ -109,7 +109,7 @@ public class NetworkManagerInjector implements ChannelListener {
|
||||
public PacketEvent onPacketReceiving(Injector injector, Object packet, NetworkMarker marker) {
|
||||
// check if we need to intercept the packet
|
||||
Class<?> packetClass = packet.getClass();
|
||||
if (this.inboundListeners.contains(packetClass) || marker != null) {
|
||||
if (marker != null || inboundListeners.contains(packetClass)) {
|
||||
// wrap the packet and construct the event
|
||||
PacketContainer container = new PacketContainer(PacketRegistry.getPacketType(packetClass), packet);
|
||||
PacketEvent packetEvent = PacketEvent.fromClient(this, container, marker, injector.getPlayer());
|
||||
|
@ -46,12 +46,12 @@ public class PacketRegistry {
|
||||
*/
|
||||
protected static class Register {
|
||||
// The main lookup table
|
||||
private final Map<PacketType, Optional<Class<?>>> typeToClass = new ConcurrentHashMap<>();
|
||||
private final Map<Class<?>, PacketType> classToType = new ConcurrentHashMap<>();
|
||||
final Map<PacketType, Optional<Class<?>>> typeToClass = new ConcurrentHashMap<>();
|
||||
final Map<Class<?>, PacketType> classToType = new ConcurrentHashMap<>();
|
||||
|
||||
private volatile Set<PacketType> serverPackets = new HashSet<>();
|
||||
private volatile Set<PacketType> clientPackets = new HashSet<>();
|
||||
private final List<MapContainer> containers = new ArrayList<>();
|
||||
volatile Set<PacketType> serverPackets = new HashSet<>();
|
||||
volatile Set<PacketType> clientPackets = new HashSet<>();
|
||||
final List<MapContainer> containers = new ArrayList<>();
|
||||
|
||||
public Register() {}
|
||||
|
||||
@ -383,10 +383,12 @@ public class PacketRegistry {
|
||||
* @return The packet type, or NULL if not found.
|
||||
*/
|
||||
public static PacketType getPacketType(Class<?> packet) {
|
||||
if(Util.isBundlePacket(packet)) {
|
||||
return PacketType.Play.Server.DELIMITER;
|
||||
}
|
||||
initialize();
|
||||
|
||||
if (MinecraftReflection.isBundlePacket(packet)) {
|
||||
return PacketType.Play.Server.BUNDLE;
|
||||
}
|
||||
|
||||
return REGISTER.classToType.get(packet);
|
||||
}
|
||||
|
||||
|
@ -632,6 +632,10 @@ public final class MinecraftReflection {
|
||||
return getMinecraftClass("network.protocol.game.ClientboundBundlePacket", "ClientboundBundlePacket");
|
||||
}
|
||||
|
||||
public static boolean isBundlePacket(Class<?> packetClass) {
|
||||
return MinecraftVersion.FEATURE_PREVIEW_2.atOrAbove() && packetClass.equals(getPackedBundlePacketClass());
|
||||
}
|
||||
|
||||
public static Class<?> getBundleDelimiterClass() {
|
||||
return getMinecraftClass("network.protocol.BundleDelimiterPacket","BundleDelimiterPacket");
|
||||
}
|
||||
|
@ -60,14 +60,4 @@ public final class Util {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isBundlePacket(Class<?> packetClass) {
|
||||
if(!MinecraftVersion.atOrAbove(MinecraftVersion.FEATURE_PREVIEW_2)) {
|
||||
return false;
|
||||
}
|
||||
if(cachedBundleClass == null) {
|
||||
cachedBundleClass = MinecraftReflection.getPackedBundlePacketClass();
|
||||
}
|
||||
return packetClass.equals(cachedBundleClass);
|
||||
}
|
||||
}
|
||||
|
@ -828,7 +828,7 @@ public class PacketContainerTest {
|
||||
for (PacketType type : PacketType.values()) {
|
||||
// TODO: try to support chat - for now chat contains to many sub classes to properly clone it
|
||||
if (type.isDeprecated() || !type.isSupported() || type.name().contains("CUSTOM_PAYLOAD") || type.name().contains("CHAT")
|
||||
|| type.name().contains("DELIMITER")) {
|
||||
|| type.name().contains("BUNDLE")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user