Using separate process - Did a while ago
This commit is contained in:
parent
d7deeb35b5
commit
97217cb0c4
2 changed files with 30 additions and 57 deletions
5
pom.xml
5
pom.xml
|
@ -18,10 +18,5 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.xeustechnologies</groupId>
|
|
||||||
<artifactId>jcl-core</artifactId>
|
|
||||||
<version>2.6</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -1,61 +1,39 @@
|
||||||
package buttondevteam.serverrunner;
|
package buttondevteam.serverrunner;
|
||||||
|
|
||||||
import java.util.logging.ConsoleHandler;
|
import java.io.BufferedReader;
|
||||||
import java.util.logging.Level;
|
import java.io.BufferedWriter;
|
||||||
import java.util.logging.Logger;
|
import java.io.IOException;
|
||||||
import java.util.logging.SimpleFormatter;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.craftbukkit.Main;
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
|
|
||||||
import org.xeustechnologies.jcl.ClasspathResources;
|
|
||||||
import org.xeustechnologies.jcl.Configuration;
|
|
||||||
import org.xeustechnologies.jcl.JarClassLoader;
|
|
||||||
import org.xeustechnologies.jcl.JclObjectFactory;
|
|
||||||
import org.xeustechnologies.jcl.proxy.CglibProxyProvider;
|
|
||||||
import org.xeustechnologies.jcl.proxy.ProxyProviderFactory;
|
|
||||||
|
|
||||||
public class ServerRunner {
|
public class ServerRunner {
|
||||||
private static final String SERVER_VERSION = "1.9.2";
|
private static final String SERVER_VERSION = "1.9.2";
|
||||||
|
|
||||||
@SuppressWarnings("static-access")
|
public static void main(String[] args) throws IOException {
|
||||||
public static void main(String[] args) {
|
System.out.println("Starting server...");
|
||||||
try {
|
Process p = Runtime.getRuntime().exec(
|
||||||
System.out.println("Loading server classes...");
|
new String[] { "java", "-Xms512M", "-Xmx1024M", "-XX:MaxPermSize=128M", "-jar", "spigot-1.9.2.jar" });
|
||||||
JarClassLoader jcl = new JarClassLoader();
|
Thread t = new Thread() {
|
||||||
jcl.getSystemLoader().setEnabled(true);
|
@Override
|
||||||
jcl.getCurrentLoader().setEnabled(false);
|
public void run() {
|
||||||
jcl.getParentLoader().setEnabled(false);
|
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
|
||||||
jcl.getOsgiBootLoader().setEnabled(false);
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
jcl.getThreadLoader().setEnabled(false);
|
String outline;
|
||||||
jcl.getLocalLoader().setEnabled(true);
|
try {
|
||||||
jcl.add("spigot-" + SERVER_VERSION + ".jar");
|
while ((outline = br.readLine()) != null)
|
||||||
jcl.add("craftbukkit-" + SERVER_VERSION + ".jar");
|
output.write(outline + "\n");
|
||||||
System.out.println("Starting server...");
|
} catch (IOException e) {
|
||||||
// Set default to cglib (from version 2.2.1)
|
e.printStackTrace();
|
||||||
ProxyProviderFactory.setDefaultProxyProvider(new CglibProxyProvider());
|
}
|
||||||
|
}
|
||||||
// Create a factory of castable objects/proxies
|
};
|
||||||
JclObjectFactory factory = JclObjectFactory.getInstance(true);
|
t.setName("InputThread");
|
||||||
|
t.start();
|
||||||
// Create and cast object of loaded class
|
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||||
Main serverinstance = (Main) factory.create(jcl, "buttondevteam.serverrunner.ServerMain");
|
String line;
|
||||||
serverinstance.main(new String[0]);
|
while ((line = input.readLine()) != null) {
|
||||||
Thread.sleep(5000); // Wait for primaryThread to be set
|
System.out.println(line);
|
||||||
while (Bukkit.getServer() == null || ((CraftServer) Bukkit.getServer()).getServer() == null
|
|
||||||
|| ((CraftServer) Bukkit.getServer()).getServer().primaryThread == null)
|
|
||||||
;
|
|
||||||
((CraftServer) Bukkit.getServer()).getServer().primaryThread.join();
|
|
||||||
/*
|
|
||||||
* for (Thread t : Thread.getAllStackTraces().keySet()) if
|
|
||||||
* (t.getName().equals("Server Infinisleeper")) t.join();
|
|
||||||
*/ // TODO: After stopping the server it stops
|
|
||||||
System.out.println("Unloading classes...");
|
|
||||||
for (String entry : jcl.getLoadedClasses().keySet())
|
|
||||||
jcl.unloadClass(entry);
|
|
||||||
System.out.println("Done!");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
input.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue