Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
a8b808ba
Commit
a8b808ba
authored
May 01, 2022
by
coooookies
Committed by
Melledy
May 01, 2022
Browse files
Improve registration methods.
parent
dde5a609
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java
View file @
a8b808ba
...
...
@@ -23,25 +23,15 @@ public class GameServerPacketHandler {
this
.
registerHandlers
(
handlerClass
);
}
public
void
registerPacketHandler
(
int
opcode
,
PacketHandler
handler
)
{
this
.
handlers
.
put
(
opcode
,
handler
);
}
public
void
registerHandlers
(
Class
<?
extends
PacketHandler
>
handlerClass
)
{
Reflections
reflections
=
new
Reflections
(
"emu.grasscutter.server.packet"
);
Set
<?>
handlerClasses
=
reflections
.
getSubTypesOf
(
handlerClass
);
for
(
Object
obj
:
handlerClasses
)
{
Class
<?>
c
=
(
Class
<?>)
obj
;
public
void
registerPacketHandler
(
Class
<?
extends
PacketHandler
>
handlerClass
)
{
try
{
Opcodes
opcode
=
c
.
getAnnotation
(
Opcodes
.
class
);
Opcodes
opcode
=
handlerClass
.
getAnnotation
(
Opcodes
.
class
);
if
(
opcode
==
null
||
opcode
.
disabled
()
||
opcode
.
value
()
<=
0
)
{
continue
;
return
;
}
PacketHandler
packetHandler
=
(
PacketHandler
)
c
.
newInstance
();
PacketHandler
packetHandler
=
(
PacketHandler
)
handlerClass
.
newInstance
();
this
.
handlers
.
put
(
opcode
.
value
(),
packetHandler
);
}
catch
(
Exception
e
)
{
...
...
@@ -49,6 +39,14 @@ public class GameServerPacketHandler {
}
}
public
void
registerHandlers
(
Class
<?
extends
PacketHandler
>
handlerClass
)
{
Reflections
reflections
=
new
Reflections
(
"emu.grasscutter.server.packet"
);
Set
<?>
handlerClasses
=
reflections
.
getSubTypesOf
(
handlerClass
);
for
(
Object
obj
:
handlerClasses
)
{
this
.
registerPacketHandler
((
Class
<?
extends
PacketHandler
>)
obj
);
}
// Debug
Grasscutter
.
getLogger
().
info
(
"Registered "
+
this
.
handlers
.
size
()
+
" "
+
handlerClass
.
getSimpleName
()
+
"s"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment