diff --git a/SubServers.Bungee/pom.xml b/SubServers.Bungee/pom.xml
index 1b7879c9..c53b9911 100644
--- a/SubServers.Bungee/pom.xml
+++ b/SubServers.Bungee/pom.xml
@@ -27,12 +27,6 @@
1.9-SNAPSHOT
provided
-
- net.java.dev.jna
- jna-platform
- 5.2.0
- compile
-
org.msgpack
msgpack-core
diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Executable.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Executable.java
index 2ce75a01..e4385100 100644
--- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Executable.java
+++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Executable.java
@@ -1,8 +1,6 @@
package net.ME1312.SubServers.Bungee.Host;
-import com.sun.jna.Pointer;
-import com.sun.jna.platform.win32.Kernel32;
-import com.sun.jna.platform.win32.WinNT;
+import net.ME1312.SubServers.Bungee.Library.Compatibility.JNA;
import java.io.File;
import java.lang.reflect.Field;
@@ -37,7 +35,7 @@ public class Executable {
* Get the PID of a currently running process
*
* @param process Process
- * @return Process ID
+ * @return Process ID (null if unknown)
*/
public static Long pid(Process process) {
if (process.isAlive()) {
@@ -51,17 +49,22 @@ public class Executable {
long handle = f.getLong(process);
f.setAccessible(false);
- Kernel32 k32 = Kernel32.INSTANCE;
- WinNT.HANDLE nt = new WinNT.HANDLE();
- nt.setPointer(Pointer.createConstant(handle));
- return (long) k32.GetProcessId(nt);
+ ClassLoader jna = JNA.get();
+ Class> pc = jna.loadClass("com.sun.jna.Pointer"),
+ ntc = jna.loadClass("com.sun.jna.platform.win32.WinNT$HANDLE"),
+ k32c = jna.loadClass("com.sun.jna.platform.win32.Kernel32");
+ Object k32 = k32c.getField("INSTANCE").get(null),
+ nt = ntc.getConstructor().newInstance();
+ ntc.getMethod("setPointer", pc).invoke(nt, pc.getMethod("createConstant", long.class).invoke(null, handle));
+ return ((Number) k32c.getMethod("GetProcessId", ntc).invoke(k32, nt)).longValue();
} else if (process.getClass().getName().equals("java.lang.UNIXProcess")) {
Field f = process.getClass().getDeclaredField("pid");
f.setAccessible(true);
Object response = f.get(process);
f.setAccessible(false);
- if (response instanceof Number) return ((Number) response).longValue();
+ if (response instanceof Number)
+ return ((Number) response).longValue();
}
} catch (Throwable e) {}
}
@@ -79,7 +82,7 @@ public class Executable {
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
Long pid = pid(process);
if (pid != null) try {
- Process terminator = Runtime.getRuntime().exec(new String[]{"taskkill", "/T", "/F", "/PID", pid.toString()});
+ Process terminator = Runtime.getRuntime().exec(new String[]{"taskkill.exe", "/T", "/F", "/PID", pid.toString()});
terminator.waitFor();
} catch (Throwable e) {}
}
diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/JNA.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/JNA.java
new file mode 100644
index 00000000..413e7de4
--- /dev/null
+++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/JNA.java
@@ -0,0 +1,66 @@
+package net.ME1312.SubServers.Bungee.Library.Compatibility;
+
+import com.google.common.io.Resources;
+import net.ME1312.SubServers.Bungee.Library.UniversalFile;
+import net.ME1312.SubServers.Bungee.SubAPI;
+
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+/**
+ * Load JNA Library
+ */
+public class JNA {
+ private static ClassLoader JNA = null;
+ private static final String JNA_VERSION = "5.2.0";
+ private static final String JNA_DOWNLOAD = "https://oss.sonatype.org/service/local/repositories/releases/content/net/java/dev/jna/$1/" + JNA_VERSION + "/$1-" + JNA_VERSION + ".jar";
+
+ @SuppressWarnings("deprecation")
+ public static ClassLoader get() {
+ if (JNA == null) {
+ boolean announced = false;
+ UniversalFile library = new UniversalFile(SubAPI.getInstance().getInternals().dir, "SubServers:Cache:Libraries");
+ library.mkdirs();
+ UniversalFile jna = new UniversalFile(library, "JNA.jar");
+ if (!jna.exists()) {
+ jna.getParentFile().mkdirs();
+ if (!jna.exists()) {
+ System.out.println(">> Downloading JNA Library v" + JNA_VERSION);
+ try (FileOutputStream fin = new FileOutputStream(jna)) {
+ Resources.copy(new URL(JNA_DOWNLOAD.replace("$1", "jna")), fin);
+ } catch (Throwable e) {
+ jna.delete();
+ e.printStackTrace();
+ }
+ announced = true;
+ }
+ }
+ UniversalFile platform = new UniversalFile(library, "JNA-Platform.jar");
+ if (!platform.exists()) {
+ platform.getParentFile().mkdirs();
+ if (!platform.exists()) {
+ if (!announced) System.out.println(">> Downloading JNA Library v" + JNA_VERSION);
+ try (FileOutputStream fin = new FileOutputStream(platform)) {
+ Resources.copy(new URL(JNA_DOWNLOAD.replace("$1", "jna-platform")), fin);
+ } catch (Throwable e) {
+ platform.delete();
+ e.printStackTrace();
+ }
+ }
+ }
+ if (jna.exists()) {
+ System.out.println(">> Loading JNA Library");
+ try {
+ JNA = new URLClassLoader(new URL[]{jna.toURI().toURL(), platform.toURI().toURL()});
+ } catch (Throwable e) {
+ e.printStackTrace();
+ throw new IllegalArgumentException("Could not load JNA Library");
+ }
+ } else {
+ throw new IllegalArgumentException("Could not find JNA Library");
+ }
+ }
+ return JNA;
+ }
+}
diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/v1_13/CommandX.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/mc1_13/CommandX.java
similarity index 97%
rename from SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/v1_13/CommandX.java
rename to SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/mc1_13/CommandX.java
index cbcbc10f..ebc1550a 100644
--- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/v1_13/CommandX.java
+++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/mc1_13/CommandX.java
@@ -1,4 +1,4 @@
-package net.ME1312.SubServers.Bungee.Library.Compatibility.v1_13;
+package net.ME1312.SubServers.Bungee.Library.Compatibility.mc1_13;
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
import net.md_5.bungee.api.CommandSender;
diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java
index c2b08cb0..0c7e2fa8 100644
--- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java
+++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java
@@ -36,7 +36,7 @@ public final class SubCommand extends CommandX {
NamedContainer cmd = new NamedContainer<>(new SubCommand(plugin, command), null);
CommandX now = cmd.name();
//if (plugin.api.getGameVersion()[plugin.api.getGameVersion().length - 1].compareTo(new Version("1.13")) >= 0) { // TODO Future Command Validator API?
- // now = new net.ME1312.SubServers.Bungee.Library.Compatibility.v1_13.CommandX(cmd.name());
+ // now = new net.ME1312.SubServers.Bungee.Library.Compatibility.mc1_13.CommandX(cmd.name());
//}
cmd.set(now);
return cmd;
@@ -858,7 +858,7 @@ public final class SubCommand extends CommandX {
NamedContainer cmd = new NamedContainer<>(new BungeeServer(plugin, command), null);
CommandX now = cmd.name();
//if (plugin.api.getGameVersion()[plugin.api.getGameVersion().length - 1].compareTo(new Version("1.13")) >= 0) { // TODO Future Command Validator API?
- // now = new net.ME1312.SubServers.Bungee.Library.Compatibility.v1_13.CommandX(cmd.name());
+ // now = new net.ME1312.SubServers.Bungee.Library.Compatibility.mc1_13.CommandX(cmd.name());
//}
cmd.set(now);
return cmd;
diff --git a/SubServers.Host/pom.xml b/SubServers.Host/pom.xml
index dd71c901..97185c57 100644
--- a/SubServers.Host/pom.xml
+++ b/SubServers.Host/pom.xml
@@ -23,12 +23,6 @@
19w02e
compile
-
- net.java.dev.jna
- jna-platform
- 5.2.0
- compile
-
org.msgpack
msgpack-core
diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/Executable.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/Executable.java
index 637d9641..03d1ec87 100644
--- a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/Executable.java
+++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/Executable.java
@@ -1,8 +1,6 @@
package net.ME1312.SubServers.Host.Executable;
-import com.sun.jna.Pointer;
-import com.sun.jna.platform.win32.Kernel32;
-import com.sun.jna.platform.win32.WinNT;
+import net.ME1312.SubServers.Host.Library.Compatibility.JNA;
import java.io.File;
import java.lang.reflect.Field;
@@ -37,7 +35,7 @@ public class Executable {
* Get the PID of a currently running process
*
* @param process Process
- * @return Process ID
+ * @return Process ID (null if unknown)
*/
public static Long pid(Process process) {
if (process.isAlive()) {
@@ -51,17 +49,22 @@ public class Executable {
long handle = f.getLong(process);
f.setAccessible(false);
- Kernel32 k32 = Kernel32.INSTANCE;
- WinNT.HANDLE nt = new WinNT.HANDLE();
- nt.setPointer(Pointer.createConstant(handle));
- return (long) k32.GetProcessId(nt);
+ ClassLoader jna = JNA.get();
+ Class> pc = jna.loadClass("com.sun.jna.Pointer"),
+ ntc = jna.loadClass("com.sun.jna.platform.win32.WinNT$HANDLE"),
+ k32c = jna.loadClass("com.sun.jna.platform.win32.Kernel32");
+ Object k32 = k32c.getField("INSTANCE").get(null),
+ nt = ntc.getConstructor().newInstance();
+ ntc.getMethod("setPointer", pc).invoke(nt, pc.getMethod("createConstant", long.class).invoke(null, handle));
+ return ((Number) k32c.getMethod("GetProcessId", ntc).invoke(k32, nt)).longValue();
} else if (process.getClass().getName().equals("java.lang.UNIXProcess")) {
Field f = process.getClass().getDeclaredField("pid");
f.setAccessible(true);
Object response = f.get(process);
f.setAccessible(false);
- if (response instanceof Number) return ((Number) response).longValue();
+ if (response instanceof Number)
+ return ((Number) response).longValue();
}
} catch (Throwable e) {}
}
@@ -79,7 +82,7 @@ public class Executable {
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
Long pid = pid(process);
if (pid != null) try {
- Process terminator = Runtime.getRuntime().exec(new String[]{"taskkill", "/T", "/F", "/PID", pid.toString()});
+ Process terminator = Runtime.getRuntime().exec(new String[]{"taskkill.exe", "/T", "/F", "/PID", pid.toString()});
terminator.waitFor();
} catch (Throwable e) {}
}
diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Compatibility/JNA.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Compatibility/JNA.java
new file mode 100644
index 00000000..73cc9acd
--- /dev/null
+++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Compatibility/JNA.java
@@ -0,0 +1,69 @@
+package net.ME1312.SubServers.Host.Library.Compatibility;
+
+import net.ME1312.Galaxi.Galaxi;
+import net.ME1312.Galaxi.Library.Log.Logger;
+import net.ME1312.Galaxi.Library.UniversalFile;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+
+/**
+ * Load JNA Library
+ */
+public class JNA {
+ private static ClassLoader JNA = null;
+ private static final String JNA_VERSION = "5.2.0";
+ private static final String JNA_DOWNLOAD = "https://oss.sonatype.org/service/local/repositories/releases/content/net/java/dev/jna/$1/" + JNA_VERSION + "/$1-" + JNA_VERSION + ".jar";
+
+ @SuppressWarnings("deprecation")
+ public static ClassLoader get() {
+ if (JNA == null) {
+ boolean announced = false;
+ Logger log = new Logger("JNA");
+ UniversalFile library = new UniversalFile(Galaxi.getInstance().getRuntimeDirectory(), "Cache:Libraries");
+ library.mkdirs();
+ UniversalFile jna = new UniversalFile(library, "JNA.jar");
+ if (!jna.exists()) {
+ jna.getParentFile().mkdirs();
+ if (!jna.exists()) {
+ announced = true;
+ log.info.println("Downloading JNA Library v" + JNA_VERSION);
+ try (InputStream in = new URL(JNA_DOWNLOAD.replace("$1", "jna")).openStream()) {
+ Files.copy(in, jna.toPath(), StandardCopyOption.REPLACE_EXISTING);
+ } catch (Throwable e) {
+ jna.delete();
+ log.error.println(e);
+ }
+ }
+ }
+ UniversalFile platform = new UniversalFile(library, "JNA-Platform.jar");
+ if (!platform.exists()) {
+ platform.getParentFile().mkdirs();
+ if (!platform.exists()) {
+ if (!announced) log.info.println("Downloading JNA Library v" + JNA_VERSION);
+ try (InputStream in = new URL(JNA_DOWNLOAD.replace("$1", "jna-platform")).openStream()) {
+ Files.copy(in, platform.toPath(), StandardCopyOption.REPLACE_EXISTING);
+ } catch (Throwable e) {
+ platform.delete();
+ log.error.println(e);
+ }
+ }
+ }
+ if (jna.exists()) {
+ log.info.println("Loading JNA Library");
+ try {
+ JNA = new URLClassLoader(new URL[]{jna.toURI().toURL(), platform.toURI().toURL()});
+ } catch (Throwable e) {
+ log.error.println(e);
+ throw new IllegalArgumentException("Could not load JNA Library");
+ }
+ } else {
+ throw new IllegalArgumentException("Could not find JNA Library");
+ }
+ }
+ return JNA;
+ }
+}
diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketDownloadLang.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketDownloadLang.java
index 7e97abc9..80f019c4 100644
--- a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketDownloadLang.java
+++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketDownloadLang.java
@@ -44,7 +44,7 @@ public class PacketDownloadLang implements PacketIn, PacketOut {
f.setAccessible(false);
log.info.println("Lang Settings Downloaded");
} catch (IllegalAccessException | NoSuchFieldException e) {
- e.printStackTrace();
+ log.error.println(e);
}
}
diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.java
index 373cb12d..a515478f 100644
--- a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.java
+++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketExDeleteServer.java
@@ -92,7 +92,7 @@ public class PacketExDeleteServer implements PacketIn, PacketOut {
Util.deleteDirectory(from);
}
} catch (Exception e) {
- e.printStackTrace();
+ log.error.println(e);
}
log.info.println("Saving...");
@@ -102,7 +102,7 @@ public class PacketExDeleteServer implements PacketIn, PacketOut {
data.getSection("info").toJSON().write(writer);
writer.close();
} catch (Exception e) {
- e.printStackTrace();
+ log.error.println(e);
}
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(server.getPort())) UPnP.closePortTCP(server.getPort());
log.info.println("Deleted SubServer: " + data.getRawString("server"));
diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketInReload.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketInReload.java
index 1d1be470..90bdc0e5 100644
--- a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketInReload.java
+++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketInReload.java
@@ -1,20 +1,30 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
+import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Host.ExHost;
import net.ME1312.SubServers.Host.Network.PacketIn;
+import net.ME1312.SubServers.Host.Network.SubDataClient;
import java.io.IOException;
+import java.lang.reflect.Field;
/**
* Reload Packet
*/
public class PacketInReload implements PacketIn {
private ExHost host;
+ private Logger log;
public PacketInReload(ExHost host) {
this.host = host;
+ try {
+ Field f = SubDataClient.class.getDeclaredField("log");
+ f.setAccessible(true);
+ this.log = (Logger) f.get(null);
+ f.setAccessible(false);
+ } catch (IllegalAccessException | NoSuchFieldException e) {}
}
@Override
@@ -22,7 +32,7 @@ public class PacketInReload implements PacketIn {
try {
host.reload();
} catch (IOException e) {
- e.printStackTrace();
+ log.error.println(e);
}
}
diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java
index c054d7de..b9920150 100644
--- a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java
+++ b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java
@@ -58,7 +58,7 @@ public class SubCommand {
commands = (TreeMap) f.get(GalaxiEngine.getInstance().getPluginManager());
f.setAccessible(false);
} catch (Exception e) {
- e.printStackTrace();
+ SubAPI.getInstance().getAppInfo().getLogger().error.println(e);
commands = new TreeMap();
}
if (args.length <= 1) {
diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Compatibility/v1_13/CommandX.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Compatibility/mc1_13/CommandX.java
similarity index 97%
rename from SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Compatibility/v1_13/CommandX.java
rename to SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Compatibility/mc1_13/CommandX.java
index dd90f66f..2a283e04 100644
--- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Compatibility/v1_13/CommandX.java
+++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Compatibility/mc1_13/CommandX.java
@@ -1,4 +1,4 @@
-package net.ME1312.SubServers.Sync.Library.Compatibility.v1_13;
+package net.ME1312.SubServers.Sync.Library.Compatibility.mc1_13;
import net.ME1312.SubServers.Sync.Library.NamedContainer;
import net.md_5.bungee.api.CommandSender;
diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java
index 049266a6..7363621b 100644
--- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java
+++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java
@@ -41,7 +41,7 @@ public final class SubCommand extends CommandX {
NamedContainer cmd = new NamedContainer<>(new SubCommand(plugin, command), null);
CommandX now = cmd.name();
//if (plugin.api.getGameVersion()[plugin.api.getGameVersion().length - 1].compareTo(new Version("1.13")) >= 0) { // TODO Future Command Validator API?
- // now = new net.ME1312.SubServers.Sync.Library.Compatibility.v1_13.CommandX(cmd.name());
+ // now = new net.ME1312.SubServers.Sync.Library.Compatibility.mc1_13.CommandX(cmd.name());
//}
cmd.set(now);
return cmd;
@@ -857,7 +857,7 @@ public final class SubCommand extends CommandX {
NamedContainer cmd = new NamedContainer<>(new BungeeServer(plugin, command), null);
CommandX now = cmd.name();
//if (plugin.api.getGameVersion()[plugin.api.getGameVersion().length - 1].compareTo(new Version("1.13")) >= 0) { // TODO Future Command Validator API?
- // now = new net.ME1312.SubServers.Sync.Library.Compatibility.v1_13.CommandX(cmd.name());
+ // now = new net.ME1312.SubServers.Sync.Library.Compatibility.mc1_13.CommandX(cmd.name());
//}
cmd.set(now);
return cmd;