diff --git a/Assembly/pom.xml b/Assembly/pom.xml index cb132a6..a118190 100644 --- a/Assembly/pom.xml +++ b/Assembly/pom.xml @@ -21,7 +21,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.2 + 3.2.4 package @@ -65,6 +65,12 @@ ${version} compile + + org.xerial + sqlite-jdbc + 3.41.2.2 + compile + dev.brighten.antivpn Bukkit diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index 182d3d6..0cc59d1 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -16,7 +16,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.13.0 + 3.7.0 8 8 @@ -26,7 +26,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.2 + 3.2.4 package @@ -34,6 +34,7 @@ shade + true org.bstats diff --git a/Bukkit/src/main/java/dev/brighten/antivpn/bukkit/BukkitListener.java b/Bukkit/src/main/java/dev/brighten/antivpn/bukkit/BukkitListener.java index 0f2f730..8c1c105 100644 --- a/Bukkit/src/main/java/dev/brighten/antivpn/bukkit/BukkitListener.java +++ b/Bukkit/src/main/java/dev/brighten/antivpn/bukkit/BukkitListener.java @@ -11,14 +11,12 @@ import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scheduler.BukkitRunnable; -import java.net.InetAddress; -import java.net.InetSocketAddress; import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.logging.Level; @@ -56,7 +54,7 @@ public class BukkitListener extends VPNExecutor implements Listener { Bukkit.getLogger().log(Level.SEVERE, message, ex); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onJoin(final PlayerJoinEvent event) { AntiVPN.getInstance().getPlayerExecutor().getPlayer(event.getPlayer().getUniqueId()) .ifPresent(player -> AntiVPN.getInstance().getDatabase().alertsState(player.getUuid(), enabled -> { @@ -67,15 +65,20 @@ public class BukkitListener extends VPNExecutor implements Listener { .getFormattedMessage(new VpnString.Var<>("state", true))); } })); - } - @EventHandler - public void onListener(final PlayerLoginEvent event) { - //If they're exempt, don't check. + String address; + + if(event.getPlayer().getAddress() != null) { + address = event.getPlayer().getAddress().getAddress().getHostAddress(); + } else { + log(Level.WARNING, "Player %s address is null! This is a bug and should be reported!", event.getPlayer().getName()); + return; + } + 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.getAddress().getHostAddress()) + || AntiVPN.getInstance().getExecutor().isWhitelisted(address) || AntiVPN.getInstance().getVpnConfig().getPrefixWhitelists().stream() .anyMatch(prefix -> event.getPlayer().getName().startsWith(prefix))) return; @@ -83,147 +86,124 @@ public class BukkitListener extends VPNExecutor implements Listener { VPNResponse cached = responseCache.getIfPresent(event.getPlayer().getUniqueId()); if (cached != null && cached.isProxy()) { - event.setResult(PlayerLoginEvent.Result.KICK_BANNED); - event.setKickMessage(org.bukkit.ChatColor.translateAlternateColorCodes('&', - AntiVPN.getInstance().getVpnConfig().getKickString())); + proxyKick(event.getPlayer(), cached); return; } } final Player player = event.getPlayer(); - checkIp(event.getAddress().getHostAddress(), + checkIp(address, AntiVPN.getInstance().getVpnConfig().cachedResults(), result -> { if(result.isSuccess()) { //We need to run on main thread or kicking and running commands will cause errors //If the player is whitelisted, we don't want to kick them if(AntiVPN.getInstance().getExecutor().isWhitelisted(event.getPlayer().getUniqueId())) { - log("UUID is whitelisted: %s", - event.getPlayer().getUniqueId().toString()); + log("UUID is whitelisted: %s", event.getPlayer().getUniqueId().toString()); return; } //If the IP is whitelisted, we don't want to kick them - InetSocketAddress address = event.getPlayer().getAddress(); - if (address != null){ - InetAddress address1 = address.getAddress(); - if (address1 != null && AntiVPN.getInstance().getExecutor() - .isWhitelisted(address1.getHostAddress())) { - log("IP is whitelisted: %s", - address1.getHostAddress()); - return; - } + if (AntiVPN.getInstance().getExecutor().isWhitelisted(address)) { + log("IP is whitelisted: %s", + address); + return; } // If the countryList() size is zero, no need to check. // Running country check first if(!AntiVPN.getInstance().getVpnConfig().countryList().isEmpty() - // 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 + // This bit of code will decide whether to kick the player + // If contains the code, and 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()) { - final String kickReason = AntiVPN.getInstance().getVpnConfig() - .countryVanillaKickReason(); - - // Start "online" fix - // In case the response was so fast from API the player wouldn't be "online". - event.setResult(PlayerLoginEvent.Result.KICK_BANNED); - event.setKickMessage(ChatColor - .translateAlternateColorCodes('&', - kickReason - .replace("%player%", event.getPlayer().getName()) - .replace("%country%", result.getCountryName()) - .replace("%code%", result.getCountryCode()))); - // End "online" fix - - //Using our built in kicking system if no commands are configured - if(AntiVPN.getInstance().getVpnConfig().countryKickCommands().isEmpty()) { - // Kicking our player - new BukkitRunnable() { - public void run() { - event.getPlayer().kickPlayer(ChatColor - .translateAlternateColorCodes('&', - kickReason - .replace("%player%", event.getPlayer().getName()) - .replace("%country%", result.getCountryName()) - .replace("%code%", result.getCountryCode()))); - } - }.runTask(BukkitPlugin.pluginInstance); - } else { - final String playerName = event.getPlayer().getName(); - - BukkitPlugin.pluginInstance.getPlayerCommandRunner() - .addAction(event.getPlayer().getUniqueId(), () -> { - for (String cmd : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) { - final String formattedCommand = ChatColor.translateAlternateColorCodes('&', - cmd.replace("%player%", playerName) - .replace("%country%", result.getCountryName()) - .replace("%code%", result.getCountryCode())); - - // Runs our command from console - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), formattedCommand); - } - }); - } + countryKick(player, result); } else if(result.isProxy()) { - - // Start "online" fix - // In case the response was so fast from API the player wouldn't be "online". - event.setResult(PlayerLoginEvent.Result.KICK_BANNED); - event.setKickMessage(ChatColor - .translateAlternateColorCodes('&', - AntiVPN.getInstance().getVpnConfig().getKickString() - .replace("%player%", event.getPlayer().getName()) - .replace("%country%", result.getCountryName()) - .replace("%code%", result.getCountryCode()))); - // End "online" fix - - if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect()) { - new BukkitRunnable() { - public void run() { - player.kickPlayer(org.bukkit.ChatColor.translateAlternateColorCodes('&', - AntiVPN.getInstance().getVpnConfig().getKickString())); - } - }.runTask(BukkitPlugin.pluginInstance); - } - log(Level.INFO, event.getPlayer().getName() - + " 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().getName()) - .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()) { - String playerName = event.getPlayer().getName(); - BukkitPlugin.pluginInstance.getPlayerCommandRunner() - .addAction(event.getPlayer().getUniqueId(), () -> { - for (String command : AntiVPN.getInstance().getVpnConfig().commands()) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), - ChatColor.translateAlternateColorCodes('&', - command.replace("%player%", - playerName))); - } - }); - } - AntiVPN.getInstance().detections++; + proxyKick(player, result); } } else { log(Level.WARNING, - "The API query was not a success! " + - "You may need to upgrade your license on https://funkemunky.cc/shop"); + "The API query was not a success! " + + "You may need to upgrade your license on https://funkemunky.cc/shop"); } AntiVPN.getInstance().checked++; }); } + private void countryKick(Player player, VPNResponse result) { + final String kickReason = AntiVPN.getInstance().getVpnConfig() + .countryVanillaKickReason(); + //Using our built-in kicking system if no commands are configured + if(AntiVPN.getInstance().getVpnConfig().countryKickCommands().isEmpty()) { + // Kicking our player + new BukkitRunnable() { + public void run() { + player.kickPlayer(ChatColor + .translateAlternateColorCodes('&', + kickReason + .replace("%player%", player.getName()) + .replace("%country%", result.getCountryName()) + .replace("%code%", result.getCountryCode()))); + } + }.runTask(BukkitPlugin.pluginInstance); + } else { + final String playerName = player.getName(); + + BukkitPlugin.pluginInstance.getPlayerCommandRunner() + .addAction(player.getUniqueId(), () -> { + for (String cmd : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) { + final String formattedCommand = ChatColor.translateAlternateColorCodes('&', + cmd.replace("%player%", playerName) + .replace("%country%", result.getCountryName()) + .replace("%code%", result.getCountryCode())); + + // Runs our command from console + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), formattedCommand); + } + }); + } + } + + private void proxyKick(Player player, VPNResponse result) { + log(Level.INFO, player.getName() + + " 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%", player.getName()) + .replace("%reason%", result.getMethod()) + .replace("%country%", result.getCountryName()) + .replace("%city%", result.getCity()))); + + if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect()) { + new BukkitRunnable() { + public void run() { + player.kickPlayer(org.bukkit.ChatColor.translateAlternateColorCodes('&', + AntiVPN.getInstance().getVpnConfig().getKickString())); + } + }.runTask(BukkitPlugin.pluginInstance); + } else { + //In case the user wants to run their own commands instead of using the built-in kicking + if(AntiVPN.getInstance().getVpnConfig().runCommands()) { + String playerName = player.getName(); + BukkitPlugin.pluginInstance.getPlayerCommandRunner() + .addAction(player.getUniqueId(), () -> { + for (String command : AntiVPN.getInstance().getVpnConfig().commands()) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), + ChatColor.translateAlternateColorCodes('&', + command.replace("%player%", + playerName))); + } + }); + } + AntiVPN.getInstance().detections++; + } + } + @EventHandler public void onQuit(PlayerQuitEvent event) { AntiVPN.getInstance().getPlayerExecutor().unloadPlayer(event.getPlayer().getUniqueId()); diff --git a/Bungee/pom.xml b/Bungee/pom.xml index c067297..06e4cff 100644 --- a/Bungee/pom.xml +++ b/Bungee/pom.xml @@ -16,7 +16,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.13.0 + 3.7.0 8 8 @@ -26,7 +26,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.2 + 3.1.0 diff --git a/Common/pom.xml b/Common/pom.xml index 44eaa80..82f313f 100644 --- a/Common/pom.xml +++ b/Common/pom.xml @@ -21,7 +21,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.13.0 + 3.10.1 8 8 @@ -38,7 +38,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.2 + 3.4.1 package @@ -46,7 +46,7 @@ shade - false + true org.yaml.snakeyaml @@ -86,11 +86,13 @@ com.mysql mysql-connector-j 9.1.0 + jar + compile com.h2database h2 - 2.2.224 + 2.2.220 compile diff --git a/Common/src/main/resources/config.yml b/Common/src/main/resources/config.yml index a28421a..4827f1e 100644 --- a/Common/src/main/resources/config.yml +++ b/Common/src/main/resources/config.yml @@ -11,7 +11,8 @@ cachedResults: true # All players with any of the following characters in the beginning of their name will be whitelisted # This is a useful feature for servers that allow players through Geyser and their IPs are not forwarded, causing # players to be removed falsely for use of proxy. -prefixWhitelists: [] +prefixWhitelists: + - "*" # Configure your database here. database: # Enable to cache queries and save alerts state beyond restarts diff --git a/Sponge/pom.xml b/Sponge/pom.xml index 4d60ce4..de32988 100644 --- a/Sponge/pom.xml +++ b/Sponge/pom.xml @@ -34,8 +34,8 @@ - 8 - 8 + 17 + 17 \ No newline at end of file diff --git a/Velocity/pom.xml b/Velocity/pom.xml index dc8ef95..045296f 100644 --- a/Velocity/pom.xml +++ b/Velocity/pom.xml @@ -49,7 +49,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.13.0 + 3.7.0 8 8 @@ -59,7 +59,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.2 + 3.1.0 diff --git a/pom.xml b/pom.xml index 141fada..1bab415 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.13.0 + 3.7.0 8 8