Add get methods to the server hook

This commit is contained in:
KingRainbow44 2022-04-26 21:24:37 -04:00
parent 34c358669b
commit 5b351b955c
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE

View File

@ -1,5 +1,7 @@
package emu.grasscutter.plugin.api; package emu.grasscutter.plugin.api;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.server.dispatch.DispatchServer; import emu.grasscutter.server.dispatch.DispatchServer;
import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameServer;
@ -35,6 +37,20 @@ public final class ServerHook {
instance = this; 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. * Gets all online players.
* @return Players connected to the server. * @return Players connected to the server.
@ -42,4 +58,16 @@ public final class ServerHook {
public List<GenshinPlayer> getOnlinePlayers() { public List<GenshinPlayer> getOnlinePlayers() {
return new LinkedList<>(this.gameServer.getPlayers().values()); 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);
}
} }