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 73d7841..bd8446c 100644 --- a/Bukkit/src/main/java/dev/brighten/antivpn/bukkit/BukkitListener.java +++ b/Bukkit/src/main/java/dev/brighten/antivpn/bukkit/BukkitListener.java @@ -87,6 +87,7 @@ public class BukkitListener extends VPNExecutor implements Listener { new BukkitRunnable() { public void run() { // 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 @@ -94,13 +95,27 @@ public class BukkitListener extends VPNExecutor implements Listener { && 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())); + //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().kickPlayer(ChatColor + .translateAlternateColorCodes('&', + kickReason + .replace("%player%", event.getPlayer().getName()) + .replace("%country%", result.getCountryName()) + .replace("%code%", result.getCountryCode()))); + } else { + 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())); - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), formattedCommand); + // Runs our command from console + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), formattedCommand); + } } } else if(result.isProxy()) { if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect()) 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 16130d0..43895d3 100644 --- a/Bungee/src/main/java/dev/brighten/antivpn/bungee/BungeeListener.java +++ b/Bungee/src/main/java/dev/brighten/antivpn/bungee/BungeeListener.java @@ -59,20 +59,35 @@ public class BungeeListener extends VPNExecutor implements Listener { 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()) { - 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())); + //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(TextComponent.fromLegacyText(ChatColor + .translateAlternateColorCodes('&', + kickReason + .replace("%player%", event.getPlayer().getName()) + .replace("%country%", result.getCountryName()) + .replace("%code%", result.getCountryCode())))); + } else { + 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); + // Runs our command from console + BungeeCord.getInstance().getPluginManager().dispatchCommand( + BungeeCord.getInstance().getConsole(), formattedCommand); + } } } else if(result.isProxy()) { if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect()) diff --git a/Common/src/main/java/dev/brighten/antivpn/api/VPNConfig.java b/Common/src/main/java/dev/brighten/antivpn/api/VPNConfig.java index 2498772..d6df035 100644 --- a/Common/src/main/java/dev/brighten/antivpn/api/VPNConfig.java +++ b/Common/src/main/java/dev/brighten/antivpn/api/VPNConfig.java @@ -22,9 +22,10 @@ public class VPNConfig { "database.username", AntiVPN.getInstance()), defaultPassword = new ConfigDefault<>("password", "database.password", AntiVPN.getInstance()), - - - defaultIp = new ConfigDefault<>("localhost", "database.ip", AntiVPN.getInstance()), + defaultCountryKickReason = new ConfigDefault<>( + "&cSorry, but our server does not allow connections from\n&f%country%", + "countries.vanillaKickReason", AntiVPN.getInstance()), + defaultIp = new ConfigDefault<>("localhost", "database.ip", AntiVPN.getInstance()), defaultAlertMsg = new ConfigDefault<>("&8[&6KauriVPN&8] &e%player% &7has joined on a VPN/proxy" + " &8(&f%reason%&8) &7in location &8(&f%city%&7, &f%country%&8)", "alerts.message", AntiVPN.getInstance()); @@ -47,13 +48,13 @@ public class VPNConfig { "prefixWhitelists", AntiVPN.getInstance()), defaultCommands = new ConfigDefault<>( Collections.singletonList("kick %player% VPNs are not allowed on our server!"), "commands.execute", AntiVPN.getInstance()), - defCountryKickCommands = new ConfigDefault<>(Collections.singletonList( - "kick %player% &cSorry, but our server does not allow connections from\\n&f%country%"), + defCountryKickCommands = new ConfigDefault<>(Collections.emptyList(), "countries.commands", AntiVPN.getInstance()), defCountrylist = new ConfigDefault<>(new ArrayList<>(), "countries.list", AntiVPN.getInstance()); - private String license, kickMessage, databaseType, databaseName, mongoURL, username, password, ip, alertMsg; + private String license, kickMessage, databaseType, databaseName, mongoURL, username, password, ip, alertMsg, + countryVanillaKickReason; private List prefixWhitelists, commands, countryList, countryKickCommands; private int port; private boolean cacheResults, databaseEnabled, useCredentials, commandsEnabled, kickPlayers, alertToStaff, @@ -220,6 +221,14 @@ public class VPNConfig { return countryKickCommands; } + /** + * Returns the vanilla kick reason for bad country locations + * @return String + */ + public String countryVanillaKickReason() { + return countryVanillaKickReason; + } + /** * Gets the port based on configuration. If {@link VPNConfig#port} is -1, will get default port * based on {@link VPNConfig#getDatabaseType()} lowerCase(). @@ -276,6 +285,7 @@ public class VPNConfig { countryList = defCountrylist.get(); whitelistCountries = defaultWhitelistCountries.get(); countryKickCommands = defCountryKickCommands.get(); + countryVanillaKickReason = defaultCountryKickReason.get(); } } diff --git a/Common/src/main/resources/config.yml b/Common/src/main/resources/config.yml index df1ca32..76c8abe 100644 --- a/Common/src/main/resources/config.yml +++ b/Common/src/main/resources/config.yml @@ -57,8 +57,11 @@ countries: whitelist: true # The commands to be run if the player is not allowed on the server with the above configured conditions # Placeholders: %country% (Country name), %player% (Player name), %code% (Country ISO Code) - commands: - - "kick %player% &cSorry, but our server does not allow connections from\n&f%country%" + # Keep this empty with "[]" if you want to use the built in kicking system. + commands: [] + # The kick message that will be used if commands are configured to use the built-in kicking sytem. + # PlaceHolders: %country% (Country name), %player% (Player name), %code% (Country ISO Code) + vanillaKickReason: "&cSorry, but our server does not allow connections from\n&f%country%" # This will disable any information being sent to https://bstats.org. We recommend you keep this enabled as it helps # us understand our users and put effort where it is needed. All information sent goes under their privacy as seen # here: https://bstats.org/privacy-policy 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 5d78fd8..3daf9bc 100644 --- a/Velocity/src/main/java/dev/brighten/antivpn/velocity/VelocityListener.java +++ b/Velocity/src/main/java/dev/brighten/antivpn/velocity/VelocityListener.java @@ -37,6 +37,7 @@ public class VelocityListener extends VPNExecutor { 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 @@ -45,18 +46,31 @@ public class VelocityListener extends VPNExecutor { && 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)); + //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())