2016-12-24 05:55:17 +01:00
|
|
|
package net.ME1312.SubServers.Bungee.Host.Internal;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2016-12-24 05:55:17 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Event.*;
|
2017-08-22 15:02:23 +02:00
|
|
|
import net.ME1312.SubServers.Bungee.Host.*;
|
2017-01-31 04:04:37 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
2017-04-24 18:28:16 +02:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Config.YAMLValue;
|
2016-12-24 05:55:17 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Container;
|
|
|
|
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
2017-01-21 17:49:37 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
2017-01-31 04:04:37 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.UniversalFile;
|
2017-01-30 21:22:36 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Util;
|
2017-01-31 04:04:37 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
|
|
|
import net.ME1312.SubServers.Bungee.SubPlugin;
|
2018-01-12 22:56:22 +01:00
|
|
|
import net.md_5.bungee.BungeeServerInfo;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2017-01-31 04:04:37 +01:00
|
|
|
import java.io.*;
|
2017-08-22 15:02:23 +02:00
|
|
|
import java.lang.reflect.Field;
|
2017-07-21 22:45:41 +02:00
|
|
|
import java.util.ArrayList;
|
2017-01-21 17:49:37 +01:00
|
|
|
import java.util.LinkedList;
|
2017-07-21 22:45:41 +02:00
|
|
|
import java.util.List;
|
2016-12-05 04:21:04 +01:00
|
|
|
import java.util.UUID;
|
2017-01-31 04:04:37 +01:00
|
|
|
import java.util.jar.JarFile;
|
2018-07-17 09:10:17 +02:00
|
|
|
import java.util.jar.JarInputStream;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2017-01-07 20:06:54 +01:00
|
|
|
/**
|
|
|
|
* Internal SubServer Class
|
|
|
|
*/
|
2017-08-27 20:37:25 +02:00
|
|
|
public class InternalSubServer extends SubServerContainer {
|
2016-12-05 04:21:04 +01:00
|
|
|
private InternalHost host;
|
|
|
|
private boolean enabled;
|
|
|
|
private Container<Boolean> log;
|
2017-01-01 20:34:46 +01:00
|
|
|
private String dir;
|
2016-12-05 04:21:04 +01:00
|
|
|
private File directory;
|
2019-01-04 22:51:58 +01:00
|
|
|
private String executable;
|
2016-12-05 04:21:04 +01:00
|
|
|
private String stopcmd;
|
2018-08-30 03:55:59 +02:00
|
|
|
private StopAction stopaction;
|
2017-01-21 17:49:37 +01:00
|
|
|
private LinkedList<LoggedCommand> history;
|
2016-12-05 04:21:04 +01:00
|
|
|
private Process process;
|
2017-01-09 20:37:57 +01:00
|
|
|
private InternalSubLogger logger;
|
2016-12-20 00:31:01 +01:00
|
|
|
private Thread thread;
|
2016-12-15 22:04:39 +01:00
|
|
|
private BufferedWriter command;
|
|
|
|
private boolean allowrestart;
|
2018-07-30 01:01:36 +02:00
|
|
|
private boolean lock;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2017-01-07 20:06:54 +01:00
|
|
|
/**
|
|
|
|
* Creates an Internal SubServer
|
|
|
|
*
|
|
|
|
* @param host Host
|
|
|
|
* @param name Name
|
|
|
|
* @param enabled Enabled Status
|
|
|
|
* @param port Port Number
|
|
|
|
* @param motd MOTD
|
|
|
|
* @param log Logging Status
|
|
|
|
* @param directory Directory
|
|
|
|
* @param executable Executable String
|
|
|
|
* @param stopcmd Stop Command
|
|
|
|
* @param hidden Hidden Status
|
|
|
|
* @param restricted Restricted Status
|
|
|
|
* @throws InvalidServerException
|
|
|
|
*/
|
2019-01-04 22:51:58 +01:00
|
|
|
public InternalSubServer(InternalHost host, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
|
2016-12-19 01:38:02 +01:00
|
|
|
super(host, name, port, motd, hidden, restricted);
|
2018-08-30 03:55:59 +02:00
|
|
|
if (Util.isNull(host, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted)) throw new NullPointerException();
|
2017-01-07 20:06:54 +01:00
|
|
|
this.host = host;
|
2016-12-05 04:21:04 +01:00
|
|
|
this.enabled = enabled;
|
|
|
|
this.log = new Container<Boolean>(log);
|
2017-01-01 20:34:46 +01:00
|
|
|
this.dir = directory;
|
2017-04-24 18:28:16 +02:00
|
|
|
this.directory = new File(host.getPath(), directory);
|
2016-12-05 04:21:04 +01:00
|
|
|
this.executable = executable;
|
|
|
|
this.stopcmd = stopcmd;
|
2018-08-30 03:55:59 +02:00
|
|
|
this.stopaction = StopAction.NONE;
|
2017-01-21 17:49:37 +01:00
|
|
|
this.history = new LinkedList<LoggedCommand>();
|
2016-12-05 04:21:04 +01:00
|
|
|
this.process = null;
|
2017-01-11 04:23:29 +01:00
|
|
|
this.logger = new InternalSubLogger(null, this, getName(), this.log, null);
|
2016-12-20 00:31:01 +01:00
|
|
|
this.thread = null;
|
2016-12-15 22:04:39 +01:00
|
|
|
this.command = null;
|
2017-01-31 04:04:37 +01:00
|
|
|
|
|
|
|
if (new UniversalFile(this.directory, "plugins:SubServers.Client.jar").exists()) {
|
|
|
|
try {
|
2018-07-17 09:10:17 +02:00
|
|
|
JarInputStream updated = new JarInputStream(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/client.jar"));
|
|
|
|
JarFile existing = new JarFile(new UniversalFile(this.directory, "plugins:SubServers.Client.jar"));
|
|
|
|
|
2018-07-27 21:36:51 +02:00
|
|
|
if (existing.getManifest().getMainAttributes().getValue("Implementation-Title") != null && existing.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && existing.getManifest().getMainAttributes().getValue("Specification-Title") != null &&
|
|
|
|
updated.getManifest().getMainAttributes().getValue("Implementation-Title") != null && updated.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && updated.getManifest().getMainAttributes().getValue("Specification-Title") != null) {
|
2018-07-17 09:10:17 +02:00
|
|
|
if (new Version(existing.getManifest().getMainAttributes().getValue("Specification-Title")).compareTo(new Version(updated.getManifest().getMainAttributes().getValue("Specification-Title"))) < 0) {
|
|
|
|
new UniversalFile(this.directory, "plugins:SubServers.Client.jar").delete();
|
|
|
|
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(this.directory, "plugins:SubServers.Client.jar").getPath());
|
|
|
|
}
|
2017-01-31 04:04:37 +01:00
|
|
|
}
|
2018-07-17 09:10:17 +02:00
|
|
|
existing.close();
|
|
|
|
updated.close();
|
2017-01-31 04:04:37 +01:00
|
|
|
} catch (Throwable e) {
|
2018-07-17 09:10:17 +02:00
|
|
|
System.out.println("Couldn't auto-update SubServers.Client.jar for " + name);
|
2018-07-23 05:44:20 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
} else if (new UniversalFile(this.directory, "mods:SubServers.Client.jar").exists()) {
|
|
|
|
try {
|
|
|
|
JarInputStream updated = new JarInputStream(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/client.jar"));
|
|
|
|
JarFile existing = new JarFile(new UniversalFile(this.directory, "mods:SubServers.Client.jar"));
|
|
|
|
|
2018-07-27 21:36:51 +02:00
|
|
|
if (existing.getManifest().getMainAttributes().getValue("Implementation-Title") != null && existing.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && existing.getManifest().getMainAttributes().getValue("Specification-Title") != null &&
|
|
|
|
updated.getManifest().getMainAttributes().getValue("Implementation-Title") != null && updated.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && updated.getManifest().getMainAttributes().getValue("Specification-Title") != null) {
|
2018-07-23 05:44:20 +02:00
|
|
|
if (new Version(existing.getManifest().getMainAttributes().getValue("Specification-Title")).compareTo(new Version(updated.getManifest().getMainAttributes().getValue("Specification-Title"))) < 0) {
|
|
|
|
new UniversalFile(this.directory, "mods:SubServers.Client.jar").delete();
|
|
|
|
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(this.directory, "mods:SubServers.Client.jar").getPath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
existing.close();
|
|
|
|
updated.close();
|
|
|
|
} catch (Throwable e) {
|
|
|
|
System.out.println("Couldn't auto-update SubServers.Client.jar for " + name);
|
2017-01-31 04:04:37 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 01:01:36 +02:00
|
|
|
this.lock = false;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void run() {
|
2017-01-06 21:44:34 +01:00
|
|
|
allowrestart = true;
|
|
|
|
try {
|
2019-01-04 22:51:58 +01:00
|
|
|
process = Runtime.getRuntime().exec(Executable.parse(host.getCreator().getBashDirectory(), executable), null, directory);
|
2017-01-06 21:44:34 +01:00
|
|
|
System.out.println("SubServers > Now starting " + getName());
|
2017-01-09 20:37:57 +01:00
|
|
|
logger.process = process;
|
|
|
|
logger.start();
|
2017-01-06 21:44:34 +01:00
|
|
|
command = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
|
2017-01-21 17:49:37 +01:00
|
|
|
for (LoggedCommand command : history) if (process.isAlive()) {
|
|
|
|
this.command.write(command.getCommand());
|
|
|
|
this.command.newLine();
|
|
|
|
this.command.flush();
|
|
|
|
}
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
if (process.isAlive()) process.waitFor();
|
2017-01-06 21:44:34 +01:00
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
allowrestart = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubStoppedEvent event = new SubStoppedEvent(this);
|
|
|
|
host.plugin.getPluginManager().callEvent(event);
|
|
|
|
System.out.println("SubServers > " + getName() + " has stopped");
|
|
|
|
process = null;
|
|
|
|
command = null;
|
2017-01-21 17:49:37 +01:00
|
|
|
history.clear();
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2018-08-30 03:55:59 +02:00
|
|
|
if (stopaction == StopAction.REMOVE_SERVER || stopaction == StopAction.DELETE_SERVER) {
|
2017-01-06 21:44:34 +01:00
|
|
|
try {
|
2018-08-30 03:55:59 +02:00
|
|
|
if (stopaction == StopAction.DELETE_SERVER) {
|
|
|
|
host.deleteSubServer(getName());
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
host.plugin.config.get().getSection("Servers").remove(getName());
|
|
|
|
host.plugin.config.save();
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
host.removeSubServer(getName());
|
|
|
|
}
|
2017-01-06 21:44:34 +01:00
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-08-30 03:55:59 +02:00
|
|
|
} else if (stopaction == StopAction.RESTART) {
|
|
|
|
if (allowrestart) {
|
2017-01-26 23:19:48 +01:00
|
|
|
new Thread(() -> {
|
|
|
|
try {
|
|
|
|
while (thread != null && thread.isAlive()) {
|
|
|
|
Thread.sleep(250);
|
|
|
|
}
|
|
|
|
start();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}).start();
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
2017-01-06 21:44:34 +01:00
|
|
|
}
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-12-19 01:38:02 +01:00
|
|
|
public boolean start(UUID player) {
|
2018-07-30 01:01:36 +02:00
|
|
|
if (!lock && isEnabled() && !(thread != null && thread.isAlive()) && getCurrentIncompatibilities().size() == 0) {
|
|
|
|
lock = true;
|
2016-12-15 22:04:39 +01:00
|
|
|
SubStartEvent event = new SubStartEvent(player, this);
|
2016-12-05 04:21:04 +01:00
|
|
|
host.plugin.getPluginManager().callEvent(event);
|
2018-07-30 01:01:36 +02:00
|
|
|
lock = false;
|
2016-12-05 04:21:04 +01:00
|
|
|
if (!event.isCancelled()) {
|
2017-01-21 17:49:37 +01:00
|
|
|
(thread = new Thread(this::run)).start();
|
2016-12-19 01:38:02 +01:00
|
|
|
return true;
|
|
|
|
} else return false;
|
|
|
|
} else return false;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-12-19 01:38:02 +01:00
|
|
|
public boolean stop(UUID player) {
|
2017-01-21 17:49:37 +01:00
|
|
|
if (thread != null && thread.isAlive()) {
|
2016-12-15 22:04:39 +01:00
|
|
|
SubStopEvent event = new SubStopEvent(player, this, false);
|
2016-12-05 04:21:04 +01:00
|
|
|
host.plugin.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
2016-12-15 22:04:39 +01:00
|
|
|
try {
|
2016-12-19 01:38:02 +01:00
|
|
|
allowrestart = false;
|
2017-01-21 17:49:37 +01:00
|
|
|
history.add(new LoggedCommand(player, stopcmd));
|
|
|
|
if (process != null && process.isAlive()) {
|
|
|
|
command.write(stopcmd);
|
|
|
|
command.newLine();
|
|
|
|
command.flush();
|
|
|
|
}
|
2016-12-19 01:38:02 +01:00
|
|
|
return true;
|
2016-12-15 22:04:39 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2016-12-19 01:38:02 +01:00
|
|
|
return false;
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
2016-12-19 01:38:02 +01:00
|
|
|
} else return false;
|
|
|
|
} else return false;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-12-19 01:38:02 +01:00
|
|
|
public boolean terminate(UUID player) {
|
2017-01-21 17:49:37 +01:00
|
|
|
if (thread != null && thread.isAlive()) {
|
2016-12-15 22:04:39 +01:00
|
|
|
SubStopEvent event = new SubStopEvent(player, this, true);
|
2016-12-05 04:21:04 +01:00
|
|
|
host.plugin.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
2016-12-19 01:38:02 +01:00
|
|
|
allowrestart = false;
|
2017-01-21 17:49:37 +01:00
|
|
|
if (process != null && process.isAlive()) process.destroyForcibly();
|
2016-12-19 01:38:02 +01:00
|
|
|
return true;
|
|
|
|
} else return false;
|
|
|
|
} else return false;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-12-19 01:38:02 +01:00
|
|
|
public boolean command(UUID player, String command) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(command)) throw new NullPointerException();
|
2017-01-21 17:49:37 +01:00
|
|
|
if (thread != null && thread.isAlive()) {
|
2016-12-15 22:04:39 +01:00
|
|
|
SubSendCommandEvent event = new SubSendCommandEvent(player, this, command);
|
2016-12-05 04:21:04 +01:00
|
|
|
host.plugin.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
2016-12-15 22:04:39 +01:00
|
|
|
try {
|
2016-12-19 01:38:02 +01:00
|
|
|
if (event.getCommand().equalsIgnoreCase(stopcmd)) allowrestart = false;
|
2017-01-21 17:49:37 +01:00
|
|
|
history.add(new LoggedCommand(player, event.getCommand()));
|
|
|
|
if (process != null && process.isAlive()) {
|
|
|
|
this.command.write(event.getCommand());
|
|
|
|
this.command.newLine();
|
|
|
|
this.command.flush();
|
|
|
|
}
|
2016-12-19 01:38:02 +01:00
|
|
|
return true;
|
2016-12-15 22:04:39 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
2016-12-19 01:38:02 +01:00
|
|
|
return false;
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
2016-12-19 01:38:02 +01:00
|
|
|
} else return false;
|
|
|
|
} else return false;
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
|
|
|
|
2017-08-26 07:19:59 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2017-04-24 18:28:16 +02:00
|
|
|
public int edit(UUID player, YAMLSection edit) {
|
|
|
|
int c = 0;
|
|
|
|
boolean state = isRunning();
|
|
|
|
SubServer forward = null;
|
|
|
|
YAMLSection pending = edit.clone();
|
2018-08-30 03:55:59 +02:00
|
|
|
for (String key : edit.getKeys()) {
|
2017-04-24 18:28:16 +02:00
|
|
|
pending.remove(key);
|
|
|
|
YAMLValue value = edit.get(key);
|
2017-08-22 15:02:23 +02:00
|
|
|
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, YAMLValue>(key, value), true);
|
2017-04-24 18:28:16 +02:00
|
|
|
host.plugin.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
try {
|
|
|
|
switch (key) {
|
|
|
|
case "name":
|
|
|
|
if (value.isString() && host.removeSubServer(player, getName())) {
|
2018-08-30 03:55:59 +02:00
|
|
|
SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
2017-04-24 18:28:16 +02:00
|
|
|
if (server != null) {
|
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
YAMLSection config = this.host.plugin.config.get().getSection("Servers").getSection(getName());
|
|
|
|
this.host.plugin.config.get().getSection("Servers").remove(getName());
|
|
|
|
this.host.plugin.config.get().getSection("Servers").set(server.getName(), config);
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
forward = server;
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "display":
|
|
|
|
if (value.isString()) {
|
2017-08-27 20:37:25 +02:00
|
|
|
Field f = ServerContainer.class.getDeclaredField("nick");
|
2017-08-22 15:02:23 +02:00
|
|
|
f.setAccessible(true);
|
|
|
|
if (value == null || value.asString().length() == 0 || getName().equals(value)) {
|
|
|
|
f.set(this, null);
|
|
|
|
} else {
|
|
|
|
f.set(this, value.asString());
|
|
|
|
}
|
|
|
|
f.setAccessible(false);
|
2017-12-09 09:43:29 +01:00
|
|
|
logger.name = getDisplayName();
|
2017-04-24 18:28:16 +02:00
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
if (getName().equals(getDisplayName())) {
|
2017-12-09 09:43:29 +01:00
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).remove("Display");
|
2017-04-24 18:28:16 +02:00
|
|
|
} else {
|
2017-12-09 09:43:29 +01:00
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Display", getDisplayName());
|
2017-04-24 18:28:16 +02:00
|
|
|
}
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "enabled":
|
|
|
|
if (value.isBoolean()) {
|
2017-08-22 15:02:23 +02:00
|
|
|
enabled = value.asBoolean();
|
2017-04-24 18:28:16 +02:00
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Enabled", isEnabled());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
2017-08-26 07:19:59 +02:00
|
|
|
case "group":
|
|
|
|
if (value.isList()) {
|
2017-12-09 09:43:29 +01:00
|
|
|
Field f = ServerContainer.class.getDeclaredField("groups");
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.set(this, value.asStringList());
|
|
|
|
f.setAccessible(false);
|
2017-08-26 07:19:59 +02:00
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Group", value.asStringList());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
2017-04-24 18:28:16 +02:00
|
|
|
case "host":
|
|
|
|
if (value.isString() && host.removeSubServer(player, getName())) {
|
2018-08-30 03:55:59 +02:00
|
|
|
SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
2017-04-24 18:28:16 +02:00
|
|
|
if (server != null) {
|
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Host", server.getHost().getName());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
forward = server;
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "port":
|
2017-12-22 00:37:39 +01:00
|
|
|
if (value.isNumber() && host.removeSubServer(player, getName())) {
|
2018-08-30 03:55:59 +02:00
|
|
|
SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
2017-04-24 18:28:16 +02:00
|
|
|
if (server != null) {
|
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Port", server.getAddress().getPort());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
forward = server;
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "motd":
|
|
|
|
if (value.isString()) {
|
2018-01-12 22:56:22 +01:00
|
|
|
Field f = BungeeServerInfo.class.getDeclaredField("motd");
|
2017-08-22 15:02:23 +02:00
|
|
|
f.setAccessible(true);
|
|
|
|
f.set(this, value.asColoredString('&'));
|
|
|
|
f.setAccessible(false);
|
2017-04-24 18:28:16 +02:00
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Motd", value.asString());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "log":
|
|
|
|
if (value.isBoolean()) {
|
2017-08-22 15:02:23 +02:00
|
|
|
log.set(value.asBoolean());
|
2017-04-24 18:28:16 +02:00
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Log", isLogging());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "dir":
|
|
|
|
if (value.isString()) {
|
|
|
|
if (isRunning()) {
|
|
|
|
stop(player);
|
|
|
|
waitFor();
|
|
|
|
}
|
2017-12-14 01:04:58 +01:00
|
|
|
dir = value.asRawString();
|
2017-04-24 18:28:16 +02:00
|
|
|
directory = new File(getHost().getPath(), value.asRawString());
|
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Directory", getPath());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "exec":
|
|
|
|
if (value.isString()) {
|
|
|
|
if (isRunning()) {
|
|
|
|
stop(player);
|
|
|
|
waitFor();
|
|
|
|
}
|
2019-01-04 22:51:58 +01:00
|
|
|
executable = value.asRawString();
|
2017-04-24 18:28:16 +02:00
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Executable", value.asRawString());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "stop-cmd":
|
|
|
|
if (value.isString()) {
|
2017-08-22 15:02:23 +02:00
|
|
|
stopcmd = value.asRawString();
|
2017-04-24 18:28:16 +02:00
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Stop-Command", getStopCommand());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
2018-08-30 03:55:59 +02:00
|
|
|
case "stop-action":
|
|
|
|
if (value.isString()) {
|
|
|
|
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
|
|
|
if (action != null) {
|
|
|
|
stopaction = action;
|
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Stop-Action", getStopAction().toString());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-04-24 18:28:16 +02:00
|
|
|
case "state":
|
|
|
|
if (value.isBoolean()) {
|
|
|
|
state = value.asBoolean();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "auto-run":
|
|
|
|
if (value.isBoolean()) {
|
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Run-On-Launch", value.asBoolean());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
2017-12-09 09:43:29 +01:00
|
|
|
case "incompatible":
|
|
|
|
if (value.isList()) {
|
|
|
|
for (String oname : value.asStringList()) {
|
|
|
|
SubServer oserver = host.plugin.api.getSubServer(oname);
|
|
|
|
if (oserver != null && isCompatible(oserver)) toggleCompatibility(oserver);
|
|
|
|
}
|
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Incompatible", value.asStringList());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
2017-04-24 18:28:16 +02:00
|
|
|
case "restricted":
|
|
|
|
if (value.isBoolean()) {
|
2018-01-12 22:56:22 +01:00
|
|
|
Field f = BungeeServerInfo.class.getDeclaredField("restricted");
|
2017-08-22 15:02:23 +02:00
|
|
|
f.setAccessible(true);
|
|
|
|
f.set(this, value.asBoolean());
|
|
|
|
f.setAccessible(false);
|
2017-04-24 18:28:16 +02:00
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Restricted", isRestricted());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "hidden":
|
|
|
|
if (value.isBoolean()) {
|
2017-08-27 20:37:25 +02:00
|
|
|
Field f = ServerContainer.class.getDeclaredField("hidden");
|
2017-08-22 15:02:23 +02:00
|
|
|
f.setAccessible(true);
|
|
|
|
f.set(this, value.asBoolean());
|
|
|
|
f.setAccessible(false);
|
2017-04-24 18:28:16 +02:00
|
|
|
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
|
|
|
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Hidden", isHidden());
|
|
|
|
this.host.plugin.config.save();
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (forward != null) {
|
2018-08-30 03:55:59 +02:00
|
|
|
forward.setStopAction(getStopAction());
|
2017-12-09 09:43:29 +01:00
|
|
|
if (!getName().equals(getDisplayName())) forward.setDisplayName(getDisplayName());
|
|
|
|
List<String> groups = new ArrayList<String>();
|
|
|
|
groups.addAll(getGroups());
|
|
|
|
for (String group : groups) {
|
|
|
|
removeGroup(group);
|
|
|
|
forward.addGroup(group);
|
|
|
|
}
|
|
|
|
for (SubServer server : getIncompatibilities()) {
|
|
|
|
toggleCompatibility(server);
|
|
|
|
forward.toggleCompatibility(server);
|
|
|
|
}
|
|
|
|
for (String extra : getExtra().getKeys()) forward.addExtra(extra, getExtra(extra));
|
|
|
|
|
2017-04-24 18:28:16 +02:00
|
|
|
if (state) pending.set("state", true);
|
|
|
|
c += forward.edit(player, pending);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isRunning() && forward == null && state) start(player);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2016-12-05 04:21:04 +01:00
|
|
|
@Override
|
|
|
|
public void waitFor() throws InterruptedException {
|
2016-12-20 00:31:01 +01:00
|
|
|
while (thread != null && thread.isAlive()) {
|
|
|
|
Thread.sleep(250);
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isRunning() {
|
|
|
|
return process != null && process.isAlive();
|
|
|
|
}
|
|
|
|
|
2017-01-26 23:19:48 +01:00
|
|
|
@Override
|
|
|
|
public void setDisplayName(String value) {
|
|
|
|
super.setDisplayName(value);
|
|
|
|
logger.name = getDisplayName();
|
|
|
|
}
|
|
|
|
|
2016-12-05 04:21:04 +01:00
|
|
|
@Override
|
|
|
|
public Host getHost() {
|
|
|
|
return host;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled() {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setEnabled(boolean value) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(value)) throw new NullPointerException();
|
2018-08-30 03:55:59 +02:00
|
|
|
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("enabled", value), false));
|
2016-12-05 04:21:04 +01:00
|
|
|
enabled = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLogging() {
|
|
|
|
return log.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setLogging(boolean value) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(value)) throw new NullPointerException();
|
2018-08-30 03:55:59 +02:00
|
|
|
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("log", value), false));
|
2016-12-05 04:21:04 +01:00
|
|
|
log.set(value);
|
|
|
|
}
|
|
|
|
|
2017-01-09 20:37:57 +01:00
|
|
|
@Override
|
|
|
|
public SubLogger getLogger() {
|
|
|
|
return logger;
|
|
|
|
}
|
|
|
|
|
2017-01-21 17:49:37 +01:00
|
|
|
@Override
|
|
|
|
public LinkedList<LoggedCommand> getCommandHistory() {
|
|
|
|
return new LinkedList<LoggedCommand>(history);
|
|
|
|
}
|
|
|
|
|
2017-01-01 20:34:46 +01:00
|
|
|
@Override
|
2017-04-24 18:28:16 +02:00
|
|
|
public String getPath() {
|
2017-01-01 20:34:46 +01:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2017-04-24 18:28:16 +02:00
|
|
|
@Override
|
2019-01-04 22:51:58 +01:00
|
|
|
public String getExecutable() {
|
2017-04-24 18:28:16 +02:00
|
|
|
return executable;
|
|
|
|
}
|
|
|
|
|
2016-12-05 04:21:04 +01:00
|
|
|
@Override
|
|
|
|
public String getStopCommand() {
|
|
|
|
return stopcmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setStopCommand(String value) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(value)) throw new NullPointerException();
|
2018-08-30 03:55:59 +02:00
|
|
|
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("stop-cmd", value), false));
|
2016-12-05 04:21:04 +01:00
|
|
|
stopcmd = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-30 03:55:59 +02:00
|
|
|
public StopAction getStopAction() {
|
|
|
|
return stopaction;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-30 03:55:59 +02:00
|
|
|
public void setStopAction(StopAction action) {
|
|
|
|
if (Util.isNull(action)) throw new NullPointerException();
|
|
|
|
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("stop-action", action), false));
|
|
|
|
stopaction = action;
|
2017-01-21 17:49:37 +01:00
|
|
|
}
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|