mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-11 00:02:53 +08:00
Improve registration methods.
This commit is contained in:
parent
dde5a609fb
commit
a8b808ba2e
@ -23,8 +23,20 @@ public class GameServerPacketHandler {
|
|||||||
this.registerHandlers(handlerClass);
|
this.registerHandlers(handlerClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerPacketHandler(int opcode, PacketHandler handler) {
|
public void registerPacketHandler(Class<? extends PacketHandler> handlerClass) {
|
||||||
this.handlers.put(opcode, handler);
|
try {
|
||||||
|
Opcodes opcode = handlerClass.getAnnotation(Opcodes.class);
|
||||||
|
|
||||||
|
if (opcode == null || opcode.disabled() || opcode.value() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketHandler packetHandler = (PacketHandler) handlerClass.newInstance();
|
||||||
|
|
||||||
|
this.handlers.put(opcode.value(), packetHandler);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerHandlers(Class<? extends PacketHandler> handlerClass) {
|
public void registerHandlers(Class<? extends PacketHandler> handlerClass) {
|
||||||
@ -32,21 +44,7 @@ public class GameServerPacketHandler {
|
|||||||
Set<?> handlerClasses = reflections.getSubTypesOf(handlerClass);
|
Set<?> handlerClasses = reflections.getSubTypesOf(handlerClass);
|
||||||
|
|
||||||
for (Object obj : handlerClasses) {
|
for (Object obj : handlerClasses) {
|
||||||
Class<?> c = (Class<?>) obj;
|
this.registerPacketHandler((Class<? extends PacketHandler>) obj);
|
||||||
|
|
||||||
try {
|
|
||||||
Opcodes opcode = c.getAnnotation(Opcodes.class);
|
|
||||||
|
|
||||||
if (opcode == null || opcode.disabled() || opcode.value() <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketHandler packetHandler = (PacketHandler) c.newInstance();
|
|
||||||
|
|
||||||
this.handlers.put(opcode.value(), packetHandler);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
|
Loading…
Reference in New Issue
Block a user