SubServers Release v2.11.2a

This commit is contained in:
ME1312 2016-12-27 19:15:36 -05:00
parent 83415cb873
commit 60fc38b5fb
9 changed files with 106 additions and 42 deletions

Binary file not shown.

View File

@ -4,11 +4,13 @@ import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
import net.ME1312.SubServers.Bungee.Host.Executable; import net.ME1312.SubServers.Bungee.Host.Executable;
import net.ME1312.SubServers.Bungee.Host.Host; import net.ME1312.SubServers.Bungee.Host.Host;
import net.ME1312.SubServers.Bungee.Host.SubCreator; import net.ME1312.SubServers.Bungee.Host.SubCreator;
import net.ME1312.SubServers.Bungee.Library.Config.YAMLConfig;
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection; import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
import net.ME1312.SubServers.Bungee.Library.Container; import net.ME1312.SubServers.Bungee.Library.Container;
import net.ME1312.SubServers.Bungee.Library.UniversalFile; import net.ME1312.SubServers.Bungee.Library.UniversalFile;
import net.ME1312.SubServers.Bungee.Library.Util; import net.ME1312.SubServers.Bungee.Library.Util;
import net.ME1312.SubServers.Bungee.Library.Version.Version; import net.ME1312.SubServers.Bungee.Library.Version.Version;
import net.ME1312.SubServers.Bungee.SubPlugin;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@ -27,6 +29,7 @@ import java.util.UUID;
public class InternalSubCreator extends SubCreator { public class InternalSubCreator extends SubCreator {
private InternalHost host; private InternalHost host;
private String gitBash; private String gitBash;
private Process process = null;
private Thread thread = null; private Thread thread = null;
public InternalSubCreator(Host host, String gitBash) { public InternalSubCreator(Host host, String gitBash) {
@ -370,7 +373,15 @@ public class InternalSubCreator extends SubCreator {
try { try {
GenerateSpigotYAML(dir); GenerateSpigotYAML(dir);
GenerateProperties(dir, port); GenerateProperties(dir, port);
} catch (IOException e) { new UniversalFile(dir, "plugins:SubServers").mkdirs();
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/bukkit.jar", new UniversalFile(dir, "plugins:SubServers.Client.jar").getPath());
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/bukkit.yml", new UniversalFile(dir, "plugins:Subservers:config.yml").getPath());
YAMLConfig config = new YAMLConfig(new UniversalFile(dir, "plugins:Subservers:config.yml"));
config.get().getSection("Settings").getSection("SubData").set("Name", name);
config.get().getSection("Settings").getSection("SubData").set("Address", host.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Address"));
config.get().getSection("Settings").getSection("SubData").set("Password", host.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"));
config.save();
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -426,7 +437,7 @@ public class InternalSubCreator extends SubCreator {
OutputStream output = null; OutputStream output = null;
try { try {
input = new FileInputStream(new UniversalFile(host.plugin.dir, "SubServers:build.sh")); input = new FileInputStream(new UniversalFile(host.plugin.dir, "SubServers:build.sh"));
output = new FileOutputStream(new File(dir, "build-subserver.sh")); output = new FileOutputStream(new File(dir, "build.sh"));
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int bytesRead; int bytesRead;
while ((bytesRead = input.read(buf)) > 0) { while ((bytesRead = input.read(buf)) > 0) {
@ -439,39 +450,39 @@ public class InternalSubCreator extends SubCreator {
output.close(); output.close();
} }
if (!(new File(dir, "build-subserver.sh").exists())) { if (!(new File(dir, "build.sh").exists())) {
System.out.println("SubCreator > Problem Copying build-subserver.sh!"); System.out.println(host.getName() + "/Creator > Problem Copying build.sh!");
} else { } else {
File gitBash = new File(this.gitBash, "bin" + File.separatorChar + "bash.exe"); File gitBash = new File(this.gitBash, "bin" + File.separatorChar + "bash.exe");
if (!(System.getProperty("os.name").toLowerCase().indexOf("win") >= 0)) { if (!(System.getProperty("os.name").toLowerCase().indexOf("win") >= 0)) {
Process process1 = Runtime.getRuntime().exec("chmod +x build-subserver.sh", null, dir); Process process = Runtime.getRuntime().exec("chmod +x build.sh", null, dir);
try { try {
process1.waitFor(); process.waitFor();
Thread.sleep(500); Thread.sleep(500);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (process1.exitValue() != 0) { if (process.exitValue() != 0) {
System.out.println("SubCreator > Problem Setting Executable Permissions for build-subserver.sh"); System.out.println(host.getName() + "/Creator > Problem Setting Executable Permissions for build.sh");
System.out.println("SubCreator > This may cause errors in the Build Process"); System.out.println(host.getName() + "/Creator > This may cause errors in the Build Process");
} }
} }
Process process2 = Runtime.getRuntime().exec((System.getProperty("os.name").toLowerCase().indexOf("win") >= 0)? this.process = Runtime.getRuntime().exec((System.getProperty("os.name").toLowerCase().indexOf("win") >= 0)?
"\"" + gitBash + "\" --login -i -c \"bash build-subserver.sh " + version.toString() + " " + type.toString().toLowerCase() + "\"" "\"" + gitBash + "\" --login -i -c \"bash build.sh " + version.toString() + " " + type.toString().toLowerCase() + "\""
:("bash build-subserver.sh " + version.toString() + " " + type.toString().toLowerCase() + " " + System.getProperty("user.home")), null, dir); :("bash build.sh " + version.toString() + " " + type.toString().toLowerCase() + " " + System.getProperty("user.home")), null, dir);
InternalSubLogger read = new InternalSubLogger(process2.getInputStream(), host.getName() + "/Creator", new Container<Boolean>(host.plugin.config.get().getSection("Settings").getBoolean("Log-Creator")), new File(dir, "SubCreator-" + type.toString() + "-" + version.toString().replace("::", "@") + ".log")); InternalSubLogger read = new InternalSubLogger(this.process.getInputStream(), host.getName() + "/Creator", new Container<Boolean>(host.plugin.config.get().getSection("Settings").getBoolean("Log-Creator")), new File(dir, "SubCreator-" + type.toString() + "-" + version.toString().replace("::", "@") + ".log"));
read.start(); read.start();
try { try {
process2.waitFor(); this.process.waitFor();
Thread.sleep(500); Thread.sleep(500);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (process2.exitValue() == 0) { if (this.process.exitValue() == 0) {
if (host.plugin.exServers.keySet().contains(name.toLowerCase())) host.plugin.exServers.remove(name.toLowerCase()); if (host.plugin.exServers.keySet().contains(name.toLowerCase())) host.plugin.exServers.remove(name.toLowerCase());
host.addSubServer(player, name, true, port, "&aThis is a SubServer", true, new UniversalFile(".:" + name).getPath(), exec, "stop", true, false, false, false, false); host.addSubServer(player, name, true, port, "&aThis is a SubServer", true, "." + File.separatorChar + name, exec, "stop", true, false, false, false, false);
YAMLSection server = new YAMLSection(); YAMLSection server = new YAMLSection();
server.set("Enabled", true); server.set("Enabled", true);
@ -479,7 +490,7 @@ public class InternalSubCreator extends SubCreator {
server.set("Port", port); server.set("Port", port);
server.set("Motd", "&aThis is a SubServer"); server.set("Motd", "&aThis is a SubServer");
server.set("Log", true); server.set("Log", true);
server.set("Directory", new UniversalFile(".:" + name)); server.set("Directory", "." + File.separatorChar + name);
server.set("Executable", exec.toString()); server.set("Executable", exec.toString());
server.set("Stop-Command", "stop"); server.set("Stop-Command", "stop");
server.set("Run-On-Launch", false); server.set("Run-On-Launch", false);
@ -490,7 +501,7 @@ public class InternalSubCreator extends SubCreator {
host.plugin.config.save(); host.plugin.config.save();
} else { } else {
System.out.println("SubCreator > build-subserver.sh exited with an errors. Please try again."); System.out.println(host.getName() + "/Creator build.sh exited with an errors. Please try again.");
} }
} }
} catch (IOException e) { } catch (IOException e) {
@ -512,6 +523,15 @@ public class InternalSubCreator extends SubCreator {
} else return false; } else return false;
} }
@Override
public void terminate() {
if (process != null && this.process.isAlive()) {
process.destroyForcibly();
} else if (thread != null && this.thread.isAlive()) {
thread.interrupt();
}
}
@Override @Override
public void waitFor() throws InterruptedException { public void waitFor() throws InterruptedException {
while (thread != null && thread.isAlive()) { while (thread != null && thread.isAlive()) {

View File

@ -16,16 +16,63 @@ public abstract class SubCreator {
SPONGE, SPONGE,
} }
/**
* Create a SubServer
*
* @param player Player Creating
* @param name Server Name
* @param type Server Type
* @param version Server Version
* @param memory Server Memory Amount (in MB)
* @param port Server Port Number
* @return Success Status
*/
public abstract boolean create(UUID player, String name, ServerType type, Version version, int memory, int port); public abstract boolean create(UUID player, String name, ServerType type, Version version, int memory, int port);
/**
* Create a SubServer
*
* @param name Server Name
* @param type Server Type
* @param version Server Version
* @param memory Server Memory Amount (in MB)
* @param port Server Port Number
* @return Success Status
*/
public boolean create(String name, ServerType type, Version version, int memory, int port) { public boolean create(String name, ServerType type, Version version, int memory, int port) {
return create(null, name, type, version, memory, port); return create(null, name, type, version, memory, port);
} }
/**
* Terminate SubCreator
*/
public abstract void terminate();
/**
* Wait for SubCreator to Finish
*
* @throws InterruptedException
*/
public abstract void waitFor() throws InterruptedException; public abstract void waitFor() throws InterruptedException;
/**
* Gets the host this creator belongs to
*
* @return Host
*/
public abstract Host getHost(); public abstract Host getHost();
/**
* Gets the Git Bash install directory
*
* @return Git Bash Directory
*/
public abstract String getGitBashDirectory(); public abstract String getGitBashDirectory();
/**
* Gets the status of SubCreator
*
* @return SubCreator Status
*/
public abstract boolean isBusy(); public abstract boolean isBusy();
} }

View File

@ -7,13 +7,13 @@
if [ -z "$1" ] if [ -z "$1" ]
then then
echo ERROR: No Build Version Supplied echo ERROR: No Build Version Supplied
rm -Rf build-subserver.sh rm -Rf $0
exit 1 exit 1
fi fi
if [ -z "$2" ] if [ -z "$2" ]
then then
echo ERROR: No Server Software Supplied echo ERROR: No Server Software Supplied
rm -Rf build-subserver.sh rm -Rf $0
exit 1 exit 1
fi fi
echo ---------- SERVER BUILD START ---------- echo ---------- SERVER BUILD START ----------
@ -25,7 +25,7 @@ if [ $2 == bukkit ] || [ $2 == spigot ]
echo Downloaded Buildtools! echo Downloaded Buildtools!
else else
echo ERROR: Failed Downloading Buildtools. Is SpigotMC.org down? echo ERROR: Failed Downloading Buildtools. Is SpigotMC.org down?
rm -Rf build-subserver.sh rm -Rf $0
exit 3 exit 3
fi fi
if [ -d "Buildtools" ] if [ -d "Buildtools" ]
@ -55,13 +55,13 @@ if [ $2 == bukkit ] || [ $2 == spigot ]
rm -Rf BuildTools.jar rm -Rf BuildTools.jar
rm -Rf Buildtools rm -Rf Buildtools
echo ---------- END SERVER BUILD ---------- echo ---------- END SERVER BUILD ----------
rm -Rf build-subserver.sh rm -Rf $0
exit 0 exit 0
else else
echo ERROR: Buildtools exited with an error. Please try again echo ERROR: Buildtools exited with an error. Please try again
rm -Rf BuildTools.jar rm -Rf BuildTools.jar
rm -Rf Buildtools rm -Rf Buildtools
rm -Rf build-subserver.sh rm -Rf $0
exit 4 exit 4
fi fi
else else
@ -90,24 +90,24 @@ else
echo Cleaning Up... echo Cleaning Up...
rm -Rf Buildtools rm -Rf Buildtools
echo ---------- END SERVER BUILD ---------- echo ---------- END SERVER BUILD ----------
rm -Rf build-subserver.sh rm -Rf $0
exit 0 exit 0
else else
echo ERROR: Failed Applying Patch. echo ERROR: Failed Applying Patch.
rm -Rf Buildtools rm -Rf Buildtools
rm -Rf build-subserver.sh rm -Rf $0
exit 5 exit 5
fi fi
else else
echo ERROR: Failed Downloading Patch. Is Github.com down? echo ERROR: Failed Downloading Patch. Is Github.com down?
rm -Rf Buildtools rm -Rf Buildtools
rm -Rf build-subserver.sh rm -Rf $0
exit 4 exit 4
fi fi
else else
echo ERROR: Failed Downloading Jarfile. Is Minecraft.net down? echo ERROR: Failed Downloading Jarfile. Is Minecraft.net down?
rm -Rf Buildtools rm -Rf Buildtools
rm -Rf build-subserver.sh rm -Rf $0
exit 3 exit 3
fi fi
else else
@ -129,26 +129,26 @@ else
rm -Rf forge-${version[0]}-installer.jar.log rm -Rf forge-${version[0]}-installer.jar.log
mv -f forge-${version[0]}-universal.jar Forge.jar mv -f forge-${version[0]}-universal.jar Forge.jar
echo ---------- END SERVER BUILD ---------- echo ---------- END SERVER BUILD ----------
rm -Rf build-subserver.sh rm -Rf $0
exit 0 exit 0
else else
echo ERROR: Failed Downloading Jarfile. Is MinecraftForge.net down? echo ERROR: Failed Downloading Jarfile. Is MinecraftForge.net down?
rm -Rf forge-${version[0]}-installer.jar rm -Rf forge-${version[0]}-installer.jar
rm -Rf forge-${version[0]}-installer.jar.log rm -Rf forge-${version[0]}-installer.jar.log
rm -Rf forge-${version[0]}-universal.jar rm -Rf forge-${version[0]}-universal.jar
rm -Rf build-subserver.sh rm -Rf $0
exit 5 exit 5
fi fi
else else
echo ERROR: Failed Installing Forge. echo ERROR: Failed Installing Forge.
rm -Rf forge-${version[0]}-installer.jar rm -Rf forge-${version[0]}-installer.jar
rm -Rf forge-${version[0]}-installer.jar.log rm -Rf forge-${version[0]}-installer.jar.log
rm -Rf build-subserver.sh rm -Rf $0
exit 4 exit 4
fi fi
else else
echo ERROR: Failed Downloading Jarfile. Is MinecraftForge.net down? echo ERROR: Failed Downloading Jarfile. Is MinecraftForge.net down?
rm -Rf build-subserver.sh rm -Rf $0
exit 3 exit 3
fi fi
fi fi

View File

@ -32,7 +32,7 @@ public class PacketAuthorization implements PacketIn, PacketOut {
@Override @Override
public void execute(Client client, JSONObject data) { public void execute(Client client, JSONObject data) {
try { try {
if (data.getString("password").equals(plugin.config.get().getSection("Settings").getSection("SubData").getString("Password"))) { if (data.getString("password").equals(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"))) {
client.authorize(); client.authorize();
client.sendPacket(new PacketAuthorization(0, "Successfully Logged in")); client.sendPacket(new PacketAuthorization(0, "Successfully Logged in"));
} else { } else {

View File

@ -37,7 +37,7 @@ public final class SubPlugin extends BungeeCord {
public HashMap<String, String> exLang = new HashMap<String, String>(); public HashMap<String, String> exLang = new HashMap<String, String>();
public SubDataServer subdata = null; public SubDataServer subdata = null;
public final Version version = new Version("2.11.2a"); public final Version version = new Version("2.11.2a");
protected Version bversion = new Version(5); protected Version bversion = null;
protected boolean running = false; protected boolean running = false;
public final SubAPI api = new SubAPI(this); public final SubAPI api = new SubAPI(this);
@ -237,6 +237,10 @@ public final class SubPlugin extends BungeeCord {
this.hosts.get(host).removeSubServer(server); this.hosts.get(host).removeSubServer(server);
} }
subservers.clear(); subservers.clear();
if (this.hosts.get(host).getCreator().isBusy()) {
this.hosts.get(host).getCreator().terminate();
this.hosts.get(host).getCreator().waitFor();
}
this.hosts.remove(host); this.hosts.remove(host);
} }
hosts.clear(); hosts.clear();

View File

@ -22,7 +22,7 @@ public final class SubPlugin extends JavaPlugin {
public UIListener gui = null; public UIListener gui = null;
public Version version; public Version version;
protected Version bversion = new Version(5); protected Version bversion = null;
//public final SubAPI api = new SubAPI(this); //public final SubAPI api = new SubAPI(this);
@ -35,7 +35,7 @@ public final class SubPlugin extends JavaPlugin {
if (!(new UniversalFile(getDataFolder(), "config.yml").exists())) { if (!(new UniversalFile(getDataFolder(), "config.yml").exists())) {
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath()); Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath());
Bukkit.getLogger().info("SubServers > Created ~/plugins/SubServers/config.yml"); Bukkit.getLogger().info("SubServers > Created ~/plugins/SubServers/config.yml");
} else if ((new Version((new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"))).get().getSection("Settings").getString("Version", "0")).compareTo(new Version("2.11.0a+"))) != 0) { } else if ((new Version((new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"))).get().getSection("Settings").getString("Version", "0")).compareTo(new Version("2.11.2a+"))) != 0) {
Files.move(new UniversalFile(getDataFolder(), "config.yml").toPath(), new UniversalFile(getDataFolder(), "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath()); Files.move(new UniversalFile(getDataFolder(), "config.yml").toPath(), new UniversalFile(getDataFolder(), "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath()); Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath());
@ -45,7 +45,6 @@ public final class SubPlugin extends JavaPlugin {
subdata = new SubDataClient(this, pluginconf.get().getSection("Settings").getSection("SubData").getString("Name", "~no_name"), subdata = new SubDataClient(this, pluginconf.get().getSection("Settings").getSection("SubData").getString("Name", "~no_name"),
InetAddress.getByName(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]), InetAddress.getByName(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1])); Integer.parseInt(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]));
Bukkit.getLogger().info("SubServers > SubData Connected to " + subdata.getClient().getRemoteSocketAddress().toString());
gui = new UIListener(this); gui = new UIListener(this);
getCommand("subservers").setExecutor(new SubCommand(this)); getCommand("subservers").setExecutor(new SubCommand(this));

View File

@ -35,9 +35,6 @@ permissions:
subservers.host.create.*: subservers.host.create.*:
description: 'Grants Access to Create a SubServer' description: 'Grants Access to Create a SubServer'
default: op default: op
subservers.host.edit.*:
description: 'Grants Access to Edit a Host'
default: op
subservers.subserver.*: subservers.subserver.*:
description: 'Grants Access to SubServers SubServer Actions' description: 'Grants Access to SubServers SubServer Actions'
default: op default: op
@ -54,9 +51,6 @@ permissions:
subservers.subserver.command.*: subservers.subserver.command.*:
description: 'Grants Access to Send Commands to a SubServer' description: 'Grants Access to Send Commands to a SubServer'
default: op default: op
subservers.subserver.edit.*:
description: 'Grants Access to Edit a SubServer'
default: op
subservers.server.*: subservers.server.*:
description: 'Grants Access to SubServer Server Actions' description: 'Grants Access to SubServer Server Actions'
default: op default: op