mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-05-31 17:31:55 +00:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| df4a14086b | |||
| f55fa88c2b | |||
| 4f79522010 | |||
| e01cbf95f2 | |||
| db49d400a0 | |||
| b39cc3e19c | |||
| ff25c75055 | |||
| 733e797a17 | |||
| 0c903794e5 | |||
| bddf26359d | |||
| 4424b2b9a5 | |||
| 60043dd07a | |||
| 314e554ce0 | |||
| 110e696995 | |||
| d12f1c983c | |||
| cf9de8115e | |||
| 338f64962e | |||
| 71604d5b45 |
@@ -13,8 +13,17 @@ jobs:
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 17.0
|
||||
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.m2
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
- name: Compile
|
||||
run: mvn -B -Pclean install
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Upload AntiVPN
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: AntiVPN
|
||||
path: Assembly/target/Assembly-*.jar
|
||||
@@ -13,6 +13,9 @@ local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
*.iml
|
||||
|
||||
.idea/
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>Assembly</artifactId>
|
||||
@@ -37,10 +37,6 @@
|
||||
<pattern>com.mysql</pattern>
|
||||
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.mysql</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.google</pattern>
|
||||
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.google</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.moandjiezana</pattern>
|
||||
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.moandjiezana</shadedPattern>
|
||||
|
||||
+1
-5
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -47,10 +47,6 @@
|
||||
<pattern>com.mysql</pattern>
|
||||
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.mysql</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.google</pattern>
|
||||
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.google</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.moandjiezana</pattern>
|
||||
<shadedPattern>dev.brighten.antivpn.utils.shaded.com.moandjiezana</shadedPattern>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>Bukkit</artifactId>
|
||||
@@ -56,7 +56,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<artifactId>Common</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<artifactId>Common</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -2,7 +2,6 @@ package dev.brighten.antivpn.bukkit;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.api.APIPlayer;
|
||||
import dev.brighten.antivpn.api.PlayerExecutor;
|
||||
import dev.brighten.antivpn.command.CommandExecutor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -17,8 +16,9 @@ public class BukkitCommandExecutor implements CommandExecutor {
|
||||
private final CommandSender sender;
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
|
||||
public void sendMessage(String message, Object... objects) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
String.format(message, objects)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,22 +4,18 @@ import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.api.APIPlayer;
|
||||
import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import dev.brighten.antivpn.message.VpnString;
|
||||
import lombok.val;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class BukkitListener extends VPNExecutor implements Listener {
|
||||
@@ -89,6 +85,12 @@ public class BukkitListener extends VPNExecutor implements Listener {
|
||||
// If the countryList() size is zero, no need to check.
|
||||
// Running country check first
|
||||
if(AntiVPN.getInstance().getVpnConfig().countryList().size() > 0
|
||||
&& !(AntiVPN.getInstance().getExecutor()
|
||||
.isWhitelisted(event.getPlayer().getUniqueId()) //Is exempt
|
||||
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer()
|
||||
.getAddress().getAddress()
|
||||
.getHostAddress()))
|
||||
// This bit of code will decide whether or not to kick the player
|
||||
// If it contains the code and it is set to whitelist, it will not kick as they are equal
|
||||
// and vise versa. However, if the contains does not match the state, it will kick.
|
||||
@@ -156,4 +158,9 @@ public class BukkitListener extends VPNExecutor implements Listener {
|
||||
AntiVPN.getInstance().checked++;
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
AntiVPN.getInstance().getPlayerExecutor().unloadPlayer(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package dev.brighten.antivpn.bukkit;
|
||||
import dev.brighten.antivpn.api.APIPlayer;
|
||||
import dev.brighten.antivpn.api.PlayerExecutor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
@@ -11,7 +10,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class BukkitPlayerExecutor implements PlayerExecutor {
|
||||
|
||||
private final Map<UUID, BukkitPlayer> cachedPlayers = new WeakHashMap<>();
|
||||
private final Map<UUID, BukkitPlayer> cachedPlayers = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Optional<APIPlayer> getPlayer(String name) {
|
||||
@@ -35,6 +34,11 @@ public class BukkitPlayerExecutor implements PlayerExecutor {
|
||||
return Optional.of(cachedPlayers.computeIfAbsent(player.getUniqueId(), k -> new BukkitPlayer(player)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadPlayer(UUID uuid) {
|
||||
cachedPlayers.remove(uuid);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<APIPlayer> getOnlinePlayers() {
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
package dev.brighten.antivpn.bukkit;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.bukkit.command.BukkitCommand;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||
import dev.brighten.antivpn.utils.MiscUtils;
|
||||
import dev.brighten.antivpn.utils.config.Configuration;
|
||||
import lombok.val;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SingleLineChart;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BukkitPlugin extends JavaPlugin {
|
||||
|
||||
@@ -35,18 +28,10 @@ public class BukkitPlugin extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
pluginInstance = this;
|
||||
|
||||
//Loading config
|
||||
Bukkit.getLogger().info("Loading config...");
|
||||
Configuration config = new Configuration();
|
||||
File configFile = new File(getDataFolder(), "config.yml");
|
||||
if(!configFile.exists()){
|
||||
configFile.getParentFile().mkdirs();
|
||||
MiscUtils.copy(getResource( "config.yml"), configFile);
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("Starting AntiVPN services...");
|
||||
AntiVPN.start(new BukkitListener(), new BukkitPlayerExecutor(), getDataFolder());
|
||||
|
||||
// Loading our bStats metrics to be pushed to https://bstats.org
|
||||
if(AntiVPN.getInstance().getVpnConfig().metrics()) {
|
||||
Bukkit.getLogger().info("Starting bStats metrics...");
|
||||
Metrics metrics = new Metrics(this, 12615);
|
||||
@@ -62,6 +47,7 @@ public class BukkitPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("Setting up and registering commands...");
|
||||
// We need access to the commandMap to register our commands without using the "proper" method
|
||||
if (pluginInstance.getServer().getPluginManager() instanceof SimplePluginManager) {
|
||||
SimplePluginManager manager = (SimplePluginManager) pluginInstance.getServer().getPluginManager();
|
||||
try {
|
||||
@@ -73,70 +59,18 @@ public class BukkitPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// Registering commands
|
||||
for (Command command : AntiVPN.getInstance().getCommands()) {
|
||||
val newCommand = new org.bukkit.command.Command(command.name(), command.description(), command.usage(),
|
||||
Arrays.asList(command.aliases())) {
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
|
||||
throws IllegalArgumentException {
|
||||
val children = command.children();
|
||||
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases())
|
||||
.anyMatch(alias2 -> alias2.equalsIgnoreCase(args[0]))) {
|
||||
return child.tabComplete(new BukkitCommandExecutor(sender), alias, IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new));
|
||||
}
|
||||
}
|
||||
}
|
||||
return command.tabComplete(new BukkitCommandExecutor(sender), alias, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String s, String[] args) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(command.permission())) {
|
||||
sender.sendMessage(ChatColor.RED + "No permission.");
|
||||
return true;
|
||||
}
|
||||
|
||||
val children = command.children();
|
||||
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases())
|
||||
.anyMatch(alias -> alias.equalsIgnoreCase(args[0]))) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(child.permission())) {
|
||||
sender.sendMessage(ChatColor.RED + "No permission.");
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
child.execute(new BukkitCommandExecutor(sender), IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new))));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
command.execute(new BukkitCommandExecutor(sender), args)));
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
// Wraps our general command API to Bukkit specific calls
|
||||
BukkitCommand newCommand = new BukkitCommand(command);
|
||||
|
||||
// Adding to our own list for later referencing
|
||||
registeredCommands.add(newCommand);
|
||||
|
||||
// This tells Bukkit to register our command for use.
|
||||
commandMap.register(pluginInstance.getName(), newCommand);
|
||||
}
|
||||
|
||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), AntiVPN.getInstance())
|
||||
.get());
|
||||
//TODO Finish system before implementing on startup
|
||||
/*Bukkit.getLogger().info("Getting strings...");
|
||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package dev.brighten.antivpn.bukkit.command;
|
||||
|
||||
import dev.brighten.antivpn.bukkit.BukkitCommandExecutor;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import lombok.val;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BukkitCommand extends org.bukkit.command.Command {
|
||||
|
||||
private final Command command;
|
||||
public BukkitCommand(Command command) {
|
||||
super(command.name(), command.description(), command.usage(), Arrays.asList(command.aliases()));
|
||||
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
|
||||
throws IllegalArgumentException {
|
||||
val children = command.children();
|
||||
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases())
|
||||
.anyMatch(alias2 -> alias2.equalsIgnoreCase(args[0]))) {
|
||||
return child.tabComplete(new BukkitCommandExecutor(sender), alias, IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new));
|
||||
}
|
||||
}
|
||||
}
|
||||
return command.tabComplete(new BukkitCommandExecutor(sender), alias, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String s, String[] args) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(command.permission())) {
|
||||
sender.sendMessage(ChatColor.RED + "No permission.");
|
||||
return true;
|
||||
}
|
||||
|
||||
val children = command.children();
|
||||
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases())
|
||||
.anyMatch(alias -> alias.equalsIgnoreCase(args[0]))) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(child.permission())) {
|
||||
sender.sendMessage(ChatColor.RED + "No permission.");
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
child.execute(new BukkitCommandExecutor(sender), IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new))));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
command.execute(new BukkitCommandExecutor(sender), args)));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>Bungee</artifactId>
|
||||
@@ -50,7 +50,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<artifactId>Common</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<artifactId>Common</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
@@ -48,10 +49,6 @@ public class BungeeListener extends VPNExecutor implements Listener {
|
||||
@EventHandler
|
||||
public void onListener(final PostLoginEvent event) {
|
||||
if(event.getPlayer().hasPermission("antivpn.bypass") //Has bypass permission
|
||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId()) //Is exempt
|
||||
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getAddress().getAddress()
|
||||
.getHostAddress())
|
||||
|| AntiVPN.getInstance().getVpnConfig().getPrefixWhitelists().stream()
|
||||
.anyMatch(prefix -> event.getPlayer().getName().startsWith(prefix))) return;
|
||||
|
||||
@@ -61,6 +58,10 @@ public class BungeeListener extends VPNExecutor implements Listener {
|
||||
// If the countryList() size is zero, no need to check.
|
||||
// Running country check first
|
||||
if(AntiVPN.getInstance().getVpnConfig().countryList().size() > 0
|
||||
&& !(AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId()) //Is exempt
|
||||
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getAddress().getAddress()
|
||||
.getHostAddress()))
|
||||
// This bit of code will decide whether or not to kick the player
|
||||
// If it contains the code and it is set to whitelist, it will not kick as they are equal
|
||||
// and vise versa. However, if the contains does not match the state, it will kick.
|
||||
@@ -127,4 +128,9 @@ public class BungeeListener extends VPNExecutor implements Listener {
|
||||
AntiVPN.getInstance().checked++;
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeave(PlayerDisconnectEvent event) {
|
||||
AntiVPN.getInstance().getPlayerExecutor().unloadPlayer(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class BungeePlayerExecutor implements PlayerExecutor {
|
||||
|
||||
private final Map<ProxiedPlayer, BungeePlayer> cachedPlayers = new WeakHashMap<>();
|
||||
private final Map<UUID, BungeePlayer> cachedPlayers = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Optional<APIPlayer> getPlayer(String name) {
|
||||
@@ -18,7 +18,7 @@ public class BungeePlayerExecutor implements PlayerExecutor {
|
||||
|
||||
if(player == null) return Optional.empty();
|
||||
|
||||
return Optional.of(cachedPlayers.computeIfAbsent(player, BungeePlayer::new));
|
||||
return Optional.of(cachedPlayers.computeIfAbsent(player.getUniqueId(), key -> new BungeePlayer(player)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,13 +27,18 @@ public class BungeePlayerExecutor implements PlayerExecutor {
|
||||
|
||||
if(player == null) return Optional.empty();
|
||||
|
||||
return Optional.of(cachedPlayers.computeIfAbsent(player, BungeePlayer::new));
|
||||
return Optional.of(cachedPlayers.computeIfAbsent(uuid, key -> new BungeePlayer(player)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadPlayer(UUID uuid) {
|
||||
this.cachedPlayers.remove(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<APIPlayer> getOnlinePlayers() {
|
||||
return BungeeCord.getInstance().getPlayers().stream()
|
||||
.map(pl -> cachedPlayers.computeIfAbsent(pl, BungeePlayer::new))
|
||||
.map(pl -> cachedPlayers.computeIfAbsent(pl.getUniqueId(), key -> new BungeePlayer(pl)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
package dev.brighten.antivpn.bungee;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.bungee.command.BungeeCommand;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||
import lombok.val;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
import org.bstats.charts.SingleLineChart;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BungeePlugin extends Plugin {
|
||||
|
||||
@@ -24,9 +17,6 @@ public class BungeePlugin extends Plugin {
|
||||
|
||||
private SingleLineChart vpnDetections, ipsChecked;
|
||||
|
||||
private static final BaseComponent[] noPermission = new ComponentBuilder("No permission").color(ChatColor.RED)
|
||||
.create();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
pluginInstance = this;
|
||||
@@ -51,61 +41,14 @@ public class BungeePlugin extends Plugin {
|
||||
10, 10, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
//TODO Add command functionality for BungeeCord
|
||||
for (Command command : AntiVPN.getInstance().getCommands()) {
|
||||
BungeeCord.getInstance().getPluginManager().registerCommand(pluginInstance, new net.md_5.bungee.api.plugin
|
||||
.Command(command.name(), command.permission(), command.aliases()) {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(command.permission())) {
|
||||
sender.sendMessage(noPermission);
|
||||
return;
|
||||
}
|
||||
|
||||
val children = command.children();
|
||||
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases())
|
||||
.anyMatch(alias -> alias.equalsIgnoreCase(args[0]))) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(child.permission())) {
|
||||
sender.sendMessage(noPermission);
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(TextComponent
|
||||
.fromLegacyText(ChatColor
|
||||
.translateAlternateColorCodes('&',
|
||||
child.execute(new BungeeCommandExecutor(sender), IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new)))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sender.sendMessage(TextComponent
|
||||
.fromLegacyText(ChatColor
|
||||
.translateAlternateColorCodes('&',
|
||||
command.execute(new BungeeCommandExecutor(sender), args))));
|
||||
}
|
||||
});
|
||||
BungeeCord.getInstance().getPluginManager().registerCommand(pluginInstance, new BungeeCommand(command));
|
||||
}
|
||||
|
||||
BungeeCord.getInstance().getLogger().info("Getting strings...");
|
||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), AntiVPN.getInstance())
|
||||
.get());
|
||||
//TODO Finish system before implementing on startup
|
||||
/*BungeeCord.getInstance().getLogger().info("Getting strings...");
|
||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), BungeePlugin.pluginInstance)
|
||||
.get());
|
||||
AntiVPN.getInstance().getMessageHandler().reloadStrings();*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package dev.brighten.antivpn.bungee.command;
|
||||
|
||||
import lombok.val;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BungeeCommand extends Command implements TabExecutor {
|
||||
|
||||
private static final BaseComponent[] noPermission = new ComponentBuilder("No permission").color(ChatColor.RED)
|
||||
.create();
|
||||
|
||||
private final dev.brighten.antivpn.command.Command command;
|
||||
public BungeeCommand(dev.brighten.antivpn.command.Command command) {
|
||||
super(command.name(), command.permission(), command.aliases());
|
||||
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(command.permission())) {
|
||||
sender.sendMessage(noPermission);
|
||||
return;
|
||||
}
|
||||
|
||||
val children = command.children();
|
||||
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (dev.brighten.antivpn.command.Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases())
|
||||
.anyMatch(alias -> alias.equalsIgnoreCase(args[0]))) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(child.permission())) {
|
||||
sender.sendMessage(noPermission);
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(TextComponent
|
||||
.fromLegacyText(ChatColor
|
||||
.translateAlternateColorCodes('&',
|
||||
child.execute(new BungeeCommandExecutor(sender), IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new)))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sender.sendMessage(TextComponent
|
||||
.fromLegacyText(ChatColor
|
||||
.translateAlternateColorCodes('&',
|
||||
command.execute(new BungeeCommandExecutor(sender), args))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
val children = command.children();
|
||||
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (dev.brighten.antivpn.command.Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases())
|
||||
.anyMatch(alias2 -> alias2.equalsIgnoreCase(args[0]))) {
|
||||
return child.tabComplete(new BungeeCommandExecutor(sender), "alias", IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new));
|
||||
}
|
||||
}
|
||||
}
|
||||
return command.tabComplete(new BungeeCommandExecutor(sender), "alias", args);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package dev.brighten.antivpn.bungee;
|
||||
package dev.brighten.antivpn.bungee.command;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.api.APIPlayer;
|
||||
@@ -17,9 +17,9 @@ public class BungeeCommandExecutor implements CommandExecutor {
|
||||
private final CommandSender sender;
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
public void sendMessage(String message, Object... objects) {
|
||||
sender.sendMessage(TextComponent.fromLegacyText(ChatColor
|
||||
.translateAlternateColorCodes('&', message)));
|
||||
.translateAlternateColorCodes('&', String.format(message, objects))));
|
||||
}
|
||||
|
||||
@Override
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.27</version>
|
||||
<version>8.0.28</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -6,17 +6,15 @@ import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import dev.brighten.antivpn.command.impl.AntiVPNCommand;
|
||||
import dev.brighten.antivpn.database.VPNDatabase;
|
||||
import dev.brighten.antivpn.database.local.H2VPN;
|
||||
import dev.brighten.antivpn.database.mongo.MongoVPN;
|
||||
import dev.brighten.antivpn.database.sql.MySqlVPN;
|
||||
import dev.brighten.antivpn.message.MessageHandler;
|
||||
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||
import dev.brighten.antivpn.utils.MiscUtils;
|
||||
import dev.brighten.antivpn.utils.VPNResponse;
|
||||
import dev.brighten.antivpn.utils.config.Configuration;
|
||||
import dev.brighten.antivpn.utils.config.ConfigurationProvider;
|
||||
import dev.brighten.antivpn.utils.config.YamlConfiguration;
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.utils.json.JSONObject;
|
||||
import dev.brighten.antivpn.utils.json.JsonReader;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -72,8 +70,15 @@ public class AntiVPN {
|
||||
INSTANCE.messageHandler = new MessageHandler();
|
||||
|
||||
switch(INSTANCE.vpnConfig.getDatabaseType().toLowerCase()) {
|
||||
case "mysql":
|
||||
case "h2":
|
||||
case "local":
|
||||
case "flatfile": {
|
||||
AntiVPN.getInstance().getExecutor().log("Using databaseType H2...");
|
||||
INSTANCE.database = new H2VPN();
|
||||
INSTANCE.database.init();
|
||||
break;
|
||||
}
|
||||
case "mysql":
|
||||
case "sql":{
|
||||
AntiVPN.getInstance().getExecutor().log("Using databaseType MySQL...");
|
||||
INSTANCE.database = new MySqlVPN();
|
||||
@@ -106,6 +111,10 @@ public class AntiVPN {
|
||||
INSTANCE.database.alertsState(player.getUuid(), player::setAlertsEnabled);
|
||||
}
|
||||
});
|
||||
|
||||
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
|
||||
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), AntiVPN.getInstance())
|
||||
.get());
|
||||
}
|
||||
|
||||
public InputStream getResource(String filename) {
|
||||
@@ -147,15 +156,6 @@ public class AntiVPN {
|
||||
}
|
||||
}
|
||||
|
||||
public static VPNResponse getVPNResponse(String ip, String license, boolean cachedResults /* faster if set to true*/)
|
||||
throws JSONException, IOException {
|
||||
JSONObject result = JsonReader.readJsonFromUrl(String
|
||||
.format("https://funkemunky.cc/vpn?ip=%s&license=%s&cache=%s",
|
||||
ip, license.length() == 0 ? "none" : license, cachedResults));
|
||||
|
||||
return VPNResponse.fromJson(result);
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
commands.add(new AntiVPNCommand());
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package dev.brighten.antivpn.api;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.message.VpnString;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -10,5 +10,7 @@ public interface PlayerExecutor {
|
||||
|
||||
Optional<APIPlayer> getPlayer(UUID uuid);
|
||||
|
||||
void unloadPlayer(UUID uuid);
|
||||
|
||||
List<APIPlayer> getOnlinePlayers();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -2,15 +2,15 @@ package dev.brighten.antivpn.api;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.utils.EvictingMap;
|
||||
import dev.brighten.antivpn.utils.VPNResponse;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.web.FunkemunkyAPI;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class VPNExecutor {
|
||||
@@ -35,10 +35,16 @@ public abstract class VPNExecutor {
|
||||
public abstract void log(String log, Object... objects);
|
||||
|
||||
public boolean isWhitelisted(UUID uuid) {
|
||||
if(AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()) {
|
||||
return AntiVPN.getInstance().getDatabase().isWhitelisted(uuid);
|
||||
}
|
||||
return whitelisted.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean isWhitelisted(String ip) {
|
||||
if(AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()) {
|
||||
return AntiVPN.getInstance().getDatabase().isWhitelisted(ip);
|
||||
}
|
||||
return whitelistedIps.contains(ip);
|
||||
}
|
||||
|
||||
@@ -50,7 +56,7 @@ public abstract class VPNExecutor {
|
||||
if(cachedRes.isPresent()) return cachedRes.get();
|
||||
else {
|
||||
try {
|
||||
VPNResponse response = AntiVPN
|
||||
VPNResponse response = FunkemunkyAPI
|
||||
.getVPNResponse(ip, AntiVPN.getInstance().getVpnConfig().getLicense(), cachedResults);
|
||||
|
||||
if(response.isSuccess()) {
|
||||
@@ -79,7 +85,7 @@ public abstract class VPNExecutor {
|
||||
if(cachedRes.isPresent()) return cachedRes.get();
|
||||
else {
|
||||
try {
|
||||
VPNResponse response = AntiVPN
|
||||
VPNResponse response = FunkemunkyAPI
|
||||
.getVPNResponse(ip, AntiVPN.getInstance().getVpnConfig().getLicense(), cachedResults);
|
||||
|
||||
if(response.isSuccess()) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package dev.brighten.antivpn.command;
|
||||
|
||||
import dev.brighten.antivpn.api.APIPlayer;
|
||||
import dev.brighten.antivpn.api.PlayerExecutor;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CommandExecutor {
|
||||
|
||||
void sendMessage(String message);
|
||||
void sendMessage(String message, Object... objects);
|
||||
boolean hasPermission(String permission);
|
||||
Optional<APIPlayer> getPlayer();
|
||||
boolean isPlayer();
|
||||
|
||||
@@ -5,7 +5,10 @@ import dev.brighten.antivpn.command.Command;
|
||||
import dev.brighten.antivpn.command.CommandExecutor;
|
||||
import dev.brighten.antivpn.utils.StringUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AntiVPNCommand extends Command {
|
||||
@@ -42,7 +45,7 @@ public class AntiVPNCommand extends Command {
|
||||
@Override
|
||||
public Command[] children() {
|
||||
return new Command[] {new LookupCommand(), new AllowlistCommand(), new AlertsCommand(),
|
||||
new ClearCacheCommand()};
|
||||
new ClearCacheCommand(), new PlanCommand()};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,7 +8,6 @@ import dev.brighten.antivpn.utils.StringUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -68,13 +67,13 @@ public class LookupCommand extends Command {
|
||||
executor.sendMessage(StringUtil.line("&8"));
|
||||
executor.sendMessage("&6&l" + player.get().getName() + "&7&l's Connection Information");
|
||||
executor.sendMessage("");
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "Proxy", result.isProxy()
|
||||
? "&a" + result.getMethod() : "&cNo"));
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "ISP", result.getIsp()));
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "Country", result.getCountryName()));
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "City", result.getCity()));
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "Coordinates", result.getLatitude()
|
||||
+ "&7/&f" + result.getLongitude()));
|
||||
executor.sendMessage("&e%s&8: &f%s", "Proxy", result.isProxy()
|
||||
? "&a" + result.getMethod() : "&cNo");
|
||||
executor.sendMessage("&e%s&8: &f%s", "ISP", result.getIsp());
|
||||
executor.sendMessage("&e%s&8: &f%s", "Country", result.getCountryName());
|
||||
executor.sendMessage("&e%s&8: &f%s", "City", result.getCity());
|
||||
executor.sendMessage("&e%s&8: &f%s", "Coordinates", result.getLatitude()
|
||||
+ "&7/&f" + result.getLongitude());
|
||||
executor.sendMessage(StringUtil.line("&8"));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package dev.brighten.antivpn.command.impl;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import dev.brighten.antivpn.command.CommandExecutor;
|
||||
import dev.brighten.antivpn.utils.StringUtil;
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.web.FunkemunkyAPI;
|
||||
import dev.brighten.antivpn.web.objects.QueryResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class PlanCommand extends Command {
|
||||
@Override
|
||||
public String permission() {
|
||||
return "antivpn.command.plan";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "plan";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] aliases() {
|
||||
return new String[] {"queries", "query"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Info related to KauriVPN Plan";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String usage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parent() {
|
||||
return "antivpn";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command[] children() {
|
||||
return new Command[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(CommandExecutor executor, String[] args) {
|
||||
VPNExecutor.threadExecutor.execute(() -> {
|
||||
QueryResponse result;
|
||||
try {
|
||||
if(AntiVPN.getInstance().getVpnConfig().getLicense().equals("")) {
|
||||
result = FunkemunkyAPI.getQueryResponse();
|
||||
} else {
|
||||
result = FunkemunkyAPI.getQueryResponse(AntiVPN.getInstance().getVpnConfig().getLicense());
|
||||
|
||||
if(!result.isValidPlan()) {
|
||||
executor.sendMessage("&cThe license &f%s &cis not a valid license, " +
|
||||
"checking your Free plan information...",
|
||||
AntiVPN.getInstance().getVpnConfig().getLicense());
|
||||
|
||||
result = FunkemunkyAPI.getQueryResponse();
|
||||
}
|
||||
}
|
||||
|
||||
String plan = result.getPlanType();
|
||||
if(plan.equals("IP")) plan+= " (Free)";
|
||||
|
||||
String queryMax = result.getQueriesMax() == Long.MAX_VALUE
|
||||
? "Unlimited" : String.valueOf(result.getQueriesMax());
|
||||
|
||||
executor.sendMessage(StringUtil.line("&8"));
|
||||
executor.sendMessage("&6&lKauriVPN Plan Information");
|
||||
executor.sendMessage("");
|
||||
executor.sendMessage("&e%s&8: &f%s", "Plan", plan);
|
||||
executor.sendMessage("&e%s&8: &f%s&7/&f%s", "Queries Used",
|
||||
result.getQueries(), queryMax);
|
||||
executor.sendMessage(StringUtil.line("&8"));
|
||||
} catch(JSONException e) {
|
||||
e.printStackTrace();
|
||||
executor.sendMessage("&cThere was a JSONException thrown while looking up your query " +
|
||||
"information. Check console for more details.");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
executor.sendMessage("&cThere was a IOException thrown while looking up your query " +
|
||||
"information. Check console for more details.");
|
||||
}
|
||||
});
|
||||
return "&7Looking up your query information...";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandExecutor executor, String alias, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.brighten.antivpn.database;
|
||||
|
||||
import dev.brighten.antivpn.utils.VPNResponse;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
package dev.brighten.antivpn.database.local;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import dev.brighten.antivpn.database.VPNDatabase;
|
||||
import dev.brighten.antivpn.database.sql.utils.MySQL;
|
||||
import dev.brighten.antivpn.database.sql.utils.Query;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class H2VPN implements VPNDatabase {
|
||||
|
||||
private Thread whitelistedThread;
|
||||
|
||||
public H2VPN() {
|
||||
whitelistedThread = new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
while (true) {
|
||||
// Updating from database
|
||||
if (AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()) {
|
||||
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));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
whitelistedThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<VPNResponse> getStoredResponse(String ip) {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()|| MySQL.isClosed())
|
||||
return Optional.empty();
|
||||
|
||||
ResultSet rs = Query.prepare("select * from `responses` where `ip` = ? limit 1").append(ip).executeQuery();
|
||||
|
||||
try {
|
||||
if (rs != null && rs.next()) {
|
||||
VPNResponse response = new VPNResponse(rs.getString("asn"), rs.getString("ip"),
|
||||
rs.getString("countryName"), rs.getString("countryCode"),
|
||||
rs.getString("city"), rs.getString("timeZone"),
|
||||
rs.getString("method"), rs.getString("isp"), "N/A",
|
||||
rs.getBoolean("proxy"), rs.getBoolean("cached"), true,
|
||||
rs.getDouble("latitude"), rs.getDouble("longitude"),
|
||||
System.currentTimeMillis(), -1);
|
||||
return Optional.of(response);
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/*
|
||||
* Query.
|
||||
* prepare("create table if not exists `responses` (`ip` varchar(45) not null, "
|
||||
* +
|
||||
* "`countryName` varchar(64), `countryCode` varchar(10), `city` varchar(64), `timeZone` varchar(64), "
|
||||
* +
|
||||
* "`method` varchar(32), `isp` varchar(32), `proxy` boolean, `cached` boolean "
|
||||
* + "`latitude` double, `longitude` double)");
|
||||
*/
|
||||
@Override
|
||||
public void cacheResponse(VPNResponse toCache) {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||
return;
|
||||
|
||||
Query.prepare("insert into `responses` (`ip`,`asn`,`countryName`,`countryCode`,`city`,`timeZone`,"
|
||||
+ "`method`,`isp`,`proxy`,`cached`,`inserted`,`latitude`,`longitude`) values (?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
||||
.append(toCache.getIp()).append(toCache.getAsn()).append(toCache.getCountryName())
|
||||
.append(toCache.getCountryCode()).append(toCache.getCity()).append(toCache.getTimeZone())
|
||||
.append(toCache.getMethod()).append(toCache.getIsp()).append(toCache.isProxy())
|
||||
.append(toCache.isCached()).append(new Timestamp(System.currentTimeMillis()))
|
||||
.append(toCache.getLatitude()).append(toCache.getLongitude()).execute();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public boolean isWhitelisted(UUID uuid) {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||
return false;
|
||||
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().getVpnConfig().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 (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||
return;
|
||||
|
||||
if (whitelisted) {
|
||||
if (!isWhitelisted(uuid)) {
|
||||
Query.prepare("insert into `whitelisted` (`uuid`) values (?)").append(uuid.toString()).execute();
|
||||
}
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().add(uuid);
|
||||
} else {
|
||||
Query.prepare("delete from `whitelisted` where `uuid` = ?").append(uuid.toString()).execute();
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhitelisted(String ip, boolean whitelisted) {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().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()) Query.prepare("select uuid from `whitelisted`")
|
||||
.execute(set -> uuids.add(UUID.fromString(set.getString("uuid"))));
|
||||
|
||||
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;
|
||||
|
||||
VPNExecutor.threadExecutor.execute(() -> result.accept(getStoredResponse(ip)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isWhitelistedAsync(UUID uuid, Consumer<Boolean> result) {
|
||||
if(MySQL.isClosed()) return;
|
||||
|
||||
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;
|
||||
|
||||
VPNExecutor.threadExecutor.execute(() -> {
|
||||
ResultSet set = Query.prepare("select * from `alerts` where `uuid` = ? limit 1")
|
||||
.append(uuid.toString()).executeQuery();
|
||||
|
||||
try {
|
||||
result.accept(set != null && set.next() && set.getString("uuid") != null);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
result.accept(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAlertsState(UUID uuid, boolean enabled) {
|
||||
if(MySQL.isClosed()) return;
|
||||
|
||||
if(enabled) {
|
||||
//We want to make sure there isn't already a uuid inserted to prevent double insertions
|
||||
alertsState(uuid, alreadyEnabled -> { //No need to make another thread execute, already async
|
||||
if(!alreadyEnabled) {
|
||||
Query.prepare("insert into `alerts` (`uuid`) values (?)").append(uuid.toString())
|
||||
.execute();
|
||||
} //No need to insert again of already enabled
|
||||
});
|
||||
//Removing any uuid from the alerts table will disable alerts globally.
|
||||
} else VPNExecutor.threadExecutor.execute(() ->
|
||||
Query.prepare("delete from `alerts` where `uuid` = ?")
|
||||
.append(uuid.toString())
|
||||
.execute());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearResponses() {
|
||||
if(MySQL.isClosed()) return;
|
||||
|
||||
VPNExecutor.threadExecutor.execute(() -> Query.prepare("delete from `responses`").execute());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled())
|
||||
return;
|
||||
AntiVPN.getInstance().getExecutor().log("Initializing H2...");
|
||||
MySQL.initH2();
|
||||
|
||||
AntiVPN.getInstance().getExecutor().log("Creating tables...");
|
||||
|
||||
//Running check for old table types to update
|
||||
|
||||
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,"
|
||||
+ "`latitude` double, `longitude` double)").execute();
|
||||
Query.prepare("create table if not exists `alerts` (`uuid` varchar(36) not null)").execute();
|
||||
|
||||
AntiVPN.getInstance().getExecutor().log("Creating indexes...");
|
||||
try {
|
||||
Query.prepare("create index `uuid_1` if not exists on `whitelisted` (`uuid`)").execute();
|
||||
Query.prepare("create index `ip_1` if not exists on `responses` (`ip`)").execute();
|
||||
Query.prepare("create index `proxy_1` if not exists on `responses` (`proxy`)").execute();
|
||||
Query.prepare("create index `inserted_1` if not exists on `responses` (`inserted`)").execute();
|
||||
Query.prepare("create index `ip_1` if not exists on `whitelisted-ips` (`ip`)").execute();
|
||||
} catch (Exception e) {
|
||||
System.err.println("MySQL Excepton created" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled())
|
||||
return;
|
||||
MySQL.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import com.mongodb.client.model.Indexes;
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import dev.brighten.antivpn.database.VPNDatabase;
|
||||
import dev.brighten.antivpn.utils.VPNResponse;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.*;
|
||||
@@ -86,8 +86,10 @@ public class MongoVPN implements VPNDatabase {
|
||||
if(whitelisted) {
|
||||
Document wdoc = new Document("setting", "whitelist");
|
||||
wdoc.put("uuid", uuid.toString());
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().add(uuid);
|
||||
VPNExecutor.threadExecutor.execute(() -> settingsDocument.insertOne(wdoc));
|
||||
} else {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelisted().remove(uuid);
|
||||
VPNExecutor.threadExecutor.execute(() -> settingsDocument.deleteMany(Filters
|
||||
.and(
|
||||
Filters.eq("setting", "whitelist"),
|
||||
@@ -100,8 +102,10 @@ public class MongoVPN implements VPNDatabase {
|
||||
if(whitelisted) {
|
||||
Document wdoc = new Document("setting", "whitelist");
|
||||
wdoc.put("ip", ip);
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps().add(ip);
|
||||
VPNExecutor.threadExecutor.execute(() -> settingsDocument.insertOne(wdoc));
|
||||
} else {
|
||||
AntiVPN.getInstance().getExecutor().getWhitelistedIps().remove(ip);
|
||||
VPNExecutor.threadExecutor.execute(() -> settingsDocument.deleteMany(Filters
|
||||
.and(
|
||||
Filters.eq("setting", "whitelist"),
|
||||
|
||||
@@ -5,11 +5,16 @@ import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import dev.brighten.antivpn.database.VPNDatabase;
|
||||
import dev.brighten.antivpn.database.sql.utils.MySQL;
|
||||
import dev.brighten.antivpn.database.sql.utils.Query;
|
||||
import dev.brighten.antivpn.utils.VPNResponse;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -237,9 +242,7 @@ public class MySqlVPN implements VPNDatabase {
|
||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled())
|
||||
return;
|
||||
AntiVPN.getInstance().getExecutor().log("Initializing MySQL...");
|
||||
if(AntiVPN.getInstance().getVpnConfig().getDatabaseType().contains("sql")) {
|
||||
MySQL.init();
|
||||
} else MySQL.initH2();
|
||||
MySQL.init();
|
||||
|
||||
AntiVPN.getInstance().getExecutor().log("Creating tables...");
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package dev.brighten.antivpn.database.sql.utils;
|
||||
|
||||
import org.h2.jdbc.JdbcConnection;
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MySQL {
|
||||
private static Connection conn;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package dev.brighten.antivpn.message;
|
||||
|
||||
import dev.brighten.antivpn.api.APIPlayer;
|
||||
import lombok.*;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
package dev.brighten.antivpn.utils;
|
||||
|
||||
import java.io.*;
|
||||
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;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MiscUtils {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package dev.brighten.antivpn.web;
|
||||
|
||||
import dev.brighten.antivpn.web.objects.QueryResponse;
|
||||
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.utils.json.JSONObject;
|
||||
import dev.brighten.antivpn.utils.json.JsonReader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FunkemunkyAPI {
|
||||
|
||||
/**
|
||||
*
|
||||
* Queries https://funkemunky.cc/vpn API and returns information on the IP
|
||||
*
|
||||
* @param ip String
|
||||
* @param license String
|
||||
* @param cachedResults boolean
|
||||
* @return VPNResponse
|
||||
* @throws JSONException Throws when JSON response is not formatted properly.
|
||||
* @throws IOException Throws when there is an error connecting to and processing information from API.
|
||||
*/
|
||||
public static VPNResponse getVPNResponse(String ip, String license, boolean cachedResults /* faster if set to true*/)
|
||||
throws JSONException, IOException {
|
||||
JSONObject result = JsonReader.readJsonFromUrl(String
|
||||
.format("https://funkemunky.cc/vpn?ip=%s&license=%s&cache=%s",
|
||||
ip, license.length() == 0 ? "none" : license, cachedResults));
|
||||
|
||||
return VPNResponse.fromJson(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Feeds into {@link FunkemunkyAPI#getQueryResponse(String)} using "none" as argument
|
||||
* to grab query information based on the connecting IP address.
|
||||
*
|
||||
* @return QueryResponse
|
||||
* @throws JSONException Throws when JSON response is not formatted properly.
|
||||
* @throws IOException Throws when there is an error connecting to and processing information from API.
|
||||
*/
|
||||
public static QueryResponse getQueryResponse() throws JSONException, IOException {
|
||||
return getQueryResponse("none");
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries https://funkemunky.cc/vpn/queryCheck and returns information based on the
|
||||
* provided licence input.
|
||||
*
|
||||
* @param license String
|
||||
* @return QueryResponse
|
||||
* @throws JSONException Throws when JSON response is not formatted properly.
|
||||
* @throws IOException Throws when there is an error connecting to and processing information from API.
|
||||
*/
|
||||
public static QueryResponse getQueryResponse(String license) throws JSONException, IOException {
|
||||
JSONObject result = JsonReader.readJsonFromUrl("https://funkemunky.cc/vpn/queryCheck?license=" + license);
|
||||
|
||||
return QueryResponse.fromJson(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package dev.brighten.antivpn.web.objects;
|
||||
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.utils.json.JSONObject;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* Used to format the JSON response from https://funkemunky.cc/vpn/queryCheck into an object for project use.
|
||||
*/
|
||||
@Data
|
||||
@Builder(toBuilder = true)
|
||||
public class QueryResponse {
|
||||
|
||||
private boolean validPlan;
|
||||
private String planType;
|
||||
private long queries;
|
||||
private long queriesMax;
|
||||
|
||||
/**
|
||||
* Takes a JSON String and feeds it into {@link QueryResponse#fromJson(JSONObject)}
|
||||
*
|
||||
* @param jsonString String (formatted in JSON)
|
||||
* @return QueryResponse
|
||||
* @throws JSONException Throws when JSON is not formatted properly.
|
||||
*/
|
||||
public static QueryResponse fromJson(String jsonString) throws JSONException {
|
||||
return fromJson(new JSONObject(jsonString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats response from https://funkemunky.cc/vpn/queryCheck into {@link QueryResponse} for project use.
|
||||
*
|
||||
* @param object JSONObject
|
||||
* @return QueryResponse
|
||||
* @throws JSONException Throws when JSON is not formatted properly.
|
||||
*/
|
||||
public static QueryResponse fromJson(JSONObject object) throws JSONException {
|
||||
boolean validPlan = object.getBoolean("validPlan");
|
||||
|
||||
if(!validPlan) { // Nothing else will be returned from API if validPlan is false.
|
||||
return QueryResponse.builder().validPlan(false).build();
|
||||
}
|
||||
|
||||
return QueryResponse.builder().validPlan(object.getBoolean("validPlan"))
|
||||
.planType(object.getString("planType"))
|
||||
.queries(object.getLong("queries"))
|
||||
.queriesMax(object.getLong("queryLimit")).build();
|
||||
}
|
||||
}
|
||||
+20
-28
@@ -1,13 +1,11 @@
|
||||
package dev.brighten.antivpn.utils;
|
||||
package dev.brighten.antivpn.web.objects;
|
||||
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import dev.brighten.antivpn.utils.json.JSONObject;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@Builder
|
||||
public class VPNResponse {
|
||||
private String asn, ip, countryName, countryCode, city, timeZone, method, isp, failureReason = "N/A";
|
||||
@@ -29,34 +27,31 @@ public class VPNResponse {
|
||||
json.put("proxy", proxy);
|
||||
json.put("success", success);
|
||||
json.put("timeZone", timeZone);
|
||||
json.put("success", true);
|
||||
json.put("queriesLeft", queriesLeft);
|
||||
json.put("cached", cached);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Feeds into {@link VPNResponse#fromJson(JSONObject)} formatting the JSON {@link String} into
|
||||
* a {@link JSONObject}
|
||||
*
|
||||
* @param json String
|
||||
* @return VPNResponse
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static VPNResponse fromJson(String json) throws JSONException {
|
||||
JSONObject jsonObject = new JSONObject(json);
|
||||
|
||||
if(jsonObject.getBoolean("success")) {
|
||||
return new VPNResponse(jsonObject.getString("asn"), jsonObject.getString("ip"),
|
||||
jsonObject.getString("countryName"), jsonObject.getString("countryCode"),
|
||||
jsonObject.getString("city"), jsonObject.getString("timeZone"),
|
||||
jsonObject.has("method") ? jsonObject.getString("method") : "N/A",
|
||||
jsonObject.getString("isp"), "N/A", jsonObject.getBoolean("proxy"),
|
||||
jsonObject.getBoolean("cached"), jsonObject.getBoolean("success"),
|
||||
jsonObject.getDouble("latitude"), jsonObject.getDouble("longitude"),
|
||||
jsonObject.getLong("lastAccess"), jsonObject.getInt("queriesLeft"));
|
||||
} else {
|
||||
VPNResponse response = new VPNResponse(false);
|
||||
|
||||
response.failureReason = jsonObject.getString("failureReason");
|
||||
|
||||
return response;
|
||||
}
|
||||
return fromJson(new JSONObject(json));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats response from https://funkemunky.cc/vpn into {@link VPNResponse} for project use.
|
||||
*
|
||||
* @param jsonObject JSONObject
|
||||
* @return VPNResponse
|
||||
* @throws JSONException Throws when JSON is not formatted properly.
|
||||
*/
|
||||
public static VPNResponse fromJson(JSONObject jsonObject) throws JSONException {
|
||||
if(jsonObject.getBoolean("success")) {
|
||||
return new VPNResponse(jsonObject.getString("asn"), jsonObject.getString("ip"),
|
||||
@@ -68,11 +63,8 @@ public class VPNResponse {
|
||||
jsonObject.getDouble("latitude"), jsonObject.getDouble("longitude"),
|
||||
jsonObject.getLong("lastAccess"), jsonObject.getInt("queriesLeft"));
|
||||
} else {
|
||||
VPNResponse response = new VPNResponse(false);
|
||||
|
||||
response.failureReason = jsonObject.getString("failureReason");
|
||||
|
||||
return response;
|
||||
return VPNResponse.builder().success(false)
|
||||
.failureReason(jsonObject.getString("failureReason")).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>AntiVPN</artifactId>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.brighten.antivpn</groupId>
|
||||
<artifactId>Common</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.8.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package dev.brighten.antivpn.velocity;
|
||||
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.event.connection.LoginEvent;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.api.APIPlayer;
|
||||
import dev.brighten.antivpn.api.VPNConfig;
|
||||
import dev.brighten.antivpn.api.VPNExecutor;
|
||||
import dev.brighten.antivpn.velocity.util.StringUtils;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
@@ -21,105 +21,113 @@ public class VelocityListener extends VPNExecutor {
|
||||
VelocityPlugin.INSTANCE.getServer().getEventManager()
|
||||
.register(VelocityPlugin.INSTANCE, this);
|
||||
|
||||
VelocityPlugin.INSTANCE.getServer().getEventManager().register(VelocityPlugin.INSTANCE, DisconnectEvent.class,
|
||||
event -> AntiVPN.getInstance().getPlayerExecutor().unloadPlayer(event.getPlayer().getUniqueId()));
|
||||
|
||||
VelocityPlugin.INSTANCE.getServer().getEventManager().register(VelocityPlugin.INSTANCE, LoginEvent.class,
|
||||
event -> {
|
||||
if(event.getResult().isAllowed()) {
|
||||
if(event.getPlayer().hasPermission("antivpn.bypass") //Has bypass permission
|
||||
//Is exempt
|
||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId())
|
||||
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getRemoteAddress()
|
||||
.getAddress().getHostAddress())
|
||||
|| AntiVPN.getInstance().getVpnConfig().getPrefixWhitelists().stream()
|
||||
.anyMatch(prefix -> event.getPlayer().getUsername().startsWith(prefix))) return;
|
||||
if (event.getResult().isAllowed()) {
|
||||
if (event.getPlayer().hasPermission("antivpn.bypass") //Has bypass permission
|
||||
//Is exempt
|
||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId())
|
||||
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getRemoteAddress()
|
||||
.getAddress().getHostAddress())
|
||||
|| AntiVPN.getInstance().getVpnConfig().getPrefixWhitelists().stream()
|
||||
.anyMatch(prefix -> event.getPlayer().getUsername().startsWith(prefix))) return;
|
||||
|
||||
checkIp(event.getPlayer().getRemoteAddress().getAddress().getHostAddress(),
|
||||
AntiVPN.getInstance().getVpnConfig().cachedResults(), result -> {
|
||||
if(result.isSuccess()) {
|
||||
// If the countryList() size is zero, no need to check.
|
||||
// Running country check first
|
||||
if(AntiVPN.getInstance().getVpnConfig().countryList().size() > 0
|
||||
// This bit of code will decide whether or not to kick the player
|
||||
// If it contains the code and it is set to whitelist, it will not kick
|
||||
// as they are equal and vise versa. However, if the contains does not match
|
||||
// the state, it will kick.
|
||||
&& AntiVPN.getInstance().getVpnConfig().countryList()
|
||||
.contains(result.getCountryCode())
|
||||
!= AntiVPN.getInstance().getVpnConfig().whitelistCountries()) {
|
||||
//Using our built in kicking system if no commands are configured
|
||||
if(AntiVPN.getInstance().getVpnConfig().countryKickCommands().size() == 0) {
|
||||
final String kickReason = AntiVPN.getInstance().getVpnConfig()
|
||||
.countryVanillaKickReason();
|
||||
// Kicking our player
|
||||
event.getPlayer().disconnect(LegacyComponentSerializer.builder().character('&')
|
||||
.build().deserialize(kickReason
|
||||
.replace("%player%", event.getPlayer().getUsername())
|
||||
.replace("%country%", result.getCountryName())
|
||||
.replace("%code%", result.getCountryCode())));
|
||||
checkIp(event.getPlayer().getRemoteAddress().getAddress().getHostAddress(),
|
||||
AntiVPN.getInstance().getVpnConfig().cachedResults(), result -> {
|
||||
if (result.isSuccess()) {
|
||||
// If the countryList() size is zero, no need to check.
|
||||
// Running country check first
|
||||
if (AntiVPN.getInstance().getVpnConfig().countryList().size() > 0
|
||||
&& !(AntiVPN.getInstance().getExecutor()
|
||||
.isWhitelisted(event.getPlayer().getUniqueId()) //Is exempt
|
||||
//Or has a name that starts with a certain prefix. This is for Bedrock exempting.
|
||||
|| AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer()
|
||||
.getRemoteAddress().getAddress().getHostAddress()))
|
||||
// This bit of code will decide whether or not to kick the player
|
||||
// If it contains the code and it is set to whitelist, it will not kick
|
||||
// as they are equal and vise versa. However, if the contains does not match
|
||||
// the state, it will kick.
|
||||
&& AntiVPN.getInstance().getVpnConfig().countryList()
|
||||
.contains(result.getCountryCode())
|
||||
!= AntiVPN.getInstance().getVpnConfig().whitelistCountries()) {
|
||||
//Using our built in kicking system if no commands are configured
|
||||
if (AntiVPN.getInstance().getVpnConfig().countryKickCommands().size() == 0) {
|
||||
final String kickReason = AntiVPN.getInstance().getVpnConfig()
|
||||
.countryVanillaKickReason();
|
||||
// Kicking our player
|
||||
event.getPlayer().disconnect(LegacyComponentSerializer.builder().character('&')
|
||||
.build().deserialize(kickReason
|
||||
.replace("%player%", event.getPlayer().getUsername())
|
||||
.replace("%country%", result.getCountryName())
|
||||
.replace("%code%", result.getCountryCode())));
|
||||
} else {
|
||||
for (String cmd : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) {
|
||||
final String formattedCommand = StringUtils
|
||||
.translateAlternateColorCodes('&',
|
||||
cmd.replace("%player%",
|
||||
event.getPlayer().getUsername())
|
||||
.replace("%country%", result.getCountryName())
|
||||
.replace("%code%", result.getCountryCode()));
|
||||
// Running the command from console
|
||||
VelocityPlugin.INSTANCE.getServer().getCommandManager()
|
||||
.executeAsync(VelocityPlugin.INSTANCE.getServer()
|
||||
.getConsoleCommandSource(),
|
||||
StringUtils.translateAlternateColorCodes('&',
|
||||
formattedCommand));
|
||||
}
|
||||
}
|
||||
} else if (result.isProxy()) {
|
||||
if (AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect())
|
||||
event.getPlayer().disconnect(LegacyComponentSerializer.builder().character('&')
|
||||
.build().deserialize(AntiVPN.getInstance().getVpnConfig()
|
||||
.getKickString()));
|
||||
VelocityPlugin.INSTANCE.getLogger().info(event.getPlayer().getUsername()
|
||||
+ " joined on a VPN/Proxy (" + result.getMethod() + ")");
|
||||
//Ensuring the user wishes to alert to staff
|
||||
if (AntiVPN.getInstance().getVpnConfig().alertToStaff())
|
||||
AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream()
|
||||
.filter(APIPlayer::isAlertsEnabled)
|
||||
.forEach(pl ->
|
||||
pl.sendMessage(AntiVPN.getInstance().getVpnConfig()
|
||||
.alertMessage()
|
||||
.replace("%player%",
|
||||
event.getPlayer().getUsername())
|
||||
.replace("%reason%",
|
||||
result.getMethod())
|
||||
.replace("%country%",
|
||||
result.getCountryName())
|
||||
.replace("%city%",
|
||||
result.getCity())));
|
||||
|
||||
//In case the user wants to run their own commands instead of using the
|
||||
// built in kicking
|
||||
if (AntiVPN.getInstance().getVpnConfig().runCommands()) {
|
||||
for (String command : AntiVPN.getInstance().getVpnConfig().commands()) {
|
||||
VelocityPlugin.INSTANCE.getServer().getCommandManager()
|
||||
.executeAsync(VelocityPlugin.INSTANCE.getServer()
|
||||
.getConsoleCommandSource(),
|
||||
StringUtils.translateAlternateColorCodes('&',
|
||||
command.replace("%player%",
|
||||
event.getPlayer().getUsername())));
|
||||
}
|
||||
}
|
||||
AntiVPN.getInstance().detections++;
|
||||
}
|
||||
} else {
|
||||
for (String cmd : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) {
|
||||
final String formattedCommand = StringUtils
|
||||
.translateAlternateColorCodes('&',
|
||||
cmd.replace("%player%",
|
||||
event.getPlayer().getUsername())
|
||||
.replace("%country%", result.getCountryName())
|
||||
.replace("%code%", result.getCountryCode()));
|
||||
// Running the command from console
|
||||
VelocityPlugin.INSTANCE.getServer().getCommandManager()
|
||||
.executeAsync(VelocityPlugin.INSTANCE.getServer()
|
||||
.getConsoleCommandSource(),
|
||||
StringUtils.translateAlternateColorCodes('&',
|
||||
formattedCommand));
|
||||
}
|
||||
VelocityPlugin.INSTANCE.getLogger()
|
||||
.log(Level.WARNING,
|
||||
"The API query was not a success! " +
|
||||
"You may need to upgrade your license on " +
|
||||
"https://funkemunky.cc/shop");
|
||||
}
|
||||
} else if(result.isProxy()) {
|
||||
if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect())
|
||||
event.getPlayer().disconnect(LegacyComponentSerializer.builder().character('&')
|
||||
.build().deserialize(AntiVPN.getInstance().getVpnConfig()
|
||||
.getKickString()));
|
||||
VelocityPlugin.INSTANCE.getLogger().info(event.getPlayer().getUsername()
|
||||
+ " joined on a VPN/Proxy (" + result.getMethod() + ")");
|
||||
//Ensuring the user wishes to alert to staff
|
||||
if(AntiVPN.getInstance().getVpnConfig().alertToStaff())
|
||||
AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream()
|
||||
.filter(APIPlayer::isAlertsEnabled)
|
||||
.forEach(pl ->
|
||||
pl.sendMessage(AntiVPN.getInstance().getVpnConfig()
|
||||
.alertMessage()
|
||||
.replace("%player%",
|
||||
event.getPlayer().getUsername())
|
||||
.replace("%reason%",
|
||||
result.getMethod())
|
||||
.replace("%country%",
|
||||
result.getCountryName())
|
||||
.replace("%city%",
|
||||
result.getCity())));
|
||||
|
||||
//In case the user wants to run their own commands instead of using the
|
||||
// built in kicking
|
||||
if(AntiVPN.getInstance().getVpnConfig().runCommands()) {
|
||||
for (String command : AntiVPN.getInstance().getVpnConfig().commands()) {
|
||||
VelocityPlugin.INSTANCE.getServer().getCommandManager()
|
||||
.executeAsync(VelocityPlugin.INSTANCE.getServer()
|
||||
.getConsoleCommandSource(),
|
||||
StringUtils.translateAlternateColorCodes('&',
|
||||
command.replace("%player%",
|
||||
event.getPlayer().getUsername())));
|
||||
}
|
||||
}
|
||||
AntiVPN.getInstance().detections++;
|
||||
}
|
||||
} else {
|
||||
VelocityPlugin.INSTANCE.getLogger()
|
||||
.log(Level.WARNING,
|
||||
"The API query was not a success! " +
|
||||
"You may need to upgrade your license on " +
|
||||
"https://funkemunky.cc/shop");
|
||||
}
|
||||
AntiVPN.getInstance().checked++;
|
||||
});
|
||||
}
|
||||
});
|
||||
AntiVPN.getInstance().checked++;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -132,7 +140,7 @@ public class VelocityListener extends VPNExecutor {
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
if(cacheResetTask != null) {
|
||||
if (cacheResetTask != null) {
|
||||
cacheResetTask.cancel();
|
||||
cacheResetTask = null;
|
||||
}
|
||||
|
||||
@@ -9,13 +9,14 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class VelocityPlayerExecutor implements PlayerExecutor {
|
||||
|
||||
private final Map<Player, VelocityPlayer> cachedPlayers = new WeakHashMap<>();
|
||||
private final Map<UUID, VelocityPlayer> cachedPlayers = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Optional<APIPlayer> getPlayer(String name) {
|
||||
Optional<Player> player = VelocityPlugin.INSTANCE.getServer().getPlayer(name);
|
||||
|
||||
return player.map(value -> cachedPlayers.computeIfAbsent(value, VelocityPlayer::new));
|
||||
return player.map(value -> cachedPlayers.computeIfAbsent(value.getUniqueId(),
|
||||
key -> new VelocityPlayer(value)));
|
||||
|
||||
}
|
||||
|
||||
@@ -23,13 +24,19 @@ public class VelocityPlayerExecutor implements PlayerExecutor {
|
||||
public Optional<APIPlayer> getPlayer(UUID uuid) {
|
||||
Optional<Player> player = VelocityPlugin.INSTANCE.getServer().getPlayer(uuid);
|
||||
|
||||
return player.map(value -> cachedPlayers.computeIfAbsent(value, VelocityPlayer::new));
|
||||
return player.map(value -> cachedPlayers.computeIfAbsent(value.getUniqueId(),
|
||||
key -> new VelocityPlayer(value)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadPlayer(UUID uuid) {
|
||||
cachedPlayers.remove(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<APIPlayer> getOnlinePlayers() {
|
||||
return VelocityPlugin.INSTANCE.getServer().getAllPlayers().stream()
|
||||
.map(pl -> cachedPlayers.computeIfAbsent(pl, VelocityPlayer::new))
|
||||
.map(pl -> cachedPlayers.computeIfAbsent(pl.getUniqueId(), key -> new VelocityPlayer(pl)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package dev.brighten.antivpn.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
@@ -10,36 +8,30 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||
import dev.brighten.antivpn.velocity.command.VelocityCommand;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bstats.velocity.Metrics;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@Getter
|
||||
@Plugin(id = "kaurivpn", name = "KauriVPN", version = "1.5.0", authors = {"funkemunky"})
|
||||
@Plugin(id = "kaurivpn", name = "KauriVPN", version = "1.7.1", authors = {"funkemunky"})
|
||||
public class VelocityPlugin {
|
||||
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private Metrics.Factory metricsFactory;
|
||||
private final Metrics.Factory metricsFactory;
|
||||
private final Path configDir;
|
||||
|
||||
public static VelocityPlugin INSTANCE;
|
||||
|
||||
@Inject
|
||||
@DataDirectory
|
||||
private Path configDir;
|
||||
|
||||
@Inject
|
||||
public VelocityPlugin(ProxyServer server, Logger logger, Metrics.Factory metricsFactory) {
|
||||
public VelocityPlugin(ProxyServer server, Logger logger, @DataDirectory Path path, Metrics.Factory metricsFactory) {
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
this.configDir = path;
|
||||
this.metricsFactory = metricsFactory;
|
||||
}
|
||||
|
||||
@@ -60,40 +52,7 @@ public class VelocityPlugin {
|
||||
logger.info("Registering commands...");
|
||||
for (Command command : AntiVPN.getInstance().getCommands()) {
|
||||
server.getCommandManager().register(server.getCommandManager().metaBuilder(command.name())
|
||||
.aliases(command.aliases()).build(), (SimpleCommand) invocation -> {
|
||||
CommandSource sender = invocation.source();
|
||||
if(!invocation.source().hasPermission("antivpn.command.*")
|
||||
&& !invocation.source().hasPermission(command.permission())) {
|
||||
invocation.source().sendMessage(Component.text("No permission").toBuilder()
|
||||
.color(TextColor.color(255,0,0)).build());
|
||||
return;
|
||||
}
|
||||
|
||||
val children = command.children();
|
||||
|
||||
String[] args = invocation.arguments();
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases())
|
||||
.anyMatch(alias -> alias.equalsIgnoreCase(args[0]))) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(child.permission())) {
|
||||
invocation.source().sendMessage(Component.text("No permission")
|
||||
.toBuilder().color(TextColor.color(255,0,0)).build());
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build()
|
||||
.deserialize(child.execute(new VelocityCommandExecutor(sender), IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build()
|
||||
.deserialize(command.execute(new VelocityCommandExecutor(sender), args)));
|
||||
});
|
||||
.aliases(command.aliases()).build(), new VelocityCommand(command));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package dev.brighten.antivpn.velocity.command;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import lombok.val;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class VelocityCommand implements SimpleCommand {
|
||||
|
||||
private final Command command;
|
||||
|
||||
public VelocityCommand(Command command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
CommandSource sender = invocation.source();
|
||||
if(!invocation.source().hasPermission("antivpn.command.*")
|
||||
&& !invocation.source().hasPermission(command.permission())) {
|
||||
invocation.source().sendMessage(Component.text("No permission").toBuilder()
|
||||
.color(TextColor.color(255,0,0)).build());
|
||||
return;
|
||||
}
|
||||
|
||||
val children = command.children();
|
||||
|
||||
String[] args = invocation.arguments();
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases())
|
||||
.anyMatch(alias -> alias.equalsIgnoreCase(args[0]))) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(child.permission())) {
|
||||
invocation.source().sendMessage(Component.text("No permission")
|
||||
.toBuilder().color(TextColor.color(255,0,0)).build());
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build()
|
||||
.deserialize(child.execute(new VelocityCommandExecutor(sender), IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build()
|
||||
.deserialize(command.execute(new VelocityCommandExecutor(sender), args)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(Invocation invocation) {
|
||||
final CommandSource sender = invocation.source();
|
||||
final String[] args = invocation.arguments();
|
||||
|
||||
val children = command.children();
|
||||
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (dev.brighten.antivpn.command.Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0]) || Arrays.stream(child.aliases())
|
||||
.anyMatch(alias2 -> alias2.equalsIgnoreCase(args[0]))) {
|
||||
return child.tabComplete(new VelocityCommandExecutor(sender), "alias", IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new));
|
||||
}
|
||||
}
|
||||
}
|
||||
return command.tabComplete(new VelocityCommandExecutor(sender), "alias", args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<String>> suggestAsync(Invocation invocation) {
|
||||
return CompletableFuture.supplyAsync(() -> this.suggest(invocation));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Invocation invocation) {
|
||||
return SimpleCommand.super.hasPermission(invocation);
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
package dev.brighten.antivpn.velocity;
|
||||
package dev.brighten.antivpn.velocity.command;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
@@ -16,8 +16,9 @@ public class VelocityCommandExecutor implements CommandExecutor {
|
||||
private final CommandSource sender;
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build().deserialize(message));
|
||||
public void sendMessage(String message, Object... objects) {
|
||||
sender.sendMessage(LegacyComponentSerializer.builder().character('&').build()
|
||||
.deserialize(String.format(message, objects)));
|
||||
}
|
||||
|
||||
@Override
|
||||
Reference in New Issue
Block a user