mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-06-07 12:22:20 +00:00
Completed new antivpn plugin
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package dev.brighten.antivpn.api;
|
||||
|
||||
public interface VPNConfig {
|
||||
|
||||
String getLicense();
|
||||
|
||||
boolean cachedResults();
|
||||
|
||||
String getKickString();
|
||||
|
||||
void update();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package dev.brighten.antivpn.api;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.utils.VPNResponse;
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class VPNExecutor {
|
||||
public static ExecutorService threadExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
private static final Map<String, VPNResponse> responseCache = new HashMap<>();
|
||||
|
||||
public abstract void registerListeners();
|
||||
|
||||
public abstract void runCacheReset();
|
||||
|
||||
public void resetCache() {
|
||||
responseCache.clear();
|
||||
}
|
||||
|
||||
public abstract void shutdown();
|
||||
|
||||
public void checkIp(String ip, boolean cachedResults, Consumer<VPNResponse> result) {
|
||||
threadExecutor.execute(() -> result.accept(responseCache.compute(ip, (key, val) -> {
|
||||
if(val == null) {
|
||||
try {
|
||||
return AntiVPN.getVPNResponse(ip, AntiVPN.getInstance().getConfig().getLicense(), cachedResults);
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
})));
|
||||
}
|
||||
|
||||
public VPNResponse checkIp(String ip, boolean cachedResults) {
|
||||
return responseCache.compute(ip, (key, val) -> {
|
||||
if(val == null) {
|
||||
try {
|
||||
return AntiVPN.getVPNResponse(ip, AntiVPN.getInstance().getConfig().getLicense(), cachedResults);
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user