13
0
geforkt von Mirrors/Velocity

Log the protocol phase in case of trying to obtain a packet id not existing in the phase (#1107)

Dieser Commit ist enthalten in:
Adrian 2023-10-12 15:29:04 -05:00 committet von GitHub
Ursprung eb594fc799
Commit f884e049c0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 14 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -550,8 +550,8 @@ public enum StateRegistry {
public static final int STATUS_ID = 1;
public static final int LOGIN_ID = 2;
protected final PacketRegistry clientbound = new PacketRegistry(CLIENTBOUND);
protected final PacketRegistry serverbound = new PacketRegistry(SERVERBOUND);
protected final PacketRegistry clientbound = new PacketRegistry(CLIENTBOUND, this);
protected final PacketRegistry serverbound = new PacketRegistry(SERVERBOUND, this);
public StateRegistry.PacketRegistry.ProtocolRegistry getProtocolRegistry(Direction direction,
ProtocolVersion version) {
@ -562,11 +562,13 @@ public enum StateRegistry {
public static class PacketRegistry {
private final Direction direction;
private final StateRegistry registry;
private final Map<ProtocolVersion, ProtocolRegistry> versions;
private boolean fallback = true;
PacketRegistry(Direction direction) {
PacketRegistry(Direction direction, StateRegistry registry) {
this.direction = direction;
this.registry = registry;
Map<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap<>(ProtocolVersion.class);
for (ProtocolVersion version : ProtocolVersion.values()) {
@ -693,8 +695,9 @@ public enum StateRegistry {
final int id = this.packetClassToId.getInt(packet.getClass());
if (id == Integer.MIN_VALUE) {
throw new IllegalArgumentException(String.format(
"Unable to find id for packet of type %s in %s protocol %s",
packet.getClass().getName(), PacketRegistry.this.direction, this.version
"Unable to find id for packet of type %s in %s protocol %s phase %s",
packet.getClass().getName(), PacketRegistry.this.direction,
this.version, PacketRegistry.this.registry
));
}
return id;

Datei anzeigen

@ -44,7 +44,7 @@ class PacketRegistryTest {
private StateRegistry.PacketRegistry setupRegistry() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND);
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
registry.register(Handshake.class, Handshake::new,
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, null, false),
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, null, false),
@ -84,7 +84,7 @@ class PacketRegistryTest {
@Test
void failOnNoMappings() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND);
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
assertThrows(IllegalArgumentException.class,
() -> registry.register(Handshake.class, Handshake::new));
assertThrows(IllegalArgumentException.class,
@ -94,7 +94,7 @@ class PacketRegistryTest {
@Test
void failOnWrongOrder() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND);
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
assertThrows(IllegalArgumentException.class,
() -> registry.register(Handshake.class, Handshake::new,
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, null, false),
@ -115,7 +115,7 @@ class PacketRegistryTest {
@Test
void failOnDuplicate() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND);
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
registry.register(Handshake.class, Handshake::new,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, null, false));
assertThrows(IllegalArgumentException.class,
@ -129,7 +129,7 @@ class PacketRegistryTest {
@Test
void shouldNotFailWhenRegisterLatestProtocolVersion() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND);
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
assertDoesNotThrow(() -> registry.register(Handshake.class, Handshake::new,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, null, false),
new StateRegistry.PacketMapping(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS),
@ -139,7 +139,7 @@ class PacketRegistryTest {
@Test
void registrySuppliesCorrectPacketsByProtocol() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND);
ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY);
registry.register(Handshake.class, Handshake::new,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, null, false),
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, null, false),