Add the ability to look up PacketType from class.
Dieser Commit ist enthalten in:
Ursprung
acea92ef5c
Commit
af58dd8d03
@ -653,6 +653,28 @@ public class PacketType implements Serializable {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a packet type from a packet class.
|
||||
* @param packetClass - the packet class.
|
||||
* @return The corresponding packet type, or NULL if not found.
|
||||
*/
|
||||
public static PacketType fromClass(Class<?> packetClass) {
|
||||
PacketType type = PacketRegistry.getPacketType(packetClass);
|
||||
|
||||
if (type != null)
|
||||
return type;
|
||||
throw new IllegalArgumentException("Class " + packetClass + " is not a registered packet.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given class represents a packet class.
|
||||
* @param packetClass - the class to lookup.
|
||||
* @return TRUE if this is a packet class, FALSE otherwise.
|
||||
*/
|
||||
public static boolean hasClass(Class<?> packetClass) {
|
||||
return PacketRegistry.getPacketType(packetClass) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a particular packet type.
|
||||
* <p>
|
||||
|
@ -79,8 +79,7 @@ class InjectionFactory {
|
||||
* @return The cached injector, or a closed injector if it could not be found.
|
||||
*/
|
||||
public Injector fromName(String name, Player player) {
|
||||
if (closed)
|
||||
return new ClosedInjector(player);
|
||||
if (!closed) {
|
||||
Injector injector = nameLookup.get(name);
|
||||
|
||||
// We can only retrieve cached injectors
|
||||
@ -89,6 +88,7 @@ class InjectionFactory {
|
||||
injector.setUpdatedPlayer(player);
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
return new ClosedInjector(player);
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class NettyProtocolRegistry {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an immutable view of the class to packet tyåe lookup.
|
||||
* Retrieve an immutable view of the class to packet type lookup.
|
||||
* @return The packet type lookup.
|
||||
*/
|
||||
public Map<Class<?>, PacketType> getPacketClassLookup() {
|
||||
|
@ -393,14 +393,14 @@ public class PacketRegistry {
|
||||
/**
|
||||
* Retrieve the packet type of a given packet.
|
||||
* @param packet - the class of the packet.
|
||||
* @return The packet type.
|
||||
* @throws IllegalArgumentException If this is not a valid packet.
|
||||
* @return The packet type, or NULL if not found.
|
||||
*/
|
||||
public static PacketType getPacketType(Class<?> packet) {
|
||||
initialize();
|
||||
|
||||
if (NETTY != null)
|
||||
return NETTY.getPacketClassLookup().get(packet);
|
||||
return PacketType.findLegacy(LEGACY.getPacketID(packet));
|
||||
final int id = LEGACY.getPacketID(packet);
|
||||
return PacketType.hasLegacy(id) ? PacketType.findLegacy(id) : null;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren