mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-24 01:21:30 +00:00
Add get
methods to the server hook
This commit is contained in:
parent
34c358669b
commit
5b351b955c
@ -1,5 +1,7 @@
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user