Archiviert
13
0

Make it possible to look up the enum name of a PacketType.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-12-30 15:25:34 +01:00
Ursprung 58c027f162
Commit e0fed34fe4

Datei anzeigen

@ -713,20 +713,7 @@ public class PacketType implements Serializable {
ObjectEnum<PacketType> objEnum; ObjectEnum<PacketType> objEnum;
// A bit ugly, but performance is critical // A bit ugly, but performance is critical
switch (type.getProtocol()) { objEnum = getObjectEnum(type);
case HANDSHAKING:
objEnum = type.isClient() ? Handshake.Client.getInstance() : Handshake.Server.getInstance(); break;
case PLAY:
objEnum = type.isClient() ? Play.Client.getInstance() : Play.Server.getInstance(); break;
case STATUS:
objEnum = type.isClient() ? Status.Client.getInstance() : Status.Server.getInstance(); break;
case LOGIN:
objEnum = type.isClient() ? Login.Client.getInstance() : Login.Server.getInstance(); break;
case LEGACY:
objEnum = type.isClient() ? Legacy.Client.getInstance() : Legacy.Server.getInstance(); break;
default:
throw new IllegalStateException("Unexpected protocol: " + type.getProtocol());
}
if (objEnum.registerMember(type, name)) { if (objEnum.registerMember(type, name)) {
getLookup().addPacketTypes(Arrays.asList(type)); getLookup().addPacketTypes(Arrays.asList(type));
@ -747,6 +734,28 @@ public class PacketType implements Serializable {
return ProtocolLibrary.getExecutorSync().submit(callable); return ProtocolLibrary.getExecutorSync().submit(callable);
} }
/**
* Retrieve the correct object enum from a specific packet type.
* @param type - the packet type.
* @return The corresponding object enum.
*/
public static ObjectEnum<PacketType> getObjectEnum(final PacketType type) {
switch (type.getProtocol()) {
case HANDSHAKING:
return type.isClient() ? Handshake.Client.getInstance() : Handshake.Server.getInstance();
case PLAY:
return type.isClient() ? Play.Client.getInstance() : Play.Server.getInstance();
case STATUS:
return type.isClient() ? Status.Client.getInstance() : Status.Server.getInstance();
case LOGIN:
return type.isClient() ? Login.Client.getInstance() : Login.Server.getInstance();
case LEGACY:
return type.isClient() ? Legacy.Client.getInstance() : Legacy.Server.getInstance();
default:
throw new IllegalStateException("Unexpected protocol: " + type.getProtocol());
}
}
/** /**
* Construct a new packet type. * Construct a new packet type.
* @param protocol - the current protocol. * @param protocol - the current protocol.
@ -847,6 +856,14 @@ public class PacketType implements Serializable {
} }
} }
/**
* Retrieve the declared enum name of this packet type.
* @return The enum name.
*/
public String name() {
return getObjectEnum(this).getDeclaredName(this);
}
/** /**
* Retrieve the Minecraft version for the current ID. * Retrieve the Minecraft version for the current ID.
* @return The Minecraft version. * @return The Minecraft version.