2017-04-01 22:31:57 +02:00
|
|
|
package net.ME1312.SubServers.Host.Network.Packet;
|
|
|
|
|
|
|
|
|
2017-05-30 21:38:51 +02:00
|
|
|
import net.ME1312.SubServers.Host.Executable.SubCreator;
|
|
|
|
import net.ME1312.SubServers.Host.Library.Config.YAMLConfig;
|
|
|
|
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
|
|
|
|
import net.ME1312.SubServers.Host.Library.UniversalFile;
|
2017-04-01 22:31:57 +02:00
|
|
|
import net.ME1312.SubServers.Host.Library.Version.Version;
|
|
|
|
import net.ME1312.SubServers.Host.Network.PacketIn;
|
2017-04-16 19:02:14 +02:00
|
|
|
import net.ME1312.SubServers.Host.ExHost;
|
2017-04-01 22:31:57 +02:00
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2017-05-30 21:38:51 +02:00
|
|
|
import java.io.File;
|
2017-04-01 22:31:57 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset Packet
|
|
|
|
*/
|
|
|
|
public class PacketInReset implements PacketIn {
|
2017-04-16 19:02:14 +02:00
|
|
|
private ExHost host;
|
2017-04-01 22:31:57 +02:00
|
|
|
|
2017-04-16 19:02:14 +02:00
|
|
|
public PacketInReset(ExHost host) {
|
2017-04-01 22:31:57 +02:00
|
|
|
this.host = host;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute(JSONObject data) {
|
|
|
|
if (data != null && data.keySet().contains("m")) {
|
|
|
|
List<String> subservers = new ArrayList<String>();
|
|
|
|
subservers.addAll(host.servers.keySet());
|
|
|
|
|
|
|
|
for (String server : subservers) {
|
|
|
|
host.servers.get(server).stop();
|
|
|
|
try {
|
|
|
|
host.servers.get(server).waitFor();
|
|
|
|
} catch (Exception e) {
|
|
|
|
host.log.error.println(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
subservers.clear();
|
|
|
|
host.servers.clear();
|
|
|
|
|
|
|
|
if (host.creator.isBusy()) {
|
|
|
|
host.creator.terminate();
|
|
|
|
try {
|
|
|
|
host.creator.waitFor();
|
|
|
|
} catch (Exception e) {
|
|
|
|
host.log.error.println(e);
|
|
|
|
}
|
|
|
|
}
|
2017-05-30 21:38:51 +02:00
|
|
|
host.templates.clear();
|
|
|
|
|
|
|
|
if (new UniversalFile(host.dir, "Templates").exists()) for (File file : new UniversalFile(host.dir, "Templates").listFiles()) {
|
|
|
|
try {
|
|
|
|
if (file.isDirectory()) {
|
|
|
|
YAMLSection config = (new UniversalFile(file, "template.yml").exists())?new YAMLConfig(new UniversalFile(file, "template.yml")).get().getSection("Template", new YAMLSection()):new YAMLSection();
|
|
|
|
SubCreator.ServerTemplate template = new SubCreator.ServerTemplate(file.getName(), config.getBoolean("Enabled", true), config.getRawString("Icon", "::NULL::"), file, config.getSection("Build", new YAMLSection()), config.getSection("Settings", new YAMLSection()));
|
|
|
|
host.templates.put(file.getName().toLowerCase(), template);
|
|
|
|
if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display"));
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
System.out.println("SubCreator > Couldn't load template: " + file.getName());
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2017-04-01 22:31:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Version getVersion() {
|
|
|
|
return new Version("2.11.0a");
|
|
|
|
}
|
|
|
|
}
|