mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-06-02 18:02:20 +00:00
Refactor, code cleanup, sponge impl.
BungeeCord still has problems, bad API, not my fault technically. still need to fix though
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
package dev.brighten.antivpn.utils;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.utils.json.JSONObject;
|
||||
import dev.brighten.antivpn.utils.json.JsonReader;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -12,7 +18,7 @@ public class MiscUtils {
|
||||
try {
|
||||
for (Closeable closeable : closeables) if (closeable != null) closeable.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
AntiVPN.getInstance().getExecutor().logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +26,7 @@ public class MiscUtils {
|
||||
try {
|
||||
for (AutoCloseable closeable : closeables) if (closeable != null) closeable.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
AntiVPN.getInstance().getExecutor().logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +44,7 @@ public class MiscUtils {
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
AntiVPN.getInstance().getExecutor().logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +56,33 @@ public class MiscUtils {
|
||||
};
|
||||
}
|
||||
|
||||
public static UUID formatFromMojangUUID(String mojangUUID) {
|
||||
StringBuilder uuid = new StringBuilder();
|
||||
for(int i = 0; i <= 31; i++) {
|
||||
uuid.append(mojangUUID.charAt(i));
|
||||
if(i == 7 || i == 11 || i == 15 || i == 19) {
|
||||
uuid.append("-");
|
||||
}
|
||||
}
|
||||
|
||||
return UUID.fromString(uuid.toString());
|
||||
}
|
||||
|
||||
public static UUID lookupUUID(String playername) {
|
||||
try {
|
||||
JSONObject object = JsonReader
|
||||
.readJsonFromUrl("https://funkemunky.cc/mojang/uuid?name=" + playername);
|
||||
|
||||
if(object.has("id")) {
|
||||
return formatFromMojangUUID(object.getString("uuid"));
|
||||
}
|
||||
} catch (IOException | JSONException e) {
|
||||
AntiVPN.getInstance().getExecutor().logException("Error while looking up UUID for " + playername, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isIpv4(String ip)
|
||||
{
|
||||
return ipv4.matcher(ip).matches();
|
||||
|
||||
Reference in New Issue
Block a user