ServerHook.java 986 Bytes
Newer Older
KingRainbow44's avatar
KingRainbow44 committed
1
2
package emu.grasscutter.plugin.api;

Melledy's avatar
Melledy committed
3
import emu.grasscutter.game.player.Player;
KingRainbow44's avatar
KingRainbow44 committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import emu.grasscutter.server.game.GameServer;

import java.util.LinkedList;
import java.util.List;

/**
 * Hooks into the {@link GameServer} class, adding convenient ways to do certain things.
 */
public final class ServerHook {
    private static ServerHook instance;
    private final GameServer server;

    /**
     * Gets the server hook instance.
     * @return A {@link ServerHook} singleton.
     */
    public static ServerHook getInstance() {
        return instance;
    }

    /**
     * Hooks into a server.
     * @param server The server to hook into.
     */
    public ServerHook(GameServer server) {
        this.server = server;
        
        instance = this;
    }

    /**
     * Gets all online players.
     * @return Players connected to the server.
     */
38
    public List<Player> getOnlinePlayers() {
KingRainbow44's avatar
KingRainbow44 committed
39
40
41
        return new LinkedList<>(this.server.getPlayers().values());
    }
}