/
GalaxiEngine.java
107 lines (93 loc) · 2.67 KB
/
GalaxiEngine.java
1
2
3
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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package net.ME1312.Galaxi.Engine;
import net.ME1312.Galaxi.Command.ConsoleCommandSender;
import net.ME1312.Galaxi.Galaxi;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Plugin.App;
import net.ME1312.Galaxi.Plugin.Plugin;
import net.ME1312.Galaxi.Plugin.PluginInfo;
/**
* GalaxiEngine Main Class
*/
public abstract class GalaxiEngine extends Galaxi {
private ConsoleCommandSender console = new ConsoleCommandSender() {};
/**
* Initialize the Galaxi Engine
*
* @see App @App
* @see Plugin @Plugin
* @param app Main class object of the app (annotated with @App/@Plugin)
* @return The GalaxiEngine
*/
public static GalaxiEngine init(Object app) throws Exception {
Util.nullpo(app);
if (instance == null) {
return Util.reflect(Class.forName("net.ME1312.Galaxi.Engine.Runtime.Engine").getDeclaredConstructor(PluginInfo.class), PluginInfo.load(app));
} else throw new IllegalStateException("Engine already initialized");
}
/**
* Initialize the Galaxi Engine
*
* @param app PluginInfo for the app
* @return The GalaxiEngine
*/
public static GalaxiEngine init(PluginInfo app) throws Exception {
Util.nullpo(app);
if (instance == null) {
return Util.reflect(Class.forName("net.ME1312.Galaxi.Engine.Runtime.Engine").getDeclaredConstructor(PluginInfo.class), app);
} else throw new IllegalStateException("Engine already initialized");
}
/**
* Get the GalaxiEngine
*
* @return The GalaxiEngine
*/
public static GalaxiEngine getInstance() {
return (GalaxiEngine) Galaxi.getInstance();
}
/**
* Start the GalaxiEngine
*/
public void start() {
start(null);
}
/**
* Start the GalaxiEngine
*
* @param callback Callback for when Galaxi is stopped
*/
public abstract void start(Runnable callback);
/**
* Stop the GalaxiEngine
*/
public void stop() {
stop(0);
}
/**
* Stop the GalaxiEngine
*
* @param code Exit Code
*/
public abstract void stop(int code);
/**
* Force stop the GalaxiEngine
*
* @param code Exit Code
*/
public abstract void terminate(int code);
/**
* Override the Console Sender
*
* @param sender Console Command Sender
*/
public void setConsole(ConsoleCommandSender sender) {
console = sender;
}
@Override
public ConsoleCommandSender getConsole() {
return console;
}
@Override
public abstract CommandParser getCommandProcessor();
@Override
public abstract CodeManager getPluginManager();
}