Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
182 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Compatibility/JNA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...Library/Compatibility/v1_13/CommandX.java → ...ibrary/Compatibility/mc1_13/CommandX.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
SubServers.Host/src/net/ME1312/SubServers/Host/Library/Compatibility/JNA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketInReload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Library/Compatibility/v1_13/CommandX.java → ...ibrary/Compatibility/mc1_13/CommandX.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters