/
SubServer.java
336 lines (293 loc) · 6.86 KB
/
SubServer.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
package net.ME1312.SubServers.Bungee.Host;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import java.util.*;
/**
* SubServer Interface
*/
public interface SubServer extends Server {
/**
* SubServer Stop Action Class
*/
enum StopAction {
NONE,
RESTART,
REMOVE_SERVER,
RECYCLE_SERVER,
DELETE_SERVER;
@Override
public String toString() {
return super.toString().substring(0, 1).toUpperCase()+super.toString().substring(1).toLowerCase().replace('_', ' ');
}
}
/**
* Command Storage Class
*/
class LoggedCommand {
private Date date;
private UUID sender;
private String command;
/**
* Store a Command
*
* @param command Command
*/
public LoggedCommand(String command) {
if (Util.isNull(command)) throw new NullPointerException();
this.date = Calendar.getInstance().getTime();
this.sender = null;
this.command = command;
}
/**
* Store a Command
*
* @param sender Command Sender (null for CONSOLE)
* @param command Command
*/
public LoggedCommand(UUID sender, String command) {
if (Util.isNull(command)) throw new NullPointerException();
this.date = Calendar.getInstance().getTime();
this.sender = sender;
this.command = command;
}
/**
* Store a Command
*
* @param date Date
* @param sender Command Sender (null for CONSOLE)
* @param command Command
*/
public LoggedCommand(Date date, UUID sender, String command) {
if (Util.isNull(date, command)) throw new NullPointerException();
this.date = date;
this.sender = sender;
this.command = command;
}
/**
* Get the date this command was logged
*
* @return Date
*/
public Date getDate() {
return date;
}
/**
* Get the command sender
*
* @return Command Sender (null if CONSOLE)
*/
public UUID getSender() {
return sender;
}
/**
* Get the command
*
* @return Command
*/
public String getCommand() {
return command;
}
}
/**
* Starts the Server
*
* @param player Player who Started
* @return Success Status
*/
boolean start(UUID player);
/**
* Starts the Server
*
* @return Success Status
*/
boolean start();
/**
* Stops the Server
*
* @param player Player who Stopped
* @return Success Status
*/
boolean stop(UUID player);
/**
* Stops the Server
*
* @return Success Status
*/
boolean stop();
/**
* Terminates the Server
*
* @param player Player who Terminated
* @return Success Status
*/
boolean terminate(UUID player);
/**
* Terminates the Server
*
* @return Success Status
*/
boolean terminate();
/**
* Commands the Server
*
* @param player Player who Commanded
* @param command Command to Send
* @return Success Status
*/
boolean command(UUID player, String command);
/**
* Commands the Server
*
* @param command Command to Send
* @return Success Status
*/
boolean command(String command);
/**
* Edits the Server
*
* @param player Player Editing
* @param edit Edits
* @return Success Status
*/
default int edit(UUID player, ObjectMap<String> edit) {
return -1;
}
/**
* Edits the Server
*
* @param edit Edits
* @return Success Status
*/
default int edit(ObjectMap<String> edit) {
return -1;
}
/**
* Waits for the Server to Stop
*
* @throws InterruptedException
*/
void waitFor() throws InterruptedException;
/**
* If the Server is Running
*
* @return Running Status
*/
boolean isRunning();
/**
* Grabs the Host of the Server
*
* @return The Host
*/
Host getHost();
/**
* If the Server is Enabled
*
* @return Enabled Status
*/
boolean isEnabled();
/**
* Set if the Server is Enabled
*
* @param value Value
*/
void setEnabled(boolean value);
/**
* If the Server is accepting requests to edit()
*
* @see #edit(ObjectMap<String>)
* @see #edit(UUID, ObjectMap<String>)
* @return Edit Status
*/
default boolean isEditable() {
return edit(new ObjectMap<String>()) >= 0;
}
/**
* If the Server is Logging
*
* @return Logging Status
*/
boolean isLogging();
/**
* Set if the Server is Logging
*
* @param value Value
*/
void setLogging(boolean value);
/**
* Get Process Logger
*/
SubLogger getLogger();
/**
* Gets all the commands that were sent to this Server successfully
*
* @return Command History
*/
LinkedList<LoggedCommand> getCommandHistory();
/**
* Get the Server Directory Path
*
* @return Server Directory Path
*/
String getPath();
/**
* Get the Full Server Directory Path
*
* @return Full Server Directory Path
*/
String getFullPath();
/**
* Get the Server's Executable String
*
* @return Executable String
*/
String getExecutable();
/**
* Grab the Command to Stop the Server
*
* @return Stop Command
*/
String getStopCommand();
/**
* Set the Command that Stops the Server
*
* @param value Value
*/
void setStopCommand(String value);
/**
* Get the action the Server will take when it stops
*
* @return Stop Action
*/
StopAction getStopAction();
/**
* Set the action the Server will take when it stops
*
* @param action Stop Action
*/
void setStopAction(StopAction action);
/**
* Toggles compatibility with other Servers
*
* @param server SubServers to toggle
*/
void toggleCompatibility(SubServer... server);
/**
* Checks if a Server is compatible
*
* @param server Server to check
* @return Compatible Status
*/
boolean isCompatible(SubServer server);
/**
* Get all listed incompatibilities for this Server
*
* @return Incompatibility List
*/
List<SubServer> getIncompatibilities();
/**
* Get incompatibility issues this server currently has
*
* @return Current Incompatibility List
*/
List<SubServer> getCurrentIncompatibilities();
}