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
47d8fd3c
Commit
47d8fd3c
authored
Apr 26, 2022
by
KingRainbow44
Browse files
Add `get` methods to the server hook
parent
d4f9820e
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/plugin/api/ServerHook.java
View file @
47d8fd3c
package
emu.grasscutter.plugin.api
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.server.dispatch.DispatchServer
;
import
emu.grasscutter.server.game.GameServer
;
...
...
@@ -35,6 +37,20 @@ public final class ServerHook {
instance
=
this
;
}
/**
* @return The game server.
*/
public
GameServer
getGameServer
()
{
return
this
.
gameServer
;
}
/**
* @return The dispatch server.
*/
public
DispatchServer
getDispatchServer
()
{
return
this
.
dispatchServer
;
}
/**
* Gets all online players.
* @return Players connected to the server.
...
...
@@ -42,4 +58,16 @@ public final class ServerHook {
public
List
<
GenshinPlayer
>
getOnlinePlayers
()
{
return
new
LinkedList
<>(
this
.
gameServer
.
getPlayers
().
values
());
}
/**
* Registers a command to the {@link emu.grasscutter.command.CommandMap}.
* @param handler The command handler.
*/
public
void
registerCommand
(
CommandHandler
handler
)
{
Class
<?
extends
CommandHandler
>
clazz
=
handler
.
getClass
();
if
(!
clazz
.
isAnnotationPresent
(
Command
.
class
))
throw
new
IllegalArgumentException
(
"Command handler must be annotated with @Command."
);
Command
commandData
=
clazz
.
getAnnotation
(
Command
.
class
);
this
.
gameServer
.
getCommandMap
().
registerCommand
(
commandData
.
label
(),
handler
);
}
}
\ No newline at end of file
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