mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-06-02 18:02:20 +00:00
1.5.1
- Added ip exemptions in addition to the existing player exemptions./ - Fixing System.out usage warnings that some users were experiencing. - Fixing MySQL drivers not loading on some servers. - Fixing bug that would make whitelisted players not load for awhile after server starts
This commit is contained in:
@@ -16,6 +16,7 @@ import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -32,12 +33,14 @@ public class AntiVPN {
|
||||
private MessageHandler messageHandler;
|
||||
private List<Command> commands = new ArrayList<>();
|
||||
public int detections, checked;
|
||||
private File pluginFolder;
|
||||
|
||||
public static void start(VPNConfig config, VPNExecutor executor, PlayerExecutor playerExecutor) {
|
||||
public static void start(VPNConfig config, VPNExecutor executor, PlayerExecutor playerExecutor, File pluginFolder) {
|
||||
//Initializing
|
||||
|
||||
INSTANCE = new AntiVPN();
|
||||
|
||||
INSTANCE.pluginFolder = pluginFolder;
|
||||
INSTANCE.config = config;
|
||||
INSTANCE.executor = executor;
|
||||
INSTANCE.playerExecutor = playerExecutor;
|
||||
|
||||
@@ -18,6 +18,8 @@ public abstract class VPNExecutor {
|
||||
private static final Map<String, VPNResponse> responseCache = new HashMap<>();
|
||||
@Getter
|
||||
private final Set<UUID> whitelisted = Collections.synchronizedSet(new HashSet<>());
|
||||
@Getter
|
||||
private final Set<String> whitelistedIps = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
public abstract void registerListeners();
|
||||
|
||||
@@ -35,6 +37,10 @@ public abstract class VPNExecutor {
|
||||
return whitelisted.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean isWhitelisted(String ip) {
|
||||
return whitelistedIps.contains(ip);
|
||||
}
|
||||
|
||||
public void checkIp(String ip, boolean cachedResults, Consumer<VPNResponse> result) {
|
||||
threadExecutor.execute(() -> result.accept(responseCache.compute(ip, (key, val) -> {
|
||||
if(val == null) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.api.APIPlayer;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import dev.brighten.antivpn.command.CommandExecutor;
|
||||
import dev.brighten.antivpn.utils.MiscUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -34,7 +35,7 @@ public class AllowlistCommand extends Command {
|
||||
|
||||
@Override
|
||||
public String usage() {
|
||||
return "<add/remove> <player/uuid>";
|
||||
return "<add/remove> <player/uuid/ip>";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,7 +51,7 @@ public class AllowlistCommand extends Command {
|
||||
@Override
|
||||
public String execute(CommandExecutor executor, String[] args) {
|
||||
if(args.length == 0 || Arrays.stream(secondArgs).noneMatch(arg -> arg.equalsIgnoreCase(args[0]))) {
|
||||
return "&cUsage: /antivpn allowlist <add/remove> <player>";
|
||||
return "&cUsage: /antivpn allowlist " + usage();
|
||||
}
|
||||
|
||||
if(args.length == 1)
|
||||
@@ -61,34 +62,82 @@ public class AllowlistCommand extends Command {
|
||||
if(!databaseEnabled) executor.sendMessage("&cThe database is currently not setup, " +
|
||||
"so any changes here will disappear after a restart.");
|
||||
|
||||
UUID uuid = null;
|
||||
try {
|
||||
uuid = UUID.fromString(args[1]);
|
||||
} catch(IllegalArgumentException e) {
|
||||
Optional<APIPlayer> player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(args[1]);
|
||||
|
||||
if(!player.isPresent()) {
|
||||
return "&cThe player \"" + args[1] + "\" is not online, so please provide a UUID.";
|
||||
}
|
||||
|
||||
uuid = player.get().getUuid();
|
||||
}
|
||||
|
||||
if(!databaseEnabled) {
|
||||
if(args[0].equalsIgnoreCase("add")) {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().add(uuid);
|
||||
return String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString());
|
||||
if(MiscUtils.isIpv4(args[1])) {
|
||||
if(!databaseEnabled) {
|
||||
switch(args[0].toLowerCase()) {
|
||||
case "add": {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps().add(args[1]);
|
||||
return String.format("&aAdded &6%s &ato the exemption allowlist.", args[1]);
|
||||
}
|
||||
case "remove":
|
||||
case "delete": {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps().remove(args[1]);
|
||||
return String.format("&cRemoved &6%s &cfrom the exemption allowlist.", args[1]);
|
||||
}
|
||||
default: {
|
||||
return "&c\"" + args[0] + "\" is not a valid argument";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().remove(uuid);
|
||||
return String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString());
|
||||
switch(args[0].toLowerCase()) {
|
||||
case "add": {
|
||||
AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], true);
|
||||
return String.format("&aAdded &6%s &a to the exemption allowlist.", args[1]);
|
||||
}
|
||||
case "remove":
|
||||
case "delete": {
|
||||
AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], false);
|
||||
return String.format("&cRemoved &6%s &c from the exemption allowlist.", args[1]);
|
||||
}
|
||||
default: {
|
||||
return "&c\"" + args[0] + "\" is not a valid argument";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(args[0].equalsIgnoreCase("add")) {
|
||||
AntiVPN.getInstance().getDatabase().setWhitelisted(uuid, true);
|
||||
return String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString());
|
||||
UUID uuid = null;
|
||||
try {
|
||||
uuid = UUID.fromString(args[1]);
|
||||
} catch(IllegalArgumentException e) {
|
||||
Optional<APIPlayer> player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(args[1]);
|
||||
|
||||
if(!player.isPresent()) {
|
||||
return "&cThe player \"" + args[1] + "\" is not online, so please provide a UUID.";
|
||||
}
|
||||
|
||||
uuid = player.get().getUuid();
|
||||
}
|
||||
|
||||
if(!databaseEnabled) {
|
||||
switch(args[0].toLowerCase()) {
|
||||
case "add": {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().add(uuid);
|
||||
return String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString());
|
||||
}
|
||||
case "remove":
|
||||
case "delete": {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().remove(uuid);
|
||||
return String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString());
|
||||
}
|
||||
default: {
|
||||
return "&c\"" + args[0] + "\" is not a valid argument";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
AntiVPN.getInstance().getDatabase().setWhitelisted(uuid, false);
|
||||
return String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString());
|
||||
switch(args[0].toLowerCase()) {
|
||||
case "add": {
|
||||
AntiVPN.getInstance().getDatabase().setWhitelisted(uuid, true);
|
||||
return String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString());
|
||||
}
|
||||
case "remove":
|
||||
case "delete": {
|
||||
AntiVPN.getInstance().getDatabase().setWhitelisted(uuid, false);
|
||||
return String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString());
|
||||
}
|
||||
default: {
|
||||
return "&c\"" + args[0] + "\" is not a valid argument";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,22 @@ public interface VPNDatabase {
|
||||
|
||||
boolean isWhitelisted(UUID uuid);
|
||||
|
||||
boolean isWhitelisted(String ip);
|
||||
|
||||
void setWhitelisted(UUID uuid, boolean whitelisted);
|
||||
|
||||
void setWhitelisted(String ip, boolean whitelisted);
|
||||
|
||||
List<UUID> getAllWhitelisted();
|
||||
|
||||
List<String> getAllWhitelistedIps();
|
||||
|
||||
void getStoredResponseAsync(String ip, Consumer<Optional<VPNResponse>> result);
|
||||
|
||||
void isWhitelistedAsync(UUID uuid, Consumer<Boolean> result);
|
||||
|
||||
void isWhitelistedAsync(String ip, Consumer<Boolean> result);
|
||||
|
||||
void alertsState(UUID uuid, Consumer<Boolean> result);
|
||||
|
||||
void updateAlertsState(UUID uuid, boolean state);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class MySqlVPN implements VPNDatabase {
|
||||
public MySqlVPN() {
|
||||
whitelistedThread = new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(8));
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -30,6 +30,9 @@ public class MySqlVPN implements VPNDatabase {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().clear();
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted()
|
||||
.addAll(AntiVPN.getInstance().getDatabase().getAllWhitelisted());
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps().clear();
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps()
|
||||
.addAll(AntiVPN.getInstance().getDatabase().getAllWhitelistedIps());
|
||||
}
|
||||
try {
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(4));
|
||||
@@ -95,15 +98,28 @@ public class MySqlVPN implements VPNDatabase {
|
||||
public boolean isWhitelisted(UUID uuid) {
|
||||
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||
return false;
|
||||
ResultSet set = Query.prepare("select uuid from `whitelisted` where `uuid` = ? limit 1").append(uuid.toString())
|
||||
.executeQuery();
|
||||
ResultSet set = Query.prepare("select uuid from `whitelisted` where `uuid` = ? limit 1")
|
||||
.append(uuid.toString()).executeQuery();
|
||||
|
||||
return set != null && set.next() && set.getString("uuid") != null;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public boolean isWhitelisted(String ip) {
|
||||
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||
return false;
|
||||
ResultSet set = Query.prepare("select `ip` from `whitelisted-ips` where `ip` = ? limit 1")
|
||||
.append(ip).executeQuery();
|
||||
|
||||
|
||||
return set != null && set.next() && set.getString("ip") != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhitelisted(UUID uuid, boolean whitelisted) {
|
||||
if(MySQL.isClosed()) return;
|
||||
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||
return;
|
||||
|
||||
if (whitelisted) {
|
||||
if (!isWhitelisted(uuid)) {
|
||||
@@ -116,24 +132,42 @@ public class MySqlVPN implements VPNDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhitelisted(String ip, boolean whitelisted) {
|
||||
if (!AntiVPN.getInstance().getConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||
return;
|
||||
|
||||
if(whitelisted) {
|
||||
if(!isWhitelisted(ip)) {
|
||||
Query.prepare("insert into `whitelisted-ips` (`ip`) values (?)").append(ip).execute();
|
||||
}
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps().add(ip);
|
||||
} else {
|
||||
Query.prepare("delete from `whitelisted-ips` where `ip` = ?").append(ip).execute();
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps().remove(ip);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getAllWhitelisted() {
|
||||
List<UUID> uuids = new ArrayList<>();
|
||||
|
||||
if(MySQL.isClosed()) return uuids;
|
||||
if(!MySQL.isClosed()) Query.prepare("select uuid from `whitelisted`")
|
||||
.execute(set -> uuids.add(UUID.fromString(set.getString("uuid"))));
|
||||
|
||||
ResultSet set = Query.prepare("select uuid from `whitelisted`").executeQuery();
|
||||
|
||||
try {
|
||||
while (set.next()) {
|
||||
uuids.add(UUID.fromString(set.getString("uuid")));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllWhitelistedIps() {
|
||||
List<String> ips = new ArrayList<>();
|
||||
|
||||
if(!MySQL.isClosed()) Query.prepare("select `ip` from `whitelisted-ips`")
|
||||
.execute(set -> ips.add(set.getString("ip")));
|
||||
|
||||
return ips;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStoredResponseAsync(String ip, Consumer<Optional<VPNResponse>> result) {
|
||||
if(MySQL.isClosed()) return;
|
||||
@@ -148,6 +182,13 @@ public class MySqlVPN implements VPNDatabase {
|
||||
VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(uuid)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isWhitelistedAsync(String ip, Consumer<Boolean> result) {
|
||||
if(MySQL.isClosed()) return;
|
||||
|
||||
VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(ip)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void alertsState(UUID uuid, Consumer<Boolean> result) {
|
||||
if(MySQL.isClosed()) return;
|
||||
@@ -208,6 +249,7 @@ public class MySqlVPN implements VPNDatabase {
|
||||
}
|
||||
|
||||
Query.prepare("create table if not exists `whitelisted` (`uuid` varchar(36) not null)").execute();
|
||||
Query.prepare("create table if not exists `whitelisted-ips` (`ip` varchar(45) not null)").execute();
|
||||
Query.prepare("create table if not exists `responses` (`ip` varchar(45) not null, `asn` varchar(12),"
|
||||
+ "`countryName` text, `countryCode` varchar(10), `city` text, `timeZone` varchar(64), "
|
||||
+ "`method` varchar(32), `isp` text, `proxy` boolean, `cached` boolean, `inserted` timestamp,"
|
||||
@@ -218,41 +260,62 @@ public class MySqlVPN implements VPNDatabase {
|
||||
try {
|
||||
// Ref:
|
||||
// https://dba.stackexchange.com/questions/24531/mysql-create-index-if-not-exists
|
||||
String query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='whitelisted' AND index_name='uuid_1';";
|
||||
|
||||
String query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE()" +
|
||||
" AND table_name='whitelisted' AND index_name='uuid_1';";
|
||||
ResultSet rs = Query.prepare(query).executeQuery();
|
||||
int id = 0;
|
||||
while (rs.next()) {
|
||||
id = rs.getInt("IndexExists");
|
||||
whitelistedIndex: {
|
||||
while (rs.next()) {
|
||||
id = rs.getInt("IndexExists");
|
||||
}
|
||||
if (id == 0) {
|
||||
Query.prepare("create index `uuid_1` on `whitelisted` (`uuid`)").execute();
|
||||
}
|
||||
id = 0;
|
||||
}
|
||||
if (id == 0) {
|
||||
Query.prepare("create index `uuid_1` on `whitelisted` (`uuid`)").execute();
|
||||
responsesIndex: {
|
||||
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() " +
|
||||
"AND table_name='responses' AND index_name='ip_1';";
|
||||
rs = Query.prepare(query).executeQuery();
|
||||
while (rs.next()) {
|
||||
id = rs.getInt("IndexExists");
|
||||
}
|
||||
if (id == 0) {
|
||||
Query.prepare("create index `ip_1` on `responses` (`ip`)").execute();
|
||||
}
|
||||
id = 0;
|
||||
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() " +
|
||||
"AND table_name='responses' AND index_name='proxy_1';";
|
||||
rs = Query.prepare(query).executeQuery();
|
||||
while (rs.next()) {
|
||||
id = rs.getInt("IndexExists");
|
||||
}
|
||||
if (id == 0) {
|
||||
Query.prepare("create index `proxy_1` on `responses` (`proxy`)").execute();
|
||||
}
|
||||
id = 0;
|
||||
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE()" +
|
||||
" AND table_name='responses' AND index_name='inserted_1';";
|
||||
rs = Query.prepare(query).executeQuery();
|
||||
while (rs.next()) {
|
||||
id = rs.getInt("IndexExists");
|
||||
}
|
||||
if (id == 0) {
|
||||
Query.prepare("create index `inserted_1` on `responses` (`inserted`)").execute();
|
||||
}
|
||||
id = 0;
|
||||
}
|
||||
id = 0;
|
||||
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='responses' AND index_name='ip_1';";
|
||||
rs = Query.prepare(query).executeQuery();
|
||||
while (rs.next()) {
|
||||
id = rs.getInt("IndexExists");
|
||||
}
|
||||
if (id == 0) {
|
||||
Query.prepare("create index `ip_1` on `responses` (`ip`)").execute();
|
||||
}
|
||||
id = 0;
|
||||
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='responses' AND index_name='proxy_1';";
|
||||
rs = Query.prepare(query).executeQuery();
|
||||
while (rs.next()) {
|
||||
id = rs.getInt("IndexExists");
|
||||
}
|
||||
if (id == 0) {
|
||||
Query.prepare("create index `proxy_1` on `responses` (`proxy`)").execute();
|
||||
}
|
||||
id = 0;
|
||||
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='responses' AND index_name='inserted_1';";
|
||||
rs = Query.prepare(query).executeQuery();
|
||||
while (rs.next()) {
|
||||
id = rs.getInt("IndexExists");
|
||||
}
|
||||
if (id == 0) {
|
||||
Query.prepare("create index `inserted_1` on `responses` (`inserted`)").execute();
|
||||
whitelistedIpsIndex: {
|
||||
query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE()" +
|
||||
" AND table_name='whitelisted-ips' AND index_name='ip_1';";
|
||||
rs = Query.prepare(query).executeQuery();
|
||||
while (rs.next()) {
|
||||
id = rs.getInt("IndexExists");
|
||||
}
|
||||
if (id == 0) {
|
||||
Query.prepare("create index `ip_1` on `whitelisted-ips` (`ip`)").execute();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("MySQL Excepton created" + e.getMessage());
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package dev.brighten.antivpn.database.sql.utils;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.utils.MiscUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
@@ -12,6 +14,15 @@ public class MySQL {
|
||||
public static void init() {
|
||||
try {
|
||||
if (conn == null || conn.isClosed()) {
|
||||
File mysqlLib = new File(AntiVPN.getInstance().getPluginFolder(), "mysqllib.jar");
|
||||
|
||||
if(!mysqlLib.exists()) {
|
||||
AntiVPN.getInstance().getExecutor().log("Downloading mysqllib.jar...");
|
||||
MiscUtils.download(mysqlLib, "https://nexus.funkemunky.cc/content/repositories/releases" +
|
||||
"/mysql/mysql-connector-java/8.0.22/mysql-connector-java-8.0.22.jar");
|
||||
}
|
||||
MiscUtils.injectURL(mysqlLib.toURI().toURL());
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
conn = DriverManager.getConnection("jdbc:mysql://" + AntiVPN.getInstance().getConfig().getIp()
|
||||
+ ":" + AntiVPN.getInstance().getConfig().getPort()
|
||||
+ "/?useSSL=true&autoReconnect=true",
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
package dev.brighten.antivpn.utils;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
|
||||
public class MiscUtils {
|
||||
|
||||
@@ -20,4 +30,44 @@ public class MiscUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isIpv4(String ip)
|
||||
{
|
||||
|
||||
try {
|
||||
InetAddress address = InetAddress.getByName(ip);
|
||||
|
||||
return address instanceof Inet4Address;
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Borrowed from FireFlyx ngxdev */
|
||||
public static void download(File file, String from) throws Exception {
|
||||
URL url = new URL(from);
|
||||
InputStream stream = url.openStream();
|
||||
ReadableByteChannel channel = Channels.newChannel(stream);
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
out.getChannel().transferFrom(channel, 0L, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
/* Borrowed from FireFlyx ngxdev */
|
||||
public static ClassLoader injectorClassLoader = MiscUtils.class.getClassLoader();
|
||||
|
||||
/* Borrowed from FireFlyx ngxdev */
|
||||
public static void injectURL(URL url) {
|
||||
try {
|
||||
URLClassLoader systemClassLoader = (URLClassLoader) injectorClassLoader;
|
||||
Class<URLClassLoader> classLoaderClass = URLClassLoader.class;
|
||||
|
||||
try {
|
||||
Method method = classLoaderClass.getDeclaredMethod("addURL", URL.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(systemClassLoader, url);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user