mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-05-31 09:31:54 +00:00
Updating to latest API and version of Atlas
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>funkemunky-releases</id>
|
||||
<url>http://nexus.funkemunky.cc/content/repositories/releases/</url>
|
||||
<url>https://nexus.funkemunky.cc/content/repositories/releases/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@@ -50,9 +50,9 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.funkemunky.plugins</groupId>
|
||||
<groupId>cc.funkemunky.utils</groupId>
|
||||
<artifactId>Atlas</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<version>1.8.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -4,6 +4,7 @@ import cc.funkemunky.api.Atlas;
|
||||
import cc.funkemunky.api.commands.ancmd.Command;
|
||||
import cc.funkemunky.api.commands.ancmd.CommandAdapter;
|
||||
import cc.funkemunky.api.utils.Init;
|
||||
import dev.brighten.pl.AntiVPN;
|
||||
|
||||
@Init(commands = true)
|
||||
public class VpnCommand {
|
||||
@@ -11,7 +12,7 @@ public class VpnCommand {
|
||||
@Command(name = "kaurivpn", description = "The Kauri AntiVPN main command.",
|
||||
aliases = {"antivpn"}, permission = "kvpn.command")
|
||||
public void onCommand(CommandAdapter cmd) {
|
||||
Atlas.getInstance().getCommandManager().runHelpMessage(cmd,
|
||||
cmd.getSender(), Atlas.getInstance().getCommandManager().getDefaultScheme());
|
||||
Atlas.getInstance().getCommandManager(AntiVPN.INSTANCE).runHelpMessage(cmd,
|
||||
cmd.getSender(), Atlas.getInstance().getCommandManager(AntiVPN.INSTANCE).getDefaultScheme());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import org.bukkit.entity.Player;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class VPNAPI {
|
||||
@@ -75,8 +77,10 @@ public class VPNAPI {
|
||||
return getResponse(player.getAddress().getAddress().getHostAddress());
|
||||
}
|
||||
|
||||
private Map<String, VPNResponse> cache = new ConcurrentHashMap<>();
|
||||
|
||||
public void cacheReponse(VPNResponse response) {
|
||||
if(database != null && response.isSuccess()) {
|
||||
/*if(database != null && response.isSuccess()) {
|
||||
try {
|
||||
//Removing old value if it contains it.
|
||||
if(database.contains(response.getIp())) database.remove(response.getIp());
|
||||
@@ -98,11 +102,13 @@ public class VPNAPI {
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
cache.put(response.getIp(), response);
|
||||
}
|
||||
|
||||
public VPNResponse getIfCached(String ipAddress) {
|
||||
if(database != null && database.contains(ipAddress)) {
|
||||
return cache.getOrDefault(ipAddress, null);
|
||||
/*if(database != null && database.contains(ipAddress)) {
|
||||
val list = hashAlgorithm != null
|
||||
? database.get(set -> hashAlgorithm.hashEqualsKey(set.getObject("ip"), ipAddress))
|
||||
: database.get(ipAddress);
|
||||
@@ -139,7 +145,7 @@ public class VPNAPI {
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;*/
|
||||
}
|
||||
|
||||
public VPNResponse getResponse(String ipAddress) {
|
||||
|
||||
@@ -11,10 +11,9 @@ import lombok.Setter;
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class VPNResponse {
|
||||
private String ip, countryName, countryCode, method, state, city, isp, timeZone, locationString;
|
||||
private String ip, countryName, countryCode, method, city, isp, timeZone;
|
||||
private boolean proxy, usedAdvanced, cached, success;
|
||||
private long cacheTime;
|
||||
private double score;
|
||||
private int queriesLeft;
|
||||
|
||||
public JSONObject toJson() throws JSONException {
|
||||
@@ -23,18 +22,15 @@ public class VPNResponse {
|
||||
json.put("ip", ip);
|
||||
json.put("countryName", countryName);
|
||||
json.put("countryCode", countryCode);
|
||||
json.put("state", state);
|
||||
json.put("city", city);
|
||||
json.put("method", method);
|
||||
json.put("isp", isp);
|
||||
json.put("score", score);
|
||||
json.put("proxy", proxy);
|
||||
json.put("success", success);
|
||||
json.put("cacheTime", cacheTime);
|
||||
json.put("timeZone", timeZone);
|
||||
json.put("success", true);
|
||||
json.put("queriesLeft", queriesLeft);
|
||||
json.put("locationString", locationString);
|
||||
json.put("usedAdvanced", usedAdvanced);
|
||||
json.put("cached", cached);
|
||||
|
||||
@@ -45,26 +41,23 @@ public class VPNResponse {
|
||||
JSONObject jsonObject = new JSONObject(json);
|
||||
|
||||
return new VPNResponse(jsonObject.getString("ip"), jsonObject.getString("countryName"),
|
||||
jsonObject.getString("countryCode"),
|
||||
jsonObject.has("method") ? jsonObject.getString("method") : "N/A",
|
||||
jsonObject.getString("countryCode"), jsonObject.getString("state"),
|
||||
jsonObject.getString("city"), jsonObject.getString("isp"),
|
||||
jsonObject.getString("timeZone"), jsonObject.getString("locationString"),
|
||||
jsonObject.getString("timeZone"),
|
||||
jsonObject.getBoolean("proxy"), jsonObject.getBoolean("usedAdvanced"),
|
||||
jsonObject.getBoolean("cached"), jsonObject.getBoolean("success"), -1,
|
||||
jsonObject.has("score") ? jsonObject.getDouble("score") : -1,
|
||||
jsonObject.getInt("queriesLeft"));
|
||||
}
|
||||
|
||||
public static VPNResponse fromSet(StructureSet set) {
|
||||
return new VPNResponse(set.getObject("ip"), set.getObject("countryName"),
|
||||
set.contains("method") ? set.getObject("method") : "N/A",
|
||||
set.getObject("countryCode"), set.getObject("state"),
|
||||
set.getObject("countryCode"), set.contains("method") ? set.getObject("method") : "N/A",
|
||||
set.getObject("city"), set.getObject("isp"),
|
||||
set.getObject("timeZone"), set.getObject("locationString"),
|
||||
set.getObject("timeZone"),
|
||||
set.getObject("proxy"), set.getObject("usedAdvanced"),
|
||||
set.getObject("cached"), set.getObject("success"),
|
||||
set.contains("cacheTime") ? set.getObject("cacheTime") : 01,
|
||||
set.contains("score") ? (double)set.getObject("score") : -1,
|
||||
set.getObject("queriesLeft"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user