From 315d4eaa3fe7d0a954a106718d8f925d8a976c0c Mon Sep 17 00:00:00 2001 From: Dawson Hessler Date: Fri, 1 Apr 2022 11:13:21 -0400 Subject: [PATCH] Running country checks before running proxy checks --- .../antivpn/bungee/BungeeListener.java | 36 ++++++------ .../antivpn/velocity/VelocityListener.java | 57 ++++++++----------- 2 files changed, 40 insertions(+), 53 deletions(-) diff --git a/Bungee/src/main/java/dev/brighten/antivpn/bungee/BungeeListener.java b/Bungee/src/main/java/dev/brighten/antivpn/bungee/BungeeListener.java index 2bcdf9b..16130d0 100644 --- a/Bungee/src/main/java/dev/brighten/antivpn/bungee/BungeeListener.java +++ b/Bungee/src/main/java/dev/brighten/antivpn/bungee/BungeeListener.java @@ -58,7 +58,23 @@ public class BungeeListener extends VPNExecutor implements Listener { checkIp(event.getPlayer().getAddress().getAddress().getHostAddress(), AntiVPN.getInstance().getVpnConfig().cachedResults(), result -> { if(result.isSuccess()) { - if(result.isProxy()) { + // If the countryList() size is zero, no need to check. + 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()) { + for (String cmd : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) { + final String formattedCommand = ChatColor.translateAlternateColorCodes('&', + cmd.replace("%player%", event.getPlayer().getName()) + .replace("%country%", result.getCountryName()) + .replace("%code%", result.getCountryCode())); + + BungeeCord.getInstance().getPluginManager().dispatchCommand( + BungeeCord.getInstance().getConsole(), formattedCommand); + } + } else if(result.isProxy()) { if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect()) event.getPlayer().disconnect(TextComponent.fromLegacyText(ChatColor .translateAlternateColorCodes('&', @@ -87,24 +103,6 @@ public class BungeeListener extends VPNExecutor implements Listener { AntiVPN.getInstance().detections++; } - // If the countryList() size is zero, no need to check. - 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()) { - for (String cmd : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) { - final String formattedCommand = ChatColor.translateAlternateColorCodes('&', - cmd.replace("%player%", event.getPlayer().getName()) - .replace("%country%", result.getCountryName()) - .replace("%code%", result.getCountryCode())); - - BungeeCord.getInstance().getPluginManager().dispatchCommand( - BungeeCord.getInstance().getConsole(), formattedCommand); - } - } - } else { BungeeCord.getInstance().getLogger() .log(Level.WARNING, diff --git a/Velocity/src/main/java/dev/brighten/antivpn/velocity/VelocityListener.java b/Velocity/src/main/java/dev/brighten/antivpn/velocity/VelocityListener.java index af5fee8..5d78fd8 100644 --- a/Velocity/src/main/java/dev/brighten/antivpn/velocity/VelocityListener.java +++ b/Velocity/src/main/java/dev/brighten/antivpn/velocity/VelocityListener.java @@ -36,7 +36,29 @@ public class VelocityListener extends VPNExecutor { checkIp(event.getPlayer().getRemoteAddress().getAddress().getHostAddress(), AntiVPN.getInstance().getVpnConfig().cachedResults(), result -> { if(result.isSuccess()) { - if(result.isProxy()) { + // If the countryList() size is zero, no need to check. + 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()) { + 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())); + System.out.println(formattedCommand); + 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() @@ -73,39 +95,6 @@ public class VelocityListener extends VPNExecutor { } AntiVPN.getInstance().detections++; } - - for (String s : AntiVPN.getInstance().getVpnConfig().countryList()) { - VelocityPlugin.INSTANCE.getLogger().info(s); - } - - System.out.println("Code: '" + result.getCountryCode() + "'"); - System.out.println("Contains: " + AntiVPN.getInstance().getVpnConfig().countryList() - .contains(result.getCountryCode()) + ", " - + AntiVPN.getInstance().getVpnConfig().whitelistCountries()); - // If the countryList() size is zero, no need to check. - 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()) { - 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())); - System.out.println(formattedCommand); - VelocityPlugin.INSTANCE.getServer().getCommandManager() - .executeAsync(VelocityPlugin.INSTANCE.getServer() - .getConsoleCommandSource(), - StringUtils.translateAlternateColorCodes('&', - formattedCommand)); - } - } - } else { VelocityPlugin.INSTANCE.getLogger() .log(Level.WARNING,