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;
|
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.
|
* Register a particular packet type.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -79,15 +79,15 @@ class InjectionFactory {
|
|||||||
* @return The cached injector, or a closed injector if it could not be found.
|
* @return The cached injector, or a closed injector if it could not be found.
|
||||||
*/
|
*/
|
||||||
public Injector fromName(String name, Player player) {
|
public Injector fromName(String name, Player player) {
|
||||||
if (closed)
|
if (!closed) {
|
||||||
return new ClosedInjector(player);
|
Injector injector = nameLookup.get(name);
|
||||||
Injector injector = nameLookup.get(name);
|
|
||||||
|
// We can only retrieve cached injectors
|
||||||
// We can only retrieve cached injectors
|
if (injector != null) {
|
||||||
if (injector != null) {
|
// Update instance
|
||||||
// Update instance
|
injector.setUpdatedPlayer(player);
|
||||||
injector.setUpdatedPlayer(player);
|
return injector;
|
||||||
return injector;
|
}
|
||||||
}
|
}
|
||||||
return new ClosedInjector(player);
|
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.
|
* @return The packet type lookup.
|
||||||
*/
|
*/
|
||||||
public Map<Class<?>, PacketType> getPacketClassLookup() {
|
public Map<Class<?>, PacketType> getPacketClassLookup() {
|
||||||
|
@ -393,14 +393,14 @@ public class PacketRegistry {
|
|||||||
/**
|
/**
|
||||||
* Retrieve the packet type of a given packet.
|
* Retrieve the packet type of a given packet.
|
||||||
* @param packet - the class of the packet.
|
* @param packet - the class of the packet.
|
||||||
* @return The packet type.
|
* @return The packet type, or NULL if not found.
|
||||||
* @throws IllegalArgumentException If this is not a valid packet.
|
|
||||||
*/
|
*/
|
||||||
public static PacketType getPacketType(Class<?> packet) {
|
public static PacketType getPacketType(Class<?> packet) {
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
if (NETTY != null)
|
if (NETTY != null)
|
||||||
return NETTY.getPacketClassLookup().get(packet);
|
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