Plugin.java 1.65 KB
Newer Older
KingRainbow44's avatar
KingRainbow44 committed
1
2
3
4
5
6
7
8
9
package emu.grasscutter.plugin;

import emu.grasscutter.Grasscutter;
import emu.grasscutter.server.game.GameServer;

/**
 * The base class for all plugins to extend.
 */
public abstract class Plugin {
KingRainbow44's avatar
KingRainbow44 committed
10
    private PluginIdentifier identifier;
KingRainbow44's avatar
KingRainbow44 committed
11
12

    /**
KingRainbow44's avatar
KingRainbow44 committed
13
14
15
     * This method is reflected into.
     * 
     * Set plugin variables.
KingRainbow44's avatar
KingRainbow44 committed
16
17
     * @param identifier The plugin's identifier.
     */
KingRainbow44's avatar
KingRainbow44 committed
18
19
20
21
    private void initializePlugin(PluginIdentifier identifier) {
        if(this.identifier == null)
            this.identifier = identifier;
        else Grasscutter.getLogger().warn(this.identifier.name + " had a reinitialization attempt.");
KingRainbow44's avatar
KingRainbow44 committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    }

    /**
     * The plugin's identifier instance.
     * @return An instance of {@link PluginIdentifier}.
     */
    public final PluginIdentifier getIdentifier(){
        return this.identifier;
    }

    /**
     * Get the plugin's name.
     */
    public final String getName() {
        return this.identifier.name;
    }

    /**
     * Get the plugin's description.
     */
    public final String getDescription() {
        return this.identifier.description;
    }

    /**
     * Get the plugin's version.
     */
    public final String getVersion() {
        return this.identifier.version;
    }

    /**
     * Returns the server that initialized the plugin.
     * @return A server instance.
     */
    public final GameServer getServer() {
        return Grasscutter.getGameServer();
    }
    
    /* Called when the plugin is first loaded. */
    public void onLoad() { }
    /* Called after (most of) the server enables. */
    public void onEnable() { }
    /* Called before the server disables. */
    public void onDisable() { }
}