Add a test to make sure all packets are registered
Dieser Commit ist enthalten in:
Ursprung
9f2141331a
Commit
a718cc9067
@ -523,6 +523,7 @@ public class PacketType implements Serializable, Comparable<PacketType> {
|
|||||||
private final int currentId;
|
private final int currentId;
|
||||||
private final int legacyId;
|
private final int legacyId;
|
||||||
private final MinecraftVersion version;
|
private final MinecraftVersion version;
|
||||||
|
private final boolean dynamic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the current packet/legacy lookup.
|
* Retrieve the current packet/legacy lookup.
|
||||||
@ -678,7 +679,7 @@ public class PacketType implements Serializable, Comparable<PacketType> {
|
|||||||
PacketType type = getLookup().getFromCurrent(protocol, sender, packetId);
|
PacketType type = getLookup().getFromCurrent(protocol, sender, packetId);
|
||||||
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
type = new PacketType(protocol, sender, packetId, legacyId);
|
type = new PacketType(protocol, sender, packetId, legacyId, PROTOCOL_VERSION, true);
|
||||||
|
|
||||||
// Many may be scheduled, but only the first will be executed
|
// Many may be scheduled, but only the first will be executed
|
||||||
scheduleRegister(type, "Dynamic-" + UUID.randomUUID().toString());
|
scheduleRegister(type, "Dynamic-" + UUID.randomUUID().toString());
|
||||||
@ -797,11 +798,25 @@ public class PacketType implements Serializable, Comparable<PacketType> {
|
|||||||
* @param version - the version of the current ID.
|
* @param version - the version of the current ID.
|
||||||
*/
|
*/
|
||||||
public PacketType(Protocol protocol, Sender sender, int currentId, int legacyId, MinecraftVersion version) {
|
public PacketType(Protocol protocol, Sender sender, int currentId, int legacyId, MinecraftVersion version) {
|
||||||
|
this(protocol, sender, currentId, legacyId, version, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new packet type.
|
||||||
|
* @param protocol - the current protocol.
|
||||||
|
* @param sender - client or server.
|
||||||
|
* @param currentId - the current packet ID.
|
||||||
|
* @param legacyId - the legacy packet ID.
|
||||||
|
* @param version - the version of the current ID.
|
||||||
|
* @param dynamic - if this type was created dynamically.
|
||||||
|
*/
|
||||||
|
public PacketType(Protocol protocol, Sender sender, int currentId, int legacyId, MinecraftVersion version, boolean dynamic) {
|
||||||
this.protocol = Preconditions.checkNotNull(protocol, "protocol cannot be NULL");
|
this.protocol = Preconditions.checkNotNull(protocol, "protocol cannot be NULL");
|
||||||
this.sender = Preconditions.checkNotNull(sender, "sender cannot be NULL");
|
this.sender = Preconditions.checkNotNull(sender, "sender cannot be NULL");
|
||||||
this.currentId = currentId;
|
this.currentId = currentId;
|
||||||
this.legacyId = legacyId;
|
this.legacyId = legacyId;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
this.dynamic = dynamic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -903,6 +918,14 @@ public class PacketType implements Serializable, Comparable<PacketType> {
|
|||||||
return legacyId;
|
return legacyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not this packet was dynamically created (ie we don't have it registered)
|
||||||
|
* @return True if dnyamic, false if not.
|
||||||
|
*/
|
||||||
|
public boolean isDynamic() {
|
||||||
|
return dynamic;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(protocol, sender, currentId, legacyId);
|
return Objects.hashCode(protocol, sender, currentId, legacyId);
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
package com.comphenix.protocol;
|
package com.comphenix.protocol;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType.Protocol;
|
import com.comphenix.protocol.PacketType.Protocol;
|
||||||
import com.comphenix.protocol.PacketType.Sender;
|
import com.comphenix.protocol.PacketType.Sender;
|
||||||
|
import com.comphenix.protocol.injector.netty.NettyProtocolRegistry;
|
||||||
|
|
||||||
public class PacketTypeTest {
|
public class PacketTypeTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initializeReflection() throws IllegalAccessException {
|
public static void initializeReflection() throws IllegalAccessException {
|
||||||
BukkitInitialization.initializePackage();
|
BukkitInitialization.initializePackage();
|
||||||
@ -18,4 +24,18 @@ public class PacketTypeTest {
|
|||||||
public void testFindCurrent() {
|
public void testFindCurrent() {
|
||||||
assertEquals(PacketType.Play.Client.STEER_VEHICLE, PacketType.findCurrent(Protocol.PLAY, Sender.CLIENT, 12));
|
assertEquals(PacketType.Play.Client.STEER_VEHICLE, PacketType.findCurrent(Protocol.PLAY, Sender.CLIENT, 12));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ensureAllExist() {
|
||||||
|
NettyProtocolRegistry registry = new NettyProtocolRegistry();
|
||||||
|
Map<PacketType, Class<?>> lookup = registry.getPacketTypeLookup();
|
||||||
|
for (Entry<PacketType, Class<?>> entry : lookup.entrySet()) {
|
||||||
|
PacketType type = entry.getKey();
|
||||||
|
Class<?> clazz = entry.getValue();
|
||||||
|
|
||||||
|
if (type.isDynamic()) {
|
||||||
|
fail("Packet " + clazz + " does not have a corresponding PacketType!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren