-
-
Notifications
You must be signed in to change notification settings - Fork 42
API
egg82 edited this page Jan 19, 2021
·
16 revisions
The developer API is fairly simple and straight-forward, so I'll leave you with some basic documentation and some examples.
To include the plugin into your Maven project, just use the repository and link below.
<repositories>
<repository>
<id>egg82-nexus</id>
<url>https://nexus.egg82.me/repository/maven-releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>me.egg82</groupId>
<artifactId>antivpn-api</artifactId>
<version>LATEST-VERSION</version>
<scope>provided</scope>
</dependency>
</dependencies>
Link to the latest version is available here.
Javadocs are available from the same repository, so IDEs should be able to pick those up automatically.
repositories {
maven {
url 'https://nexus.egg82.me/repository/maven-releases/'
}
}
dependencies {
compileOnly 'me.egg82:antivpn-api:LATEST-VERSION'
}
Link to the latest version is available here.
Javadocs are available from the same repository, so IDEs should be able to pick those up automatically.
VPNAPI api = VPNAPIProvider.getInstance();
IPManager ipManager = VPNAPIProvider.getInstance().getIPManager();
// Get consensus value for an IP, using Anti-VPN's cache
ipManager.consensus(player.getAddress(), true).whenCompleteAsync((val, ex) -> {
if (ex != null) {
ex.printStackTrace();
return;
}
if (val != null && val >= ipManager.getMinConsensusValue()) {
// Do something
}
});
// Get consensus value for an IP, using Anti-VPN's cache
// Note: This stalls the executing thread until the result is fetched
try {
Double val = ipManager.consensus(player.getAddress(), true).get();
return ipManager.consensus(val != null && val >= ipManager.getMinConsensusValue();
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
} catch (ExecutionException | CancellationException ex) {
ex.printStackTrace();
}
// Get cascade value for an IP, using Anti-VPN's cache
ipManager.cascade(player.getAddress(), true).whenCompleteAsync((val, ex) -> {
if (ex != null) {
ex.printStackTrace();
return;
}
if (Boolean.TRUE.equals(val)) {
// Do something
}
});
// Get cascade value for an IP, using Anti-VPN's cache
// Note: This stalls the executing thread until the result is fetched
try {
return Boolean.TRUE.equals(ipManager.cascade(player.getAddress(), true).get());
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
} catch (ExecutionException | CancellationException ex) {
ex.printStackTrace();
}
// Kick a player and/or run configured commands for VPN usage
if (!ipManager.kickForVpn(player.getName(), player.getUniqueId(), player.getAddress())) {
logger.warn("Could not kick player/run commands for VPN usage.");
}
PlayerManager playerManager = VPNAPIProvider.getInstance().getPlayerManager();
// Get MCLeaks result for a player, using Anti-VPN's cache
playerManager.checkMcLeaks(player.getUniqueId(), true).whenCompleteAsync((val, ex) -> {
if (ex != null) {
ex.printStackTrace();
return;
}
if (Boolean.TRUE.equals(val)) {
// Do something
}
});
// Get MCLeaks result for a player, using Anti-VPN's cache
// Note: This stalls the executing thread until the result is fetched
try {
return Boolean.TRUE.equals(playerManager.checkMcLeaks(player.getUniqueId(), true).get());
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
} catch (ExecutionException | CancellationException ex) {
ex.printStackTrace();
}
// Kick a player and/or run configured commands for MCLeaks usage
if (!playerManager.kickForMcLeaks(player.getName(), player.getUniqueId(), player.getAddress())) {
logger.warn("Could not kick player/run commands for MCLeaks usage.");
}
SourceManager sourceManager = VPNAPIProvider.getInstance().getSourceManager();
// Try a specific source for a result
Source<GetIPIntelModel> getIpIntel = sourceManager.getSource("getipintel", GetIPIntelModel.class);
try {
return Boolean.TRUE.equals(getIpIntel.getResult(player.getAddress()).join());
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
} catch (ExecutionException | CancellationException ex) {
ex.printStackTrace();
}
// Get a raw response from a specific source
Source<GetIPIntelModel> getIpIntel = sourceManager.getSource("getipintel", GetIPIntelModel.class);
try {
return getIpIntel.getRawResponse(player.getAddress()).get();
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
} catch (ExecutionException | CancellationException ex) {
ex.printStackTrace();
}
// Add your own source (yes, this affects Anti-VPN commands and behavior as well)
if (!sourceManager.registerSource(mySource)) {
logger.error("Could not register custom source.");
}
// Remove a source (yes, this affects Anti-VPN commands and behavior as well)
if (!sourceManager.deregisterSource(source)) {
logger.error("Could not deregister source.");
}
// Get a list of all available sources
return sourceManager.getSources();
MBassador<VPNEvent> eventBus = VPNAPIProvider.getInstance().getEventBus();
// Implement listener for various events
@Listener(references = References.Strong)
class SimpleListener {
@Handler
public void handle(SourceRegisterEvent file){
// do something synchronously
}
@Handler(delivery = Invoke.Asynchronously)
public void expensiveOperation(APIReloadEvent file){
// do something asynchronously
}
}
eventBus.subscribe(new SimpleListener());
More documentation on the Mbassador event bus here.
- Home
- Why Anti-VPN?
- Installation
- Usage
- Configuration
- Languages
- Commands
- Permissions
- FAQ
- Plugin Support
- PLAN
- PlaceholderAPI
- LuckPerms/Vault