diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a7de87b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,19 @@ +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21.0 + distribution: 'zulu' + cache: 'maven' + - name: Compile + run: mvn -B package --file pom.xml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Bukkit/Loader/pom.xml b/Bukkit/Loader/pom.xml index b4dff27..c697135 100644 --- a/Bukkit/Loader/pom.xml +++ b/Bukkit/Loader/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn Bukkit - 1.9.4 + 1.10.0 dev.brighten.antivpn.bukkit Loader @@ -83,7 +99,7 @@ dev.brighten.antivpn loader-utils - 1.9.4 + 1.10.0 compile diff --git a/Bukkit/Loader/src/main/java/dev/brighten/antivpn/bukkit/loader/BukkitLoaderPlugin.java b/Bukkit/Loader/src/main/java/dev/brighten/antivpn/bukkit/loader/BukkitLoaderPlugin.java index f8ea3c8..81048eb 100644 --- a/Bukkit/Loader/src/main/java/dev/brighten/antivpn/bukkit/loader/BukkitLoaderPlugin.java +++ b/Bukkit/Loader/src/main/java/dev/brighten/antivpn/bukkit/loader/BukkitLoaderPlugin.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bukkit.loader; import dev.brighten.antivpn.loader.JarInJarClassLoader; diff --git a/Bukkit/Plugin/pom.xml b/Bukkit/Plugin/pom.xml index 0a35b0c..182d091 100644 --- a/Bukkit/Plugin/pom.xml +++ b/Bukkit/Plugin/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn Bukkit - 1.9.4 + 1.10.0 Plugin @@ -82,7 +98,7 @@ dev.brighten.antivpn Source - 1.9.4 + 1.10.0 provided @@ -94,7 +110,7 @@ dev.brighten.antivpn loader-utils - 1.9.4 + 1.10.0 provided diff --git a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitCommandExecutor.java b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitCommandExecutor.java index c8df5ae..a1a8001 100644 --- a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitCommandExecutor.java +++ b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitCommandExecutor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bukkit; import dev.brighten.antivpn.AntiVPN; diff --git a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitListener.java b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitListener.java index d509b18..d124b1c 100644 --- a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitListener.java +++ b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitListener.java @@ -1,13 +1,26 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bukkit; import dev.brighten.antivpn.AntiVPN; import dev.brighten.antivpn.api.APIPlayer; -import dev.brighten.antivpn.api.CheckResult; import dev.brighten.antivpn.api.OfflinePlayer; import dev.brighten.antivpn.api.VPNExecutor; -import dev.brighten.antivpn.message.VpnString; import dev.brighten.antivpn.utils.StringUtil; -import dev.brighten.antivpn.utils.Tuple; import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; @@ -20,7 +33,6 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.logging.Level; -@SuppressWarnings("unchecked") public class BukkitListener extends VPNExecutor implements Listener { @Override @@ -65,65 +77,35 @@ public class BukkitListener extends VPNExecutor implements Listener { event.getAddress() )); - CheckResult instantResult = player.checkPlayer(result -> { + player.checkPlayer(result -> { if(!result.resultType().isShouldBlock()) return; - AntiVPN.getInstance().getExecutor().log(Level.INFO, "Adding %s to kick", event.getPlayer().getName()); - AntiVPN.getInstance().getExecutor().getToKick().add(new Tuple<>(result, event.getPlayer().getUniqueId())); - }); - - if(!instantResult.resultType().isShouldBlock()) return; - - AntiVPN.getInstance().getExecutor().getToKick() - .add(new Tuple<>(instantResult, event.getPlayer().getUniqueId())); - - if(!AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect()) { - return; - } - - AntiVPN.getInstance().getExecutor().log(Level.INFO, "%s was kicked from pre-login cache with IP %s", event.getPlayer().getName(), instantResult.response().getIp()); - - event.setResult(PlayerLoginEvent.Result.KICK_BANNED); - switch (instantResult.resultType()) { - case DENIED_COUNTRY -> event.setKickMessage(StringUtil.translateAlternateColorCodes('&', - StringUtil.varReplace( - AntiVPN.getInstance().getVpnConfig().countryVanillaKickReason(), - player, - instantResult.response() - ))); - case DENIED_PROXY -> { - if(AntiVPN.getInstance().getVpnConfig().alertToStaff()) { - AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream() - .filter(APIPlayer::isAlertsEnabled) - .forEach(pl -> - pl.sendMessage(StringUtil.varReplace( - ChatColor.translateAlternateColorCodes( - '&', - AntiVPN.getInstance().getVpnConfig().alertMessage()), - player, - instantResult.response()))); - } - event.setKickMessage(StringUtil.translateAlternateColorCodes('&', - StringUtil.varReplace( - AntiVPN.getInstance().getVpnConfig().getKickString(), - player, - instantResult.response() - ))); + if(!AntiVPN.getInstance().getVpnConfig().isKickPlayers()) { + return; } - } + + event.setResult(PlayerLoginEvent.Result.KICK_BANNED); + event.setKickMessage(switch (result.resultType()) { + case DENIED_COUNTRY -> StringUtil.varReplace( + AntiVPN.getInstance().getVpnConfig().getCountryVanillaKickReason(), + player, + result.response() + ); + case DENIED_PROXY -> + StringUtil.varReplace( + AntiVPN.getInstance().getVpnConfig().getKickMessage(), + player, + result.response() + ); + default -> "You were kicked by KauriVPN for an unknown reason!"; + }); + }); } - @EventHandler(priority = EventPriority.MONITOR) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onJoin(final PlayerJoinEvent event) { AntiVPN.getInstance().getPlayerExecutor().getPlayer(event.getPlayer().getUniqueId()) - .ifPresent(player -> AntiVPN.getInstance().getDatabase().alertsState(player.getUuid(), enabled -> { - if(enabled) { - player.setAlertsEnabled(true); - player.sendMessage(AntiVPN.getInstance().getMessageHandler() - .getString("command-alerts-toggled") - .getFormattedMessage(new VpnString.Var<>("state", true))); - } - })); + .ifPresent(APIPlayer::checkAlertsState); } @EventHandler diff --git a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlayer.java b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlayer.java index 5f8e6ac..f45f9e9 100644 --- a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlayer.java +++ b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlayer.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bukkit; import dev.brighten.antivpn.api.APIPlayer; diff --git a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlayerExecutor.java b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlayerExecutor.java index faa1f19..3a6ee4c 100644 --- a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlayerExecutor.java +++ b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlayerExecutor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bukkit; import dev.brighten.antivpn.api.APIPlayer; diff --git a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlugin.java b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlugin.java index 540780c..1cab6a2 100644 --- a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlugin.java +++ b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/BukkitPlugin.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bukkit; import dev.brighten.antivpn.AntiVPN; @@ -133,10 +149,10 @@ public class BukkitPlugin implements LoaderBootstrap { private String getDatabaseType() { VPNDatabase database = AntiVPN.getInstance().getDatabase(); - if(database instanceof H2VPN) { - return "H2"; - } else if(database instanceof MySqlVPN) { + if(database instanceof MySqlVPN) { return "MySQL"; + } else if(database instanceof H2VPN) { + return "H2"; } else if(database instanceof MongoVPN) { return "MongoDB"; } else { diff --git a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/PlayerCommandRunner.java b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/PlayerCommandRunner.java index 8ac64a7..1b240e7 100644 --- a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/PlayerCommandRunner.java +++ b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/PlayerCommandRunner.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bukkit; import dev.brighten.antivpn.utils.MiscUtils; diff --git a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/command/BukkitCommand.java b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/command/BukkitCommand.java index 2e3ecd4..132de49 100644 --- a/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/command/BukkitCommand.java +++ b/Bukkit/Plugin/src/main/java/dev/brighten/antivpn/bukkit/command/BukkitCommand.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bukkit.command; import dev.brighten.antivpn.AntiVPN; diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index e44a743..2cb1c28 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -1,11 +1,27 @@ + + AntiVPN dev.brighten.antivpn - 1.9.4 + 1.10.0 pom diff --git a/Bungee/BungeeLoader/pom.xml b/Bungee/BungeeLoader/pom.xml index 0aea182..9d19d14 100644 --- a/Bungee/BungeeLoader/pom.xml +++ b/Bungee/BungeeLoader/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn Bungee - 1.9.4 + 1.10.0 ../pom.xml @@ -79,7 +95,7 @@ dev.brighten.antivpn loader-utils - 1.9.4 + 1.10.0 compile diff --git a/Bungee/BungeeLoader/src/main/java/dev/brighten/antivpn/bungee/BungeeLoaderPlugin.java b/Bungee/BungeeLoader/src/main/java/dev/brighten/antivpn/bungee/BungeeLoaderPlugin.java index 353be25..16ae758 100644 --- a/Bungee/BungeeLoader/src/main/java/dev/brighten/antivpn/bungee/BungeeLoaderPlugin.java +++ b/Bungee/BungeeLoader/src/main/java/dev/brighten/antivpn/bungee/BungeeLoaderPlugin.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bungee; import dev.brighten.antivpn.loader.JarInJarClassLoader; diff --git a/Bungee/BungeePlugin/pom.xml b/Bungee/BungeePlugin/pom.xml index 1727eb0..e6f1a46 100644 --- a/Bungee/BungeePlugin/pom.xml +++ b/Bungee/BungeePlugin/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn Bungee - 1.9.4 + 1.10.0 ../pom.xml @@ -69,7 +85,7 @@ dev.brighten.antivpn Source - 1.9.4 + 1.10.0 provided @@ -88,7 +104,7 @@ dev.brighten.antivpn loader-utils - 1.9.4 + 1.10.0 provided diff --git a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeeListener.java b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeeListener.java index 59cd590..b09cab2 100644 --- a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeeListener.java +++ b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeeListener.java @@ -1,12 +1,27 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bungee; import dev.brighten.antivpn.AntiVPN; import dev.brighten.antivpn.api.*; import dev.brighten.antivpn.utils.MiscUtils; import dev.brighten.antivpn.utils.StringUtil; -import dev.brighten.antivpn.utils.Tuple; -import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.event.LoginEvent; import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PreLoginEvent; import net.md_5.bungee.api.plugin.Listener; @@ -35,7 +50,7 @@ public class BungeeListener extends VPNExecutor implements Listener { @Override public void log(String log, Object... objects) { - log(Level.INFO, String.format(log, objects)); + log(Level.INFO, log, objects); } @Override @@ -73,43 +88,31 @@ public class BungeeListener extends VPNExecutor implements Listener { ((InetSocketAddress) event.getConnection().getSocketAddress()).getAddress()); }); - CheckResult instantResult = player.checkPlayer(result -> { + player.checkPlayer(result -> { if (!result.resultType().isShouldBlock()) return; - AntiVPN.getInstance().getExecutor().getToKick() - .add(new Tuple<>(result, player.getUuid())); + + if(!AntiVPN.getInstance().getVpnConfig().isKickPlayers()) { + return; + } + + event.setCancelled(true); + event.setReason(TextComponent.fromLegacy(StringUtil.varReplace(switch (result.resultType()) { + case DENIED_PROXY -> StringUtil.varReplace(AntiVPN.getInstance().getVpnConfig() + .getKickMessage(), player, result.response()); + case DENIED_COUNTRY -> StringUtil.varReplace(AntiVPN.getInstance().getVpnConfig() + .getCountryVanillaKickReason(), player, result.response()); + default -> "You were kicked by KauriVPN for an unknown reason!"; + }, player, result.response()))); }); + } - if (!instantResult.resultType().isShouldBlock()) { - return; - } + @EventHandler(priority = EventPriority.HIGH) + public void onJoin(LoginEvent event) { + if(event.isCancelled()) return; - AntiVPN.getInstance().getExecutor().getToKick() - .add(new Tuple<>(instantResult, player.getUuid())); - - if (!AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect()) { - return; - } - - event.setCancelled(true); - AntiVPN.getInstance().getExecutor().log(Level.INFO, - "%s was kicked from pre-login proxy cache.", - event.getConnection().getName()); - - - switch (instantResult.resultType()) { - case DENIED_PROXY -> event.setReason(TextComponent.fromLegacy(ChatColor - .translateAlternateColorCodes('&', - StringUtil.varReplace( - AntiVPN.getInstance().getVpnConfig().getKickString(), - player, - instantResult.response())))); - case DENIED_COUNTRY -> event.setReason(TextComponent.fromLegacy(ChatColor - .translateAlternateColorCodes('&', - StringUtil.varReplace( - AntiVPN.getInstance().getVpnConfig().countryVanillaKickReason(), - player, - instantResult.response())))); - } + // Handling player alerts on join + AntiVPN.getInstance().getPlayerExecutor().getPlayer(event.getConnection().getUniqueId()) + .ifPresent(APIPlayer::checkAlertsState); } @EventHandler diff --git a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlayer.java b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlayer.java index 5a6b5e7..072a3cf 100644 --- a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlayer.java +++ b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlayer.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bungee; import dev.brighten.antivpn.api.APIPlayer; diff --git a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlayerExecutor.java b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlayerExecutor.java index ab77f95..cb01b91 100644 --- a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlayerExecutor.java +++ b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlayerExecutor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bungee; import dev.brighten.antivpn.api.APIPlayer; diff --git a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlugin.java b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlugin.java index f8361fd..15bb2ac 100644 --- a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlugin.java +++ b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/BungeePlugin.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bungee; import dev.brighten.antivpn.AntiVPN; @@ -69,11 +85,10 @@ public class BungeePlugin implements LoaderBootstrap { private String getDatabaseType() { VPNDatabase database = AntiVPN.getInstance().getDatabase(); - - if(database instanceof H2VPN) { - return "H2"; - } else if(database instanceof MySqlVPN) { + if(database instanceof MySqlVPN) { return "MySQL"; + } else if(database instanceof H2VPN) { + return "H2"; } else if(database instanceof MongoVPN) { return "MongoDB"; } else { diff --git a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/command/BungeeCommand.java b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/command/BungeeCommand.java index 4b4fa23..a762966 100644 --- a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/command/BungeeCommand.java +++ b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/command/BungeeCommand.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bungee.command; import dev.brighten.antivpn.AntiVPN; diff --git a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/command/BungeeCommandExecutor.java b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/command/BungeeCommandExecutor.java index 41b955e..c0d3ebb 100644 --- a/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/command/BungeeCommandExecutor.java +++ b/Bungee/BungeePlugin/src/main/java/dev/brighten/antivpn/bungee/command/BungeeCommandExecutor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.bungee.command; import dev.brighten.antivpn.AntiVPN; diff --git a/Bungee/pom.xml b/Bungee/pom.xml index 83aee15..bcc273a 100644 --- a/Bungee/pom.xml +++ b/Bungee/pom.xml @@ -1,11 +1,27 @@ + + AntiVPN dev.brighten.antivpn - 1.9.4 + 1.10.0 pom 4.0.0 diff --git a/Common/Source/pom.xml b/Common/Source/pom.xml index 44fe127..6384f17 100644 --- a/Common/Source/pom.xml +++ b/Common/Source/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn Common - 1.9.4 + 1.10.0 Source @@ -173,6 +189,12 @@ 3.12.14 provided + + org.jetbrains + annotations + 26.0.2 + compile + \ No newline at end of file diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/AntiVPN.java b/Common/Source/src/main/java/dev/brighten/antivpn/AntiVPN.java index e89821a..944b2f6 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/AntiVPN.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/AntiVPN.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn; import dev.brighten.antivpn.api.PlayerExecutor; @@ -109,7 +125,7 @@ public class AntiVPN { break; } case "mysql": - case "sql":{ + case "sql": { AntiVPN.getInstance().getExecutor().log("Using databaseType MySQL..."); INSTANCE.database = new MySqlVPN(); INSTANCE.database.init(); @@ -190,7 +206,7 @@ public class AntiVPN { executor.log("Failed to deregister H2 driver: " + e.getMessage()); } } - VPNExecutor.threadExecutor.shutdown(); + AntiVPN.getInstance().getExecutor().getThreadExecutor().shutdown(); if(database != null) database.shutdown(); } @@ -256,4 +272,4 @@ public class AntiVPN { private void registerCommands() { commands.add(new AntiVPNCommand()); } -} +} \ No newline at end of file diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/api/APIPlayer.java b/Common/Source/src/main/java/dev/brighten/antivpn/api/APIPlayer.java index 1c0f2bc..0bf5200 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/api/APIPlayer.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/api/APIPlayer.java @@ -1,8 +1,25 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.api; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import dev.brighten.antivpn.AntiVPN; +import dev.brighten.antivpn.message.VpnString; import lombok.Getter; import lombok.Setter; @@ -40,23 +57,45 @@ public abstract class APIPlayer { public void updateAlertsState() { //Updating into database so its synced across servers and saved on logout. AntiVPN.getInstance().getDatabase().updateAlertsState(uuid, alertsEnabled); + + sendMessage(AntiVPN.getInstance().getMessageHandler() + .getString("command-alerts-toggled") + .getFormattedMessage(new VpnString.Var<>("state", alertsEnabled))); } - public CheckResult checkPlayer(Consumer onKick) { + public void checkAlertsState() { + AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> + AntiVPN.getInstance().getDatabase().alertsState(uuid, state -> { + if(state) { + alertsEnabled = true; + updateAlertsState(); + } + }) + ); + } + + public void checkPlayer(Consumer onResult) { if (hasPermission("antivpn.bypass") //Has bypass permission //Is exempt || (uuid != null && AntiVPN.getInstance().getExecutor().isWhitelisted(uuid)) //Or has a name that starts with a certain prefix. This is for Bedrock exempting. - || AntiVPN.getInstance().getExecutor().isWhitelisted(ip.getHostAddress()) + || AntiVPN.getInstance().getExecutor().isWhitelisted(ip.getHostAddress() + "/32") || AntiVPN.getInstance().getVpnConfig().getPrefixWhitelists().stream() - .anyMatch(name::startsWith)) return new CheckResult(null, ResultType.WHITELISTED); + .anyMatch(name::startsWith)) { + onResult.accept(new CheckResult(null, ResultType.WHITELISTED, false)); + return; + } CheckResult cachedResult = checkResultCache.getIfPresent(ip.getHostAddress()); if(cachedResult != null) { if(cachedResult.response().getIp().equals(ip.getHostAddress())) { AntiVPN.getInstance().getExecutor().log(Level.FINE, "Cached result for " + ip.getHostAddress() + " is " + cachedResult.resultType()); - return cachedResult; + if(cachedResult.resultType().isShouldBlock()) { + AntiVPN.getInstance().getExecutor().handleKickingOfPlayer(cachedResult, this); + } + onResult.accept(cachedResult); + return; } } @@ -66,36 +105,41 @@ public abstract class APIPlayer { AntiVPN.getInstance().getExecutor().log(Level.WARNING, "The API query was not a success! " + "You may need to upgrade your license on " + "https://funkemunky.cc/shop"); + onResult.accept(new CheckResult(null, ResultType.API_FAILURE, false)); + return; } // If the countryList() size is zero, no need to check. // Running country check first CheckResult checkResult; - if (!AntiVPN.getInstance().getVpnConfig().countryList().isEmpty() + if (!AntiVPN.getInstance().getVpnConfig().getCountryList().isEmpty() && !((uuid != null && AntiVPN.getInstance().getExecutor() .isWhitelisted(uuid)) //Or has a name that starts with a certain prefix. This is for Bedrock exempting. - || AntiVPN.getInstance().getExecutor().isWhitelisted(ip.getHostAddress())) + || AntiVPN.getInstance().getExecutor().isWhitelisted(ip.getHostAddress() + "/32")) // 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() + && AntiVPN.getInstance().getVpnConfig().getCountryList() .contains(result.getCountryCode()) - != AntiVPN.getInstance().getVpnConfig().whitelistCountries()) { + != AntiVPN.getInstance().getVpnConfig().getWhitelistCountries()) { //Using our built in kicking system if no commands are configured - checkResult = new CheckResult(result, ResultType.DENIED_COUNTRY); + checkResult = new CheckResult(result, ResultType.DENIED_COUNTRY, false); } else if (result.isProxy()) { - checkResult = new CheckResult(result, ResultType.DENIED_PROXY); + checkResult = new CheckResult(result, ResultType.DENIED_PROXY, false); } else { - checkResult = new CheckResult(result, ResultType.ALLOWED); + checkResult = new CheckResult(result, ResultType.ALLOWED, false); } AntiVPN.getInstance().getExecutor().log(Level.FINE, "Result for " + ip.getHostAddress() + " is " + checkResult.resultType()); - checkResultCache.put(ip.getHostAddress(), checkResult); - onKick.accept(checkResult); + checkResultCache.put(ip.getHostAddress(), new CheckResult(checkResult.response(), checkResult.resultType(), true)); + if(checkResult.resultType().isShouldBlock()) { + AntiVPN.getInstance().getExecutor().handleKickingOfPlayer(checkResult, this); + } + onResult.accept(checkResult); AntiVPN.getInstance().checked++; }); - return new CheckResult(null, ResultType.UNKNOWN); + onResult.accept(new CheckResult(null, ResultType.UNKNOWN, false)); } } diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/api/CheckResult.java b/Common/Source/src/main/java/dev/brighten/antivpn/api/CheckResult.java index c331961..d10c57b 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/api/CheckResult.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/api/CheckResult.java @@ -1,6 +1,22 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.api; import dev.brighten.antivpn.web.objects.VPNResponse; -public record CheckResult(VPNResponse response, ResultType resultType) { +public record CheckResult(VPNResponse response, ResultType resultType, boolean isFromCache) { } diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/api/OfflinePlayer.java b/Common/Source/src/main/java/dev/brighten/antivpn/api/OfflinePlayer.java index 27ce5f7..cec0072 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/api/OfflinePlayer.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/api/OfflinePlayer.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.api; import java.net.InetAddress; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/api/PlayerExecutor.java b/Common/Source/src/main/java/dev/brighten/antivpn/api/PlayerExecutor.java index 56909dc..e5fba0c 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/api/PlayerExecutor.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/api/PlayerExecutor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.api; import java.util.List; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/api/ResultType.java b/Common/Source/src/main/java/dev/brighten/antivpn/api/ResultType.java index e8dfea4..3047385 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/api/ResultType.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/api/ResultType.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.api; import lombok.Getter; @@ -7,6 +23,7 @@ public enum ResultType { WHITELISTED(false), DENIED_COUNTRY(true), DENIED_PROXY(true), + API_FAILURE(false), UNKNOWN(false); @Getter diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/api/VPNConfig.java b/Common/Source/src/main/java/dev/brighten/antivpn/api/VPNConfig.java index 6549945..86e84e0 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/api/VPNConfig.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/api/VPNConfig.java @@ -1,7 +1,24 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.api; import dev.brighten.antivpn.AntiVPN; import dev.brighten.antivpn.utils.ConfigDefault; +import lombok.Getter; import java.util.ArrayList; import java.util.Collections; @@ -52,61 +69,60 @@ public class VPNConfig { defCountrylist = new ConfigDefault<>(new ArrayList<>(), "countries.list", AntiVPN.getInstance()); - private String license, kickMessage, databaseType, databaseName, mongoURL, username, password, ip, alertMsg, - countryVanillaKickReason; - private List prefixWhitelists, commands, countryList, countryKickCommands; + @Getter + private String license; + @Getter + private String kickMessage; + @Getter + private String databaseType; + @Getter + private String databaseName; + private String mongoURL; + @Getter + private String username; + @Getter + private String password; + @Getter + private String ip; + @Getter + private String alertMsg; + @Getter + private String countryVanillaKickReason; + @Getter + private List prefixWhitelists; + private List commands; + @Getter + private List countryList; + private List countryKickCommands; private int port; - private boolean cacheResults, databaseEnabled, useCredentials, commandsEnabled, kickPlayers, alertToStaff, - metrics, whitelistCountries; + private boolean cacheResults; + @Getter + private boolean databaseEnabled; + private boolean useCredentials; + @Getter + private boolean commandsEnabled; + @Getter + private boolean kickPlayers; + private boolean alertToStaff; + private boolean metrics; + private boolean whitelistCountries; /** - * License from https://funkemunky.cc/shop to be used for more queries. - * @return String - */ - public String getLicense() { - return license; - } - - /** - * If true, results will be cached to reduce queries to https://funkemunky.cc + * If true, results will be cached to reduce queries to ... * @return boolean */ public boolean cachedResults() { return cacheResults; } - /** - * Will be used for vanilla kick message when {@link VPNConfig#runCommands()} is true. - * @return String - */ - public String getKickString() { - return kickMessage; - } - - /** - * Message to send staff on proxy detection. - * @return String - */ - public String alertMessage() { - return alertMsg; - } - /** * If true, staff will be alerted on proxy detection. * @return boolean */ - public boolean alertToStaff() { + public boolean isAlertToSTaff() { return alertToStaff; } - /** - * If true, will run {@link VPNConfig#commands()} on detect. If not, it will use vanilla kicking methods. - * @return boolean - */ - public boolean runCommands() { - return commandsEnabled; - } - /** * Commands to run on proxy detection. * @return List @@ -115,31 +131,6 @@ public class VPNConfig { return commands; } - /** - * If false, no commands nor kick will be run on proxy detection. - * @return boolean - */ - public boolean kickPlayersOnDetect() { - return kickPlayers; - } - - /** - * Returns Strings of which are checked against the beginning of player names. Used to - * allow Geyser-connected players to join. - * @return List - */ - public List getPrefixWhitelists() { - return prefixWhitelists; - } - - /** - * Returns true if we want to use a database - * @return boolean - */ - public boolean isDatabaseEnabled() { - return databaseEnabled; - } - /** * Whether or not the database we want to connect to requires credentials. * @return boolean @@ -156,59 +147,11 @@ public class VPNConfig { return mongoURL; } - /** - * Database type. Either MySQL and Mongo. - * @return String - */ - public String getDatabaseType() { - return databaseType; - } - - /** - * Database name - * @return String - */ - public String getDatabaseName() { - return databaseName; - } - - /** - * Database username - * @return String - */ - public String getUsername() { - return username; - } - - /** - * Database Password - * @return String - */ - public String getPassword() { - return password; - } - - /** - * Database IP - * @return String - */ - public String getIp() { - return ip; - } - - /** - * Returns the list of ISO country codes we need to check. - * @return List - */ - public List countryList() { - return countryList; - } - /** * If true, we only allow the {@link VPNConfig#countryKickCommands()}. If false, we blacklist them. * @return boolean */ - public boolean whitelistCountries() { + public boolean getWhitelistCountries() { return whitelistCountries; } @@ -220,14 +163,6 @@ 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(). @@ -251,7 +186,7 @@ public class VPNConfig { /** - * If true, https://bstats.org metrics will be collected to improve KauriVPN. + * If true, ... metrics will be collected to improve KauriVPN. * @return boolean */ public boolean metrics() { @@ -287,4 +222,4 @@ public class VPNConfig { countryVanillaKickReason = defaultCountryKickReason.get(); } -} +} \ No newline at end of file diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/api/VPNExecutor.java b/Common/Source/src/main/java/dev/brighten/antivpn/api/VPNExecutor.java index 6635f94..6a9f870 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/api/VPNExecutor.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/api/VPNExecutor.java @@ -1,6 +1,23 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.api; import dev.brighten.antivpn.AntiVPN; +import dev.brighten.antivpn.utils.CIDRUtils; import dev.brighten.antivpn.utils.StringUtil; import dev.brighten.antivpn.utils.Tuple; import dev.brighten.antivpn.utils.json.JSONException; @@ -9,23 +26,20 @@ import dev.brighten.antivpn.web.objects.VPNResponse; import lombok.Getter; import java.io.IOException; +import java.net.UnknownHostException; import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.logging.Level; +@Getter public abstract class VPNExecutor { - public static ScheduledExecutorService threadExecutor = Executors.newScheduledThreadPool(2); - - @Getter + private final ScheduledExecutorService threadExecutor = Executors.newScheduledThreadPool(2); private final Set whitelisted = Collections.synchronizedSet(new HashSet<>()); - @Getter - private final Set whitelistedIps = Collections.synchronizedSet(new HashSet<>()); + private final Set whitelistedIps = Collections.synchronizedSet(new HashSet<>()); + private final Queue> toKick = new LinkedBlockingQueue<>(); + private final Queue playersToRecheck = new LinkedBlockingQueue<>(); + private ScheduledFuture kickTask = null; - @Getter - private final List> toKick = Collections.synchronizedList(new LinkedList<>()); public abstract void registerListeners(); @@ -42,15 +56,13 @@ public abstract class VPNExecutor { } public void startKickChecks() { - threadExecutor.scheduleAtFixedRate(() -> { + kickTask = threadExecutor.scheduleAtFixedRate(() -> { synchronized (toKick) { if(toKick.isEmpty()) return; - Iterator> i = toKick.iterator(); - - while(i.hasNext()) { - var toCheck = i.next(); + Tuple toCheck; + while((toCheck = toKick.poll()) != null) { Optional player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(toCheck.second()); if(player.isEmpty()) { @@ -58,48 +70,62 @@ public abstract class VPNExecutor { } handleKickingOfPlayer(toCheck.first(), player.get()); - - i.remove(); } } }, 8, 2, TimeUnit.SECONDS); } public void handleKickingOfPlayer(CheckResult result, APIPlayer player) { - if (AntiVPN.getInstance().getVpnConfig().alertToStaff()) AntiVPN.getInstance().getPlayerExecutor() + + //Ensuring kick task is always running + if(kickTask == null || kickTask.isDone() || kickTask.isCancelled()) { + startKickChecks(); + } + + if (AntiVPN.getInstance().getVpnConfig().isAlertToSTaff()) AntiVPN.getInstance().getPlayerExecutor() .getOnlinePlayers() .stream() .filter(APIPlayer::isAlertsEnabled) .forEach(pl -> pl.sendMessage(StringUtil.translateAlternateColorCodes('&', StringUtil.varReplace(dev.brighten.antivpn.AntiVPN.getInstance().getVpnConfig() - .alertMessage(), player, result.response())))); + .getAlertMsg(), player, result.response())))); - if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect()) { + if(AntiVPN.getInstance().getVpnConfig().isKickPlayers()) { switch (result.resultType()) { case DENIED_PROXY -> player.kickPlayer(StringUtil.varReplace(AntiVPN.getInstance().getVpnConfig() - .getKickString(), player, result.response())); + .getKickMessage(), player, result.response())); case DENIED_COUNTRY -> player.kickPlayer(StringUtil.varReplace(AntiVPN.getInstance().getVpnConfig() - .countryVanillaKickReason(), player, result.response())); + .getCountryVanillaKickReason(), player, result.response())); } + } else { + if(!AntiVPN.getInstance().getVpnConfig().isCommandsEnabled()) return; } - if(!AntiVPN.getInstance().getVpnConfig().runCommands()) return; + Runnable runCommands = () -> { + switch (result.resultType()) { + case DENIED_PROXY -> { + for (String command : AntiVPN.getInstance().getVpnConfig().commands()) { + runCommand(StringUtil.varReplace(command, player, result.response())); + } + } + case DENIED_COUNTRY -> { + for (String command : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) { + runCommand(StringUtil.varReplace(command, player, result.response())); + } + } + } + }; - switch (result.resultType()) { - case DENIED_PROXY -> { - for (String command : AntiVPN.getInstance().getVpnConfig().commands()) { - runCommand(StringUtil.translateAlternateColorCodes('&', - StringUtil.varReplace(command, player, result.response()))); - } - } - case DENIED_COUNTRY -> { - for (String command : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) { - runCommand(StringUtil.translateAlternateColorCodes('&', - StringUtil.varReplace(command, player, result.response()))); - } - } + // Fixes the commands running too fast and causing messaging errors by any downstream plugins like LiteBans + var scheduleResult = threadExecutor.schedule(runCommands, 1, TimeUnit.SECONDS); + + if(scheduleResult.isCancelled()) { + runCommands.run(); } + + //Ensuring players are actually kicked as they are supposed to be. + toKick.add(new Tuple<>(result, player.getUuid())); } public boolean isWhitelisted(UUID uuid) { @@ -109,11 +135,15 @@ public abstract class VPNExecutor { return whitelisted.contains(uuid); } - public boolean isWhitelisted(String ip) { + public boolean isWhitelisted(String cidr) { if(AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()) { - return AntiVPN.getInstance().getDatabase().isWhitelisted(ip); + return AntiVPN.getInstance().getDatabase().isWhitelisted(cidr); + } + try { + return whitelistedIps.contains(new CIDRUtils(cidr)); + } catch (UnknownHostException e) { + throw new RuntimeException(e); } - return whitelistedIps.contains(ip); } public CompletableFuture checkIp(String ip) { diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/command/Command.java b/Common/Source/src/main/java/dev/brighten/antivpn/command/Command.java index 893248e..43baa55 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/command/Command.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/command/Command.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.command; import java.util.List; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/command/CommandExecutor.java b/Common/Source/src/main/java/dev/brighten/antivpn/command/CommandExecutor.java index c9408ca..d781498 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/command/CommandExecutor.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/command/CommandExecutor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.command; import dev.brighten.antivpn.api.APIPlayer; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AlertsCommand.java b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AlertsCommand.java index 113bea4..445f479 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AlertsCommand.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AlertsCommand.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.command.impl; import dev.brighten.antivpn.AntiVPN; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AllowlistCommand.java b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AllowlistCommand.java index 1a0c297..bd22a1d 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AllowlistCommand.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AllowlistCommand.java @@ -1,11 +1,29 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.command.impl; import dev.brighten.antivpn.AntiVPN; import dev.brighten.antivpn.api.APIPlayer; import dev.brighten.antivpn.command.Command; import dev.brighten.antivpn.command.CommandExecutor; +import dev.brighten.antivpn.utils.CIDRUtils; import dev.brighten.antivpn.utils.MiscUtils; +import java.net.UnknownHostException; import java.util.*; import java.util.stream.Collectors; @@ -62,50 +80,87 @@ public class AllowlistCommand extends Command { if(!databaseEnabled) executor.sendMessage("&cThe database is currently not setup, " + "so any changes here will disappear after a restart."); + CIDRUtils cidrUtils; + + try { + cidrUtils = new CIDRUtils(args[1]); + } catch(IllegalArgumentException | UnknownHostException e) { + cidrUtils = null; + } + + if(cidrUtils != null) { + if(!databaseEnabled) { + return switch (args[0].toLowerCase()) { + case "add", "insert" -> { + AntiVPN.getInstance().getExecutor().getWhitelistedIps().add(cidrUtils); + yield String.format("&aAdded &6%s &ato exemption allowlist.", cidrUtils.getCidr()); + } + case "remove", "delete" -> { + AntiVPN.getInstance().getExecutor().getWhitelistedIps().remove(cidrUtils); + yield String.format("&cRemoved &%s &cfrom the exemption allowlist.", cidrUtils.getCidr()); + } + default -> "&c\"" + args[0] + "\" is not a valid argument"; + }; + } else return switch (args[0].toLowerCase()) { + case "add", "insert" -> { + AntiVPN.getInstance().getExecutor().getWhitelistedIps().add(cidrUtils); + AntiVPN.getInstance().getDatabase().addWhitelist(cidrUtils); + yield String.format("&aAdded &6%s &ato exemption allowlist.", cidrUtils.getCidr()); + } + case "remove", "delete" -> { + AntiVPN.getInstance().getExecutor().getWhitelistedIps().remove(cidrUtils); + AntiVPN.getInstance().getDatabase().removeWhitelist(cidrUtils); + yield String.format("&cRemoved &6%s &cfrom the exemption allowlist.", cidrUtils.getCidr()); + } + default -> "&c\"" + args[0] + "\" is not a valid argument"; + }; + } if(MiscUtils.isIpv4(args[1])) { if(!databaseEnabled) { - switch(args[0].toLowerCase()) { - case "add": - case "insert": { - AntiVPN.getInstance().getExecutor().getWhitelistedIps().add(args[1]); - AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], true); - return String.format("&aAdded &6%s &ato the exemption allowlist.", args[1]); - } - case "remove": - case "delete": { - AntiVPN.getInstance().getExecutor().getWhitelistedIps().remove(args[1]); - AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], false); - return String.format("&cRemoved &6%s &cfrom the exemption allowlist.", args[1]); - } - default: { - return "&c\"" + args[0] + "\" is not a valid argument"; - } + try { + return switch(args[0].toLowerCase()) { + case "add", "insert" -> { + AntiVPN.getInstance().getExecutor().getWhitelistedIps().add(new CIDRUtils(args[1] + "/32")); + AntiVPN.getInstance().getDatabase().addWhitelist(new CIDRUtils(args[1] + "/32")); + yield String.format("&aAdded &6%s &ato the exemption allowlist.", args[1] + "/32"); + } + case "remove", "delete" -> { + AntiVPN.getInstance().getExecutor().getWhitelistedIps().remove(new CIDRUtils(args[1] + "/32")); + AntiVPN.getInstance().getDatabase().removeWhitelist(new CIDRUtils(args[1] + "/32")); + yield String.format("&cRemoved &6%s &cfrom the exemption allowlist.", args[1] + "/32"); + } + default -> "&c\"" + args[0] + "\" is not a valid argument"; + }; + } catch (UnknownHostException e) { + AntiVPN.getInstance().getExecutor().logException("Invalid IP format for allowlist command", e); + return "&cInvalid IP format for allowlist command"; } } else { - switch(args[0].toLowerCase()) { - case "add": - case "insert": { - AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], true); - return String.format("&aAdded &6%s &a to the exemption allowlist.", args[1]); - } - case "remove": - case "delete": { - AntiVPN.getInstance().getDatabase().setWhitelisted(args[1], false); - return String.format("&cRemoved &6%s &c from the exemption allowlist.", args[1]); - } - default: { - return "&c\"" + args[0] + "\" is not a valid argument"; - } + try { + return switch (args[0].toLowerCase()) { + case "add", "insert" -> { + AntiVPN.getInstance().getDatabase().addWhitelist(new CIDRUtils(args[1] + "/32")); + yield String.format("&aAdded &6%s &a to the exemption allowlist.", args[1] + "/32"); + } + case "remove", "delete" -> { + AntiVPN.getInstance().getDatabase().removeWhitelist(new CIDRUtils(args[1] + "/32")); + yield String.format("&cRemoved &6%s &c from the exemption allowlist.", args[1] + "/32"); + } + default -> "&c\"" + args[0] + "\" is not a valid argument"; + }; + } catch (UnknownHostException e) { + AntiVPN.getInstance().getExecutor().logException("Invalid IP format for allowlist command", e); + return "&cInvalid IP format for allowlist command"; } } } else { - UUID uuid = null; + UUID uuid; try { uuid = UUID.fromString(args[1]); } catch(IllegalArgumentException e) { Optional player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(args[1]); - if(!player.isPresent()) { + if(player.isEmpty()) { return "&cThe player \"" + args[1] + "\" is not online, so please provide a UUID."; } @@ -113,54 +168,44 @@ public class AllowlistCommand extends Command { } if(!databaseEnabled) { - switch(args[0].toLowerCase()) { - case "add": { + return switch (args[0].toLowerCase()) { + case "add" -> { AntiVPN.getInstance().getExecutor().getWhitelisted().add(uuid); - return String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString()); + yield String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString()); } - case "remove": - case "delete": { + case "remove", "delete" -> { AntiVPN.getInstance().getExecutor().getWhitelisted().remove(uuid); - return String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString()); + yield String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString()); } - default: { - return "&c\"" + args[0] + "\" is not a valid argument"; - } - } + default -> "&c\"" + args[0] + "\" is not a valid argument"; + }; } else { - switch(args[0].toLowerCase()) { - case "add": { - AntiVPN.getInstance().getDatabase().setWhitelisted(uuid, true); - return String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString()); + return switch (args[0].toLowerCase()) { + case "add" -> { + AntiVPN.getInstance().getDatabase().addWhitelist(uuid); + yield String.format("&aAdded &6%s &auuid to the exemption allowlist.", uuid.toString()); } - case "remove": - case "delete": { - AntiVPN.getInstance().getDatabase().setWhitelisted(uuid, false); - return String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString()); + case "remove", "delete" -> { + AntiVPN.getInstance().getDatabase().removeWhitelist(uuid); + yield String.format("&cRemoved &6%s &cuuid from the exemption allowlist.", uuid.toString()); } - default: { - return "&c\"" + args[0] + "\" is not a valid argument"; - } - } + default -> "&c\"" + args[0] + "\" is not a valid argument"; + }; } } } @Override public List tabComplete(CommandExecutor executor, String alias, String[] args) { - switch(args.length) { - case 1: { - return Arrays.stream(secondArgs) - .filter(narg -> narg.toLowerCase().startsWith(args[0].toLowerCase())) - .collect(Collectors.toList()); - } - case 2: { - return AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream() - .map(APIPlayer::getName) - .filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase())) - .collect(Collectors.toList()); - } - } - return Collections.emptyList(); + return switch (args.length) { + case 1 -> Arrays.stream(secondArgs) + .filter(narg -> narg.toLowerCase().startsWith(args[0].toLowerCase())) + .collect(Collectors.toList()); + case 2 -> AntiVPN.getInstance().getPlayerExecutor().getOnlinePlayers().stream() + .map(APIPlayer::getName) + .filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase())) + .collect(Collectors.toList()); + default -> Collections.emptyList(); + }; } } diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AntiVPNCommand.java b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AntiVPNCommand.java index 48c0fda..15f23a0 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AntiVPNCommand.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/AntiVPNCommand.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.command.impl; import dev.brighten.antivpn.AntiVPN; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/ClearCacheCommand.java b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/ClearCacheCommand.java index 3ff5971..01ec9a5 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/ClearCacheCommand.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/ClearCacheCommand.java @@ -1,6 +1,23 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + 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; @@ -45,7 +62,7 @@ public class ClearCacheCommand extends Command { @Override public String execute(CommandExecutor executor, String[] args) { - AntiVPN.getInstance().getDatabase().clearResponses(); + AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> AntiVPN.getInstance().getDatabase().clearResponses()); return "&aCleared all cached API response information!"; } diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/LookupCommand.java b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/LookupCommand.java index 9949d40..4a123e2 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/LookupCommand.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/LookupCommand.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.command.impl; import dev.brighten.antivpn.AntiVPN; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/PlanCommand.java b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/PlanCommand.java index 3d4ae8f..0151b44 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/PlanCommand.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/PlanCommand.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.command.impl; import dev.brighten.antivpn.AntiVPN; @@ -51,7 +67,7 @@ public class PlanCommand extends Command { @Override public String execute(CommandExecutor executor, String[] args) { - VPNExecutor.threadExecutor.execute(() -> { + AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> { QueryResponse result; try { if(AntiVPN.getInstance().getVpnConfig().getLicense().isEmpty()) { diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/ReloadCommand.java b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/ReloadCommand.java index ebba1b4..5e3b97b 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/ReloadCommand.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/command/impl/ReloadCommand.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.command.impl; import dev.brighten.antivpn.AntiVPN; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/DatabaseException.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/DatabaseException.java new file mode 100644 index 0000000..53c62ef --- /dev/null +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/DatabaseException.java @@ -0,0 +1,23 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.brighten.antivpn.database; + +public class DatabaseException extends RuntimeException { + public DatabaseException(String message, Throwable e) { + super(message, e); + } +} diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/VPNDatabase.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/VPNDatabase.java index 2289197..02b958e 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/database/VPNDatabase.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/VPNDatabase.java @@ -1,5 +1,22 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.database; +import dev.brighten.antivpn.utils.CIDRUtils; import dev.brighten.antivpn.web.objects.VPNResponse; import java.util.List; @@ -16,21 +33,21 @@ public interface VPNDatabase { boolean isWhitelisted(UUID uuid); - boolean isWhitelisted(String ip); + boolean isWhitelisted(String cidr); - void setWhitelisted(UUID uuid, boolean whitelisted); + boolean isWhitelisted(CIDRUtils cidr); - void setWhitelisted(String ip, boolean whitelisted); + void addWhitelist(UUID uuid); + + void removeWhitelist(UUID uuid); + + void addWhitelist(CIDRUtils cidr); + + void removeWhitelist(CIDRUtils cidr); List getAllWhitelisted(); - List getAllWhitelistedIps(); - - void getStoredResponseAsync(String ip, Consumer> result); - - void isWhitelistedAsync(UUID uuid, Consumer result); - - void isWhitelistedAsync(String ip, Consumer result); + List getAllWhitelistedIps(); void alertsState(UUID uuid, Consumer result); @@ -41,4 +58,4 @@ public interface VPNDatabase { void init(); void shutdown(); -} +} \ No newline at end of file diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/local/H2VPN.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/local/H2VPN.java index 4dfcdf9..b0a1971 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/database/local/H2VPN.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/local/H2VPN.java @@ -1,22 +1,40 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.database.local; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import dev.brighten.antivpn.AntiVPN; -import dev.brighten.antivpn.api.VPNExecutor; import dev.brighten.antivpn.database.VPNDatabase; +import dev.brighten.antivpn.database.sql.utils.ExecutableStatement; import dev.brighten.antivpn.database.sql.utils.MySQL; import dev.brighten.antivpn.database.sql.utils.Query; +import dev.brighten.antivpn.database.version.Version; +import dev.brighten.antivpn.utils.CIDRUtils; import dev.brighten.antivpn.web.objects.VPNResponse; import lombok.SneakyThrows; +import java.io.File; +import java.math.BigInteger; +import java.net.UnknownHostException; 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.*; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @@ -29,7 +47,7 @@ public class H2VPN implements VPNDatabase { public H2VPN() { - VPNExecutor.threadExecutor.scheduleAtFixedRate(() -> { + AntiVPN.getInstance().getExecutor().getThreadExecutor().scheduleAtFixedRate(() -> { if(!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) return; //Refreshing whitelisted players @@ -50,20 +68,23 @@ public class H2VPN implements VPNDatabase { return Optional.empty(); VPNResponse response = cachedResponses.get(ip, ip2 -> { - try(ResultSet rs = Query.prepare("select * from `responses` where `ip` = ? limit 1").append(ip). - executeQuery()) { - if (rs != null && rs.next()) { - return 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"), - rs.getTimestamp("inserted").getTime(), -1); + try(ExecutableStatement statement = Query.prepare("select * from `responses` where `ip` = ? limit 1").append(ip)) { + try(ResultSet rs = statement.executeQuery()) { + if (rs != null && rs.next()) { + return 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"), + rs.getTimestamp("inserted").getTime(), -1); + } } } catch (SQLException e) { AntiVPN.getInstance().getExecutor().logException("There was a problem getting a response for " + ip, e); + } catch (Exception e) { + throw new RuntimeException(e); } return null; }); @@ -85,15 +106,21 @@ public class H2VPN implements VPNDatabase { if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) return; - cachedResponses.put(toCache.getIp(), toCache); + if(AntiVPN.getInstance().getVpnConfig().cachedResults()) { + cachedResponses.put(toCache.getIp(), toCache); - 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(); + try(var statement = 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())) { + statement.execute(); + } catch(SQLException e) { + AntiVPN.getInstance().getExecutor().logException("Could not cache response for IP: " + toCache.getIp(), e); + } + } } @Override @@ -101,61 +128,103 @@ public class H2VPN implements VPNDatabase { if(!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) return; - Query.prepare("delete from `responses` where `ip` = ?").append(ip).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); + try(var statement = Query.prepare("delete from `responses` where `ip` = ?").append(ip)) { + statement.execute(); + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("Could not delete response from IP: " + ip, e); } } @Override - public void setWhitelisted(String ip, boolean whitelisted) { + public boolean isWhitelisted(UUID uuid) { + if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) + return false; + try(var statement = Query.prepare("select uuid from `whitelisted` where `uuid` = ? limit 1") + .append(uuid.toString())) { + try(var set = statement.executeQuery()) { + return set != null && set.next() && set.getString("uuid") != null; + } + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("Could not check whitelist for uuid '" + uuid + "' due to SQL error.", e); + return false; + } + } + + @SneakyThrows + @Override + public boolean isWhitelisted(String cidr) { + return isWhitelisted(new CIDRUtils(cidr)); + } + + @Override + public boolean isWhitelisted(CIDRUtils cidr) { + if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) + return false; + + BigInteger start = cidr.getStartIpInt(); + BigInteger end = cidr.getEndIpInt(); + + try(var statement = Query.prepare("SELECT * FROM `whitelisted-ranges` WHERE ip_start <= ? AND ip_end >= ?") + .append(start).append(end)) { + + try(var result = statement.executeQuery()) { + return result.next(); + } + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("Could not check whitelist for cidr '" + cidr + "' due to SQL error.", e); + } + return false; + } + + @Override + public void addWhitelist(UUID uuid) { 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); + try(var statement = Query.prepare("insert into `whitelisted` (`uuid`) values (?)").append(uuid.toString())) { + statement.execute(); + AntiVPN.getInstance().getExecutor().getWhitelisted().add(uuid); + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("Could not add uuid '" + uuid + "' to whitelist due to SQL error.", e); + } + } + + @Override + public void removeWhitelist(UUID uuid) { + if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) + return; + try(var statement = Query.prepare("delete from `whitelisted` where `uuid` = ?").append(uuid.toString())) { + statement.execute(); + AntiVPN.getInstance().getExecutor().getWhitelisted().remove(uuid); + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("Could not remove uuid '" + uuid + "' from whitelist due to SQL error.", e); + } + } + + @Override + public void addWhitelist(CIDRUtils cidr) { + if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) + return; + + try(var statement = Query.prepare("insert into `whitelisted-ranges` (`cidr_string`, `ip_start`, `ip_end`) values (?, ?, ?)") + .append(cidr.toString()).append(cidr.getStartIpInt()).append(cidr.getEndIpInt())) { + statement.execute(); + + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("Could not add cidr '" + cidr + "' to whitelist due to SQL error.", e); + } + } + + @Override + public void removeWhitelist(CIDRUtils cidr) { + if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) + return; + + try(var statement = Query.prepare("delete from `whitelisted-ranges` where `cidr_string` = ?").append(cidr.toString())) { + statement.execute(); + + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("Could not remove cidr '" + cidr + "' from whitelist due to SQL error.", e); } } @@ -163,52 +232,51 @@ public class H2VPN implements VPNDatabase { public List getAllWhitelisted() { List uuids = new ArrayList<>(); - if(!MySQL.isClosed()) Query.prepare("select uuid from `whitelisted`") - .execute(set -> uuids.add(UUID.fromString(set.getString("uuid")))); + if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) + return uuids; + + try(var statement = Query.prepare("select uuid from `whitelisted`")) { + statement.execute(set -> uuids.add(UUID.fromString(set.getString("uuid")))); + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("Could not get all whitelisted players due to SQL error.", e); + } return uuids; } @Override - public List getAllWhitelistedIps() { - List ips = new ArrayList<>(); + public List getAllWhitelistedIps() { + List ips = new ArrayList<>(); - if(!MySQL.isClosed()) Query.prepare("select `ip` from `whitelisted-ips`") - .execute(set -> ips.add(set.getString("ip"))); + if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) + return ips; + try(var statement = Query.prepare("select `cidr_string`, `ip_start`, `ip_end` from `whitelisted-ranges`")) { + statement.execute(set -> { + try { + ips.add(new CIDRUtils(set.getString("cidr_string"))); + } catch (UnknownHostException e) { + AntiVPN.getInstance().getExecutor() + .logException("Could not format ip " + + set.getString("cidr_string") + " into a CIDR!", e); + } + }); + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("Could not get all whitelisted ips due to SQL error.", e); + } return ips; } - @Override - public void getStoredResponseAsync(String ip, Consumer> result) { - if(MySQL.isClosed()) return; - - VPNExecutor.threadExecutor.execute(() -> result.accept(getStoredResponse(ip))); - } - - @Override - public void isWhitelistedAsync(UUID uuid, Consumer result) { - if(MySQL.isClosed()) return; - - VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(uuid))); - } - - @Override - public void isWhitelistedAsync(String ip, Consumer result) { - if(MySQL.isClosed()) return; - - VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(ip))); - } - @Override public void alertsState(UUID uuid, Consumer result) { if(MySQL.isClosed()) return; + AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> { - VPNExecutor.threadExecutor.execute(() -> { - - try(ResultSet set = Query.prepare("select * from `alerts` where `uuid` = ? limit 1") - .append(uuid.toString()).executeQuery()) { - result.accept(set != null && set.next() && set.getString("uuid") != null); + try(var statement = Query.prepare("select * from `alerts` where `uuid` = ? limit 1") + .append(uuid.toString())) { + try(var set = statement.executeQuery()) { + result.accept(set != null && set.next() && set.getString("uuid") != null); + } } catch (SQLException e) { AntiVPN.getInstance().getExecutor().logException("There was a problem getting alerts state for " + uuid, e); result.accept(false); @@ -224,22 +292,35 @@ public class H2VPN implements VPNDatabase { //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(); + try(var statement = Query.prepare("insert into `alerts` (`uuid`) values (?)") + .append(uuid.toString())) { + statement.execute(); + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor() + .logException("There was a problem updating alerts state for " + uuid, e); + } } //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()); + } else { + try(var statement = Query.prepare("delete from `alerts` where `uuid` = ?").append(uuid.toString())) { + statement.execute(); + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("There was a problem updating alerts state for " + + uuid, e); + } + } } @Override public void clearResponses() { if(MySQL.isClosed()) return; - VPNExecutor.threadExecutor.execute(() -> Query.prepare("delete from `responses`").execute()); + try(var statement = Query.prepare("delete from `responses`")) { + statement.execute(); + } catch (SQLException e) { + AntiVPN.getInstance().getExecutor().logException("There was a problem clearing responses.", e); + } } @Override @@ -248,29 +329,19 @@ public class H2VPN implements VPNDatabase { return; AntiVPN.getInstance().getExecutor().log("Initializing H2..."); MySQL.initH2(); + try { + for (Version version : Version.h2Versions) { + if(version.needsUpdate(this)) { + version.update(this); + } + } + } catch (Exception e) { + throw new RuntimeException("Could not complete version setup due to SQL error", e); + } 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 if not exists `uuid_1` on `whitelisted` (`uuid`)").execute(); - Query.prepare("create index if not exists `ip_1` on `responses` (`ip`)").execute(); - Query.prepare("create index if not exists `proxy_1` on `responses` (`proxy`)").execute(); - Query.prepare("create index if not exists `inserted_1` on `responses` (`inserted`)").execute(); - Query.prepare("create index if not exists `ip_1` on `whitelisted-ips` (`ip`)").execute(); - } catch (Exception e) { - System.err.println("MySQL Excepton created" + e.getMessage()); - } } @Override @@ -280,4 +351,19 @@ public class H2VPN implements VPNDatabase { MySQL.shutdown(); } + + public void backupDatabase() { + File dataFolder = new File(AntiVPN.getInstance().getPluginFolder(), "databases"); + + if(!dataFolder.exists()) { + return; + } + + List files = new ArrayList<>(List.of(Optional.ofNullable(dataFolder.listFiles()).orElse(new File[0]))); + files.sort(Comparator.comparingLong(File::lastModified)); + + for (File file : files) { + MySQL.backupOldDB(file, dataFolder); + } + } } diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/local/version/First.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/local/version/First.java new file mode 100644 index 0000000..4724ca2 --- /dev/null +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/local/version/First.java @@ -0,0 +1,88 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.brighten.antivpn.database.local.version; + +import dev.brighten.antivpn.AntiVPN; +import dev.brighten.antivpn.database.DatabaseException; +import dev.brighten.antivpn.database.VPNDatabase; +import dev.brighten.antivpn.database.sql.utils.ExecutableStatement; +import dev.brighten.antivpn.database.sql.utils.Query; +import dev.brighten.antivpn.database.version.Version; +import dev.brighten.antivpn.utils.MiscUtils; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class First implements Version { + + private final List toClose = new ArrayList<>(); + @Override + public void update(VPNDatabase database) throws DatabaseException { + try { + closeOnEnd(Query.prepare("create table if not exists `whitelisted` (`uuid` varchar(36) not null)")) + .execute(); + closeOnEnd(Query.prepare("create table if not exists `whitelisted-ips` (`ip` varchar(45) not null)")) + .execute(); + closeOnEnd(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(); + closeOnEnd(Query.prepare("create table if not exists `alerts` (`uuid` varchar(36) not null)")) + .execute(); + closeOnEnd(Query.prepare("create table if not exists `database_version` (`version` int)")).execute(); + closeOnEnd(Query.prepare("insert into `database_version` (`version`) values (?)") + .append(versionNumber())).execute(); + + AntiVPN.getInstance().getExecutor().log("Creating indexes..."); + closeOnEnd(Query.prepare("create index if not exists `uuid_1` on `whitelisted` (`uuid`)")).execute(); + closeOnEnd(Query.prepare("create index if not exists `ip_1` on `responses` (`ip`)")).execute(); + closeOnEnd(Query.prepare("create index if not exists `proxy_1` on `responses` (`proxy`)")).execute(); + closeOnEnd(Query.prepare("create index if not exists `inserted_1` on `responses` (`inserted`)")).execute(); + closeOnEnd(Query.prepare("create index if not exists `ip_1` on `whitelisted-ips` (`ip`)")).execute(); + } catch (SQLException e) { + throw new DatabaseException("Failed to update database", e); + } finally { + MiscUtils.close(toClose.toArray(AutoCloseable[]::new)); + toClose.clear(); + } + } + + private ExecutableStatement closeOnEnd(ExecutableStatement statement) { + toClose.add(statement); + return statement; + } + + @Override + public int versionNumber() { + return 0; + } + + @Override + public boolean needsUpdate(VPNDatabase database) { + try(var statement = Query.prepare("select * from `database_version` where version = 0")) { + try(ResultSet set = statement.executeQuery()) { + return set.getFetchSize() == 0; + } + } catch (SQLException e) { + return true; + } + + } +} diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/local/version/Second.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/local/version/Second.java new file mode 100644 index 0000000..cf151e8 --- /dev/null +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/local/version/Second.java @@ -0,0 +1,160 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.brighten.antivpn.database.local.version; + +import dev.brighten.antivpn.AntiVPN; +import dev.brighten.antivpn.database.DatabaseException; +import dev.brighten.antivpn.database.VPNDatabase; +import dev.brighten.antivpn.database.local.H2VPN; +import dev.brighten.antivpn.database.sql.utils.ExecutableStatement; +import dev.brighten.antivpn.database.sql.utils.Query; +import dev.brighten.antivpn.database.version.Version; +import dev.brighten.antivpn.utils.CIDRUtils; +import dev.brighten.antivpn.utils.MiscUtils; + +import java.net.UnknownHostException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class Second implements Version { + private final List toClose = new ArrayList<>(); + + @Override + public void update(VPNDatabase database) throws DatabaseException { + if(database instanceof H2VPN h2VPN) { + h2VPN.backupDatabase(); + } + List whitelistedIps = new ArrayList<>(); + + try (var statement = Query.prepare("SELECT * FROM `whitelisted-ips`")) { + try(var set = statement.executeQuery()) { + while (set.next()) { + whitelistedIps.add(set.getString("ip")); + } + } + } catch (SQLException e) { + throw new DatabaseException("Could not get whitelisted ips from database!", e); + } + + try { + closeOnEnd(Query.prepare("CREATE TABLE IF NOT EXISTS `whitelisted-ranges` " + + "(id INT AUTO_INCREMENT PRIMARY KEY, " + + "cidr_string VARCHAR(45), " + + "ip_start BIGINT NOT NULL, " + + "ip_end BIGINT NOT NULL)")) + .execute(); + closeOnEnd(Query.prepare("CREATE INDEX idx_ip_range ON `whitelisted-ranges` (ip_start, ip_end)")).execute(); + + var cidrs = whitelistedIps.stream().map(ip -> { + try { + return new CIDRUtils(ip + "/32"); + } catch (UnknownHostException e) { + throw new RuntimeException("Could not format ip " + ip + " into a CIDR!", e); + } + }).toList(); + var insertStatement = Query.prepare("INSERT INTO `whitelisted-ranges` (`cidr_string`, `ip_start`, `ip_end`) VALUES (?, ?, ?)"); + for (CIDRUtils cidr : cidrs) { + insertStatement = insertStatement + .append(cidr.toString()) + .append(cidr.getStartIpInt()) + .append(cidr.getEndIpInt()) + .addBatch(); + } + + int[] updateCounts = insertStatement.executeBatch(); + + for (int updateCount : updateCounts) { + if(updateCount == 0) { + throw new RuntimeException("Could not insert a CIDR from previous whitelisted lists, attempted to restore previous database!"); + } + } + + closeOnEnd(Query.prepare("DROP INDEX ip_1 on `whitelisted-ips`")).execute(); + closeOnEnd(Query.prepare("DROP TABLE `whitelisted-ips`")).execute(); + closeOnEnd(Query.prepare("INSERT INTO `database_version` (`version`) VALUES (?)").append(versionNumber())).execute(); + } catch (Throwable e) { + AntiVPN.getInstance().getExecutor().log("Failed to update database to version 1: " + e.getMessage()); + try { + rollback(whitelistedIps); + } catch (SQLException ex) { + throw new DatabaseException("Failed to rollback database!", e); + } + throw new DatabaseException("Failed to update to version one, rolling back database!", e); + } finally { + MiscUtils.close(toClose.toArray(AutoCloseable[]::new)); + toClose.clear(); + } + + } + + private ExecutableStatement closeOnEnd(ExecutableStatement statement) { + toClose.add(statement); + return statement; + } + + private void rollback(List ipAddresses) throws SQLException { + AntiVPN.getInstance().getExecutor().log("Rolling back to version 0..."); + try(var statement = Query.prepare("DROP INDEX idx_ip_range ON `whitelisted-ranges`")) { + statement.execute(); + } + try(var statement = Query.prepare("DROP TABLE `whitelisted-ranges`")) { + statement.execute(); + } + + try(var statement = Query.prepare("DELETE FROM `database_version` WHERE version = ?").append(versionNumber())) { + statement.execute(); + } + + try(var statement = Query.prepare("CREATE TABLE IF NOT EXISTS `whitelisted-ips` (`ip` VARCHAR(45) NOT NULL)")) { + statement.execute(); + } + + try(var statement = Query.prepare("create index if not exists `ip_1` on `whitelisted-ips` (`ip`)")) { + statement.execute(); + } + + try(var statement = Query.prepare("DELETE FROM `whitelisted-ips`")) { + statement.execute(); + } + + try(var statement = Query.prepare("INSERT INTO `whitelisted-ips` (`ip`) VALUES (?)")) { + for (String ip : ipAddresses) { + statement.append(ip); + statement.addBatch(); + } + + statement.executeBatch(); + } + } + + @Override + public int versionNumber() { + return 1; + } + + @Override + public boolean needsUpdate(VPNDatabase database) { + try (var statement = Query.prepare("select * from `database_version` where version = 1")) { + try(var set = statement.executeQuery()) { + return set.getFetchSize() == 0; + } + } catch (SQLException e) { + return true; + } + } +} diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/mongo/MongoVPN.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/mongo/MongoVPN.java index 2e7c4eb..cd8fe24 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/database/mongo/MongoVPN.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/mongo/MongoVPN.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.database.mongo; import com.github.benmanes.caffeine.cache.Cache; @@ -8,23 +24,28 @@ import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; -import com.mongodb.client.model.Indexes; import com.mongodb.client.model.UpdateOptions; import dev.brighten.antivpn.AntiVPN; -import dev.brighten.antivpn.api.VPNExecutor; import dev.brighten.antivpn.database.VPNDatabase; +import dev.brighten.antivpn.database.version.Version; +import dev.brighten.antivpn.utils.CIDRUtils; import dev.brighten.antivpn.web.objects.VPNResponse; import org.bson.Document; import org.bson.conversions.Bson; +import org.bson.types.Decimal128; +import java.math.BigDecimal; +import java.net.UnknownHostException; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; public class MongoVPN implements VPNDatabase { - private MongoCollection settingsDocument, cacheDocument; + public MongoCollection settingsDocument; + MongoCollection cacheDocument; private MongoClient client; + public MongoDatabase antivpnDatabase; private final Cache cachedResponses = Caffeine.newBuilder() .expireAfterWrite(20, TimeUnit.MINUTES) @@ -32,7 +53,7 @@ public class MongoVPN implements VPNDatabase { .build(); public MongoVPN() { - VPNExecutor.threadExecutor.scheduleAtFixedRate(() -> { + AntiVPN.getInstance().getExecutor().getThreadExecutor().scheduleAtFixedRate(() -> { if(!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()) return; //Refreshing whitelisted players @@ -55,7 +76,7 @@ public class MongoVPN implements VPNDatabase { long lastUpdate = rdoc.get("lastAccess", 0L); if(System.currentTimeMillis() - lastUpdate > TimeUnit.HOURS.toMillis(1)) { - VPNExecutor.threadExecutor.execute(() -> deleteResponse(ip)); + AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> deleteResponse(ip)); return null; } @@ -83,29 +104,31 @@ public class MongoVPN implements VPNDatabase { @Override public void cacheResponse(VPNResponse toCache) { - Document rdoc = new Document("ip", toCache.getIp()); + if(AntiVPN.getInstance().getVpnConfig().cachedResults()) { + Document rdoc = new Document("ip", toCache.getIp()); - rdoc.put("asn", toCache.getAsn()); - rdoc.put("countryName", toCache.getCountryName()); - rdoc.put("countryCode", toCache.getCountryCode()); - rdoc.put("city", toCache.getCity()); - rdoc.put("isp", toCache.getIsp()); - rdoc.put("method", toCache.getMethod()); - rdoc.put("timeZone", toCache.getTimeZone()); - rdoc.put("proxy", toCache.isProxy()); - rdoc.put("cached", toCache.isCached()); - rdoc.put("success", toCache.isSuccess()); - rdoc.put("latitude", toCache.getLatitude()); - rdoc.put("longitude", toCache.getLongitude()); - rdoc.put("lastAccess", System.currentTimeMillis()); + rdoc.put("asn", toCache.getAsn()); + rdoc.put("countryName", toCache.getCountryName()); + rdoc.put("countryCode", toCache.getCountryCode()); + rdoc.put("city", toCache.getCity()); + rdoc.put("isp", toCache.getIsp()); + rdoc.put("method", toCache.getMethod()); + rdoc.put("timeZone", toCache.getTimeZone()); + rdoc.put("proxy", toCache.isProxy()); + rdoc.put("cached", toCache.isCached()); + rdoc.put("success", toCache.isSuccess()); + rdoc.put("latitude", toCache.getLatitude()); + rdoc.put("longitude", toCache.getLongitude()); + rdoc.put("lastAccess", System.currentTimeMillis()); - cachedResponses.put(toCache.getIp(), toCache); + cachedResponses.put(toCache.getIp(), toCache); - VPNExecutor.threadExecutor.execute(() -> { - Bson update = new Document("$set", rdoc); - cacheDocument.updateOne(Filters.eq("ip", toCache.getIp()), update, - new UpdateOptions().upsert(true)); - }); + AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> { + Bson update = new Document("$set", rdoc); + cacheDocument.updateOne(Filters.eq("ip", toCache.getIp()), update, + new UpdateOptions().upsert(true)); + }); + } } @Override @@ -121,42 +144,57 @@ public class MongoVPN implements VPNDatabase { } @Override - public boolean isWhitelisted(String ip) { - return settingsDocument - .find(Filters.and(Filters.eq("setting", "whitelist"), - Filters.eq("ip", ip))).first() != null; - } - - @Override - public void setWhitelisted(UUID uuid, boolean whitelisted) { - 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"), - Filters.eq("uuid", uuid.toString())))); + public boolean isWhitelisted(String cidr) { + try { + return isWhitelisted(new CIDRUtils(cidr)); + } catch (UnknownHostException e) { + AntiVPN.getInstance().getExecutor().log("Failed to check whitelist for IP: " + cidr, e); + return false; } } @Override - public void setWhitelisted(String ip, boolean whitelisted) { - if(whitelisted) { - Document wdoc = new Document("setting", "whitelist").append("ip", ip); + public boolean isWhitelisted(CIDRUtils cidr) { + var start = new Decimal128(new BigDecimal(cidr.getStartIpInt())); + var end = new Decimal128(new BigDecimal(cidr.getEndIpInt())); + return settingsDocument.find(Filters.and(Filters.eq("setting", "whitelist"), + Filters.lte("ip_start", start), Filters.gte("ip_end", end))).first() != null; + } - 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"), - Filters.eq("ip", ip)))); - } + @Override + public void addWhitelist(UUID uuid) { + Document wdoc = new Document("setting", "whitelist"); + wdoc.put("uuid", uuid.toString()); + AntiVPN.getInstance().getExecutor().getWhitelisted().add(uuid); + settingsDocument.insertOne(wdoc); + } + + @Override + public void removeWhitelist(UUID uuid) { + AntiVPN.getInstance().getExecutor().getWhitelisted().remove(uuid); + settingsDocument.deleteMany(Filters + .and( + Filters.eq("setting", "whitelist"), + Filters.eq("uuid", uuid.toString()))); + } + + @Override + public void addWhitelist(CIDRUtils cidr) { + Document doc = new Document("setting", "whitelist"); + doc.append("ip_start", new Decimal128(new BigDecimal(cidr.getStartIpInt()))); + doc.append("ip_end", new Decimal128(new BigDecimal(cidr.getEndIpInt()))); + doc.append("cidr_string", cidr.toString()); + + settingsDocument.insertOne(doc); + } + + @Override + public void removeWhitelist(CIDRUtils cidr) { + settingsDocument.deleteMany(Filters + .and( + Filters.eq("setting", "whitelist"), + Filters.eq("ip_start", new Decimal128(new BigDecimal(cidr.getStartIpInt()))), + Filters.eq("ip_end", new Decimal128(new BigDecimal(cidr.getEndIpInt()))))); } @Override @@ -169,39 +207,30 @@ public class MongoVPN implements VPNDatabase { } @Override - public List getAllWhitelistedIps() { - List ips = new ArrayList<>(); + public List getAllWhitelistedIps() { + List ips = new ArrayList<>(); settingsDocument.find(Filters.and(Filters.eq("setting", "whitelist"), - Filters.exists("ip"))) - .forEach((Consumer) doc -> ips.add(doc.getString("ip"))); + Filters.exists("ip"))).forEach((Consumer) doc -> { + try { + var cidr = new CIDRUtils(doc.getString("cidr_string")); + ips.add(cidr); + } catch (UnknownHostException e) { + AntiVPN.getInstance().getExecutor().logException("Could not format ip " + doc.getString("cidr_string") + " into a CIDR!", e); + } + }); return ips; } - @Override - public void getStoredResponseAsync(String ip, Consumer> result) { - VPNExecutor.threadExecutor.execute(() -> result.accept(getStoredResponse(ip))); - } - - @Override - public void isWhitelistedAsync(UUID uuid, Consumer result) { - VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(uuid))); - } - - @Override - public void isWhitelistedAsync(String ip, Consumer result) { - VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(ip))); - } - @Override public void alertsState(UUID uuid, Consumer result) { - VPNExecutor.threadExecutor.execute(() -> result.accept(settingsDocument + AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> result.accept(settingsDocument .find(Filters.and(Filters.eq("setting", "alerts"), Filters.eq("uuid", uuid.toString()))).first() != null)); } @Override public void updateAlertsState(UUID uuid, boolean state) { - VPNExecutor.threadExecutor.execute(() -> { + AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> { settingsDocument.deleteMany(Filters.and(Filters.eq("setting", "alerts"), Filters.eq("uuid", uuid.toString()))); if(state) { @@ -241,14 +270,17 @@ public class MongoVPN implements VPNDatabase { client = MongoClients.create(settingsBld.build()); } - MongoDatabase antivpnDatabase = client.getDatabase(AntiVPN.getInstance().getVpnConfig().getDatabaseName()); + antivpnDatabase = client.getDatabase(AntiVPN.getInstance().getVpnConfig().getDatabaseName()); settingsDocument = antivpnDatabase.getCollection("settings"); - if(settingsDocument.listIndexes().first() == null) { - AntiVPN.getInstance().getExecutor().log("Created index for settings collection!"); - settingsDocument.createIndex(Indexes.ascending("ip")); - } + cacheDocument = antivpnDatabase.getCollection("cache"); + + for (Version mongoDbVersion : Version.mongoDbVersions) { + if(mongoDbVersion.needsUpdate(this)) { + mongoDbVersion.update(this); + } + } } @Override diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/mongo/version/MongoFirst.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/mongo/version/MongoFirst.java new file mode 100644 index 0000000..8bf7203 --- /dev/null +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/mongo/version/MongoFirst.java @@ -0,0 +1,52 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.brighten.antivpn.database.mongo.version; + +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Indexes; +import dev.brighten.antivpn.AntiVPN; +import dev.brighten.antivpn.database.DatabaseException; +import dev.brighten.antivpn.database.mongo.MongoVPN; +import dev.brighten.antivpn.database.version.Version; +import org.bson.Document; + +public class MongoFirst implements Version { + + @Override + public void update(MongoVPN database) throws DatabaseException { + if(database.settingsDocument.listIndexes().first() == null) { + AntiVPN.getInstance().getExecutor().log("Created index for settings collection!"); + database.settingsDocument.createIndex(Indexes.ascending("ip")); + database.settingsDocument.createIndex(Indexes.ascending("setting")); + } + var versionCollect = database.antivpnDatabase.getCollection("version"); + + versionCollect.insertOne(new Document("version", versionNumber())); + } + + @Override + public int versionNumber() { + return 0; + } + + @Override + public boolean needsUpdate(MongoVPN database) { + var versionCollect = database.antivpnDatabase.getCollection("version"); + + return versionCollect.find(Filters.eq("version", versionNumber())).first() == null; + } +} diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/mongo/version/MongoSecond.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/mongo/version/MongoSecond.java new file mode 100644 index 0000000..c6faccc --- /dev/null +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/mongo/version/MongoSecond.java @@ -0,0 +1,84 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.brighten.antivpn.database.mongo.version; + +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Indexes; +import dev.brighten.antivpn.AntiVPN; +import dev.brighten.antivpn.database.DatabaseException; +import dev.brighten.antivpn.database.mongo.MongoVPN; +import dev.brighten.antivpn.database.version.Version; +import dev.brighten.antivpn.utils.CIDRUtils; +import org.bson.Document; +import org.bson.types.Decimal128; + +import java.math.BigDecimal; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +public class MongoSecond implements Version { + @Override + public void update(MongoVPN database) throws DatabaseException { + List backup = new ArrayList<>(); + database.settingsDocument.find(Filters.and(Filters.eq("setting", "whitelist"), + Filters.exists("ip"))) + .forEach((Consumer) doc -> { + backup.add(new Document(doc)); + + String ip = doc.getString("ip"); + + try { + var cidr = new CIDRUtils(ip + "/32"); + + doc.append("ip_start", new Decimal128(new BigDecimal(cidr.getStartIpInt()))); + doc.append("ip_end", new Decimal128(new BigDecimal(cidr.getEndIpInt()))); + doc.append("cidr_string", cidr.toString()); + doc.remove("ip"); + + database.settingsDocument.replaceOne(Filters.eq("_id", doc.getObjectId("_id")), doc); + } catch (UnknownHostException e) { + rollback(backup, database); + throw new RuntimeException(e); + } + }); + + database.settingsDocument.createIndex(Indexes.compoundIndex(Indexes.ascending("ip_start"), Indexes.ascending("ip_end"))); + database.settingsDocument.createIndex(Indexes.ascending("cidr_string")); + var versionCollect = database.antivpnDatabase.getCollection("version"); + versionCollect.insertOne(new Document("version", versionNumber())); + } + + private void rollback(List toRollback, MongoVPN database) { + AntiVPN.getInstance().getExecutor().log("Rolling back to version 0..."); + toRollback.forEach(doc -> database.settingsDocument.replaceOne(Filters.eq("_id", doc.getObjectId("_id")), doc)); + toRollback.clear(); + } + + @Override + public int versionNumber() { + return 1; + } + + @Override + public boolean needsUpdate(MongoVPN database) { + var versionCollect = database.antivpnDatabase.getCollection("version"); + + return versionCollect.find(Filters.eq("version", versionNumber())).first() == null; + } +} diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/MySqlVPN.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/MySqlVPN.java index 148f0c8..54ac223 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/MySqlVPN.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/MySqlVPN.java @@ -1,35 +1,32 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.database.sql; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; import dev.brighten.antivpn.AntiVPN; -import dev.brighten.antivpn.api.VPNExecutor; -import dev.brighten.antivpn.database.VPNDatabase; +import dev.brighten.antivpn.database.local.H2VPN; 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 dev.brighten.antivpn.database.version.Version; -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 MySqlVPN implements VPNDatabase { - - private final Cache cachedResponses = Caffeine.newBuilder() - .expireAfterWrite(20, TimeUnit.MINUTES) - .maximumSize(4000) - .build(); +public class MySqlVPN extends H2VPN { public MySqlVPN() { - VPNExecutor.threadExecutor.scheduleAtFixedRate(() -> { + AntiVPN.getInstance().getExecutor().getThreadExecutor().scheduleAtFixedRate(() -> { if(!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed()) return; //Refreshing whitelisted players @@ -44,212 +41,6 @@ public class MySqlVPN implements VPNDatabase { }, 2, 30, TimeUnit.SECONDS); } - @Override - public Optional getStoredResponse(String ip) { - if (isDisabled()) - return Optional.empty(); - - VPNResponse response = cachedResponses.get(ip, ip2 -> { - try(ResultSet rs = Query.prepare("select * from `responses` where `ip` = ? limit 1").append(ip) - .executeQuery()) { - if (rs != null && rs.next()) { - VPNResponse responseFromDoc = 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"), - rs.getTimestamp("inserted").getTime(), -1); - - if(System.currentTimeMillis() - responseFromDoc.getLastAccess() > TimeUnit.HOURS.toMillis(1)) { - VPNExecutor.threadExecutor.execute(() -> deleteResponse(ip)); - return null; - } - - return responseFromDoc; - } - } catch (SQLException e) { - AntiVPN.getInstance().getExecutor() - .logException("Failed to get response from cache due to SQL error for: " + ip, e); - } - return null; - }); - - return Optional.ofNullable(response); - } - - /* - * 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 (isDisabled()) - return; - - cachedResponses.put(toCache.getIp(), toCache); - - 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(); - } - - @Override - public void deleteResponse(String ip) { - if(!isDisabled()) - return; - - Query.prepare("delete from `responses` where `ip` = ?").append(ip).execute(); - } - - @SneakyThrows - @Override - public boolean isWhitelisted(UUID uuid) { - if (isDisabled()) - return false; - try(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 (isDisabled()) - return false; - try(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 (isDisabled()) - 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 (isDisabled()) - 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 getAllWhitelisted() { - List 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 getAllWhitelistedIps() { - List 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> result) { - if(MySQL.isClosed()) return; - - VPNExecutor.threadExecutor.execute(() -> result.accept(getStoredResponse(ip))); - } - - @Override - public void isWhitelistedAsync(UUID uuid, Consumer result) { - if(MySQL.isClosed()) return; - - VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(uuid))); - } - - @Override - public void isWhitelistedAsync(String ip, Consumer result) { - if(MySQL.isClosed()) return; - - VPNExecutor.threadExecutor.execute(() -> result.accept(isWhitelisted(ip))); - } - - @Override - public void alertsState(UUID uuid, Consumer result) { - if(MySQL.isClosed()) return; - - VPNExecutor.threadExecutor.execute(() -> { - - try(ResultSet set = Query.prepare("select * from `alerts` where `uuid` = ? limit 1") - .append(uuid.toString()).executeQuery()) { - result.accept(set != null && set.next() && set.getString("uuid") != null); - } catch (SQLException e) { - AntiVPN.getInstance().getExecutor() - .logException("Failed to get alerts state from database for: " + uuid, e); - 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()) @@ -257,106 +48,17 @@ public class MySqlVPN implements VPNDatabase { AntiVPN.getInstance().getExecutor().log("Initializing MySQL..."); MySQL.init(); - AntiVPN.getInstance().getExecutor().log("Creating tables..."); + AntiVPN.getInstance().getExecutor().log("Checking for updates..."); //Running check for old table types to update - Query.prepare("select `DATA_TYPE` from INFORMATION_SCHEMA.COLUMNS " + - "WHERE table_name = 'responses' AND COLUMN_NAME = 'isp';").execute(set -> { - if(set.getObject("DATA_TYPE").toString().contains("varchar")) { - AntiVPN.getInstance().getExecutor().log("Using old database format for storing responses! " + - "Dropping table and creating a new one..."); - if(Query.prepare("drop table `responses`").execute() > 0) { - AntiVPN.getInstance().getExecutor().log("Successfully dropped table!"); - } - } - }); - - 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 { - // Ref: - // https://dba.stackexchange.com/questions/24531/mysql-create-index-if-not-exists - - String query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE()" + - " AND table_name='whitelisted' AND index_name='uuid_1';"; - int id = 0; - try(ResultSet rs = Query.prepare(query).executeQuery()) { - while (rs.next()) { - id = rs.getInt("IndexExists"); - } - if (id == 0) { - Query.prepare("create index `uuid_1` on `whitelisted` (`uuid`)").execute(); - } - } - id = 0; - - // Responses index - query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() " + - "AND table_name='responses' AND index_name='ip_1';"; - try(ResultSet rs = Query.prepare(query).executeQuery()) { - while (rs.next()) { - id = rs.getInt("IndexExists"); - } - if (id == 0) { - Query.prepare("create index `ip_1` on `responses` (`ip`)").execute(); - } - id = 0; - } - - query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() " + - "AND table_name='responses' AND index_name='proxy_1';"; - try(ResultSet rs = Query.prepare(query).executeQuery()) { - while (rs.next()) { - id = rs.getInt("IndexExists"); - } - if (id == 0) { - Query.prepare("create index `proxy_1` on `responses` (`proxy`)").execute(); - } - id = 0; - } - query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE()" + - " AND table_name='responses' AND index_name='inserted_1';"; - try(ResultSet rs = Query.prepare(query).executeQuery()) { - while (rs.next()) { - id = rs.getInt("IndexExists"); - } - if (id == 0) { - Query.prepare("create index `inserted_1` on `responses` (`inserted`)").execute(); - } - id = 0; - } - - //Whitelisted IPs index - query = "SELECT COUNT(1) IndexExists FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE()" + - " AND table_name='whitelisted-ips' AND index_name='ip_1';"; - try(ResultSet rs = Query.prepare(query).executeQuery()) { - while (rs.next()) { - id = rs.getInt("IndexExists"); - } - if (id == 0) { - Query.prepare("create index `ip_1` on `whitelisted-ips` (`ip`)").execute(); + for (Version version : Version.mysqlVersions) { + if(version.needsUpdate(this)) { + version.update(this); } } } catch (Exception e) { - System.err.println("MySQL Excepton created" + e.getMessage()); + throw new RuntimeException("Could not complete version setup due to SQL error", e); } } - - private boolean isDisabled() { - return !AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()|| MySQL.isClosed(); - } - - @Override - public void shutdown() { - if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()) - return; - MySQL.shutdown(); - } } diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/ExecutableStatement.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/ExecutableStatement.java index f226fd0..5b0a7e6 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/ExecutableStatement.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/ExecutableStatement.java @@ -1,53 +1,51 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.database.sql.utils; -import dev.brighten.antivpn.utils.MiscUtils; +import lombok.Getter; import lombok.SneakyThrows; import java.sql.*; import java.util.UUID; -public class ExecutableStatement { - private PreparedStatement statement; +public class ExecutableStatement implements AutoCloseable { + @Getter + private final PreparedStatement statement; private int pos = 1; public ExecutableStatement(PreparedStatement statement) { this.statement = statement; } - @SneakyThrows - public Integer execute() { - try { - return statement.executeUpdate(); - } finally { - MiscUtils.close(statement); - } + public int execute() throws SQLException { + return statement.executeUpdate(); } - @SneakyThrows - public void execute(ResultSetIterator iterator) { - ResultSet rs = null; - try { - rs = statement.executeQuery(); + public void execute(ResultSetIterator iterator) throws SQLException { + try(var rs = statement.executeQuery()) { while (rs.next()) iterator.next(rs); - } finally { - MiscUtils.close(statement, rs); } } - @SneakyThrows - public void executeSingle(ResultSetIterator iterator) { - ResultSet rs = null; - try { - rs = statement.executeQuery(); - if (rs.next()) iterator.next(rs); - else iterator.next(null); - } finally { - MiscUtils.close(statement, rs); - } + public int[] executeBatch() throws SQLException { + return statement.executeBatch(); } - @SneakyThrows - public ResultSet executeQuery() { + public ResultSet executeQuery() throws SQLException { return statement.executeQuery(); } @@ -135,4 +133,15 @@ public class ExecutableStatement { statement.setBytes(pos++, obj); return this; } + + @SneakyThrows + public ExecutableStatement addBatch() { + statement.addBatch(); + return this; + } + + @Override + public void close() throws SQLException { + statement.close(); + } } diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/MySQL.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/MySQL.java index e8a1530..e2aef2e 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/MySQL.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/MySQL.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.database.sql.utils; import com.mysql.cj.jdbc.Driver; @@ -81,7 +97,7 @@ public class MySQL { } } - private static void backupOldDB(File dbFile, File dataFolder) { + public static void backupOldDB(File dbFile, File dataFolder) { if (dbFile.exists()) { try { // Optional: Make backup first @@ -91,7 +107,7 @@ public class MySQL { } else { AntiVPN.getInstance().getExecutor().log("Backup directory already exists"); } - File backupFile = new File(backupDir, "database.mv.db.backup_" + System.currentTimeMillis()); + File backupFile = new File(backupDir, dbFile.getName() + ".backup_" + System.currentTimeMillis()); Files.copy(dbFile.toPath(), backupFile.toPath()); // Actually delete the file diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/NonClosableConnection.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/NonClosableConnection.java index 38668af..724d5c2 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/NonClosableConnection.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/NonClosableConnection.java @@ -1,26 +1,17 @@ /* - * This file is part of LuckPerms, licensed under the MIT License. + * Copyright 2026 Dawson Hessler * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * http://www.apache.org/licenses/LICENSE-2.0 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.database.sql.utils; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/Query.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/Query.java index ac57c27..8c790e7 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/Query.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/Query.java @@ -1,20 +1,39 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.database.sql.utils; +import lombok.Getter; +import org.intellij.lang.annotations.Language; + import java.sql.Connection; import java.sql.SQLException; public class Query { + @Getter private static Connection conn; public static void use(Connection conn) { Query.conn = conn; } - public static ExecutableStatement prepare(String query) { - try { - return new ExecutableStatement(conn.prepareStatement(query)); - } catch (SQLException e) { - throw new RuntimeException(e); - } + @SuppressWarnings("SqlSourceToSinkFlow") + public static ExecutableStatement prepare(@Language("SQL") String sql) throws SQLException { + return new ExecutableStatement(conn.prepareStatement(sql)); } + + } diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/ResultSetIterator.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/ResultSetIterator.java index e99cd7c..fa16de4 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/ResultSetIterator.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/utils/ResultSetIterator.java @@ -1,7 +1,24 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.database.sql.utils; import java.sql.ResultSet; +import java.sql.SQLException; public interface ResultSetIterator { - void next(ResultSet rs) throws Exception; + void next(ResultSet rs) throws SQLException; } diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/version/MySQLFirst.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/version/MySQLFirst.java new file mode 100644 index 0000000..9f40d48 --- /dev/null +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/sql/version/MySQLFirst.java @@ -0,0 +1,51 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.brighten.antivpn.database.sql.version; + +import dev.brighten.antivpn.AntiVPN; +import dev.brighten.antivpn.database.DatabaseException; +import dev.brighten.antivpn.database.VPNDatabase; +import dev.brighten.antivpn.database.local.version.First; +import dev.brighten.antivpn.database.sql.utils.Query; + +import java.sql.SQLException; + +public class MySQLFirst extends First { + + @Override + public void update(VPNDatabase database) throws DatabaseException { + try(var statement = Query.prepare("select `DATA_TYPE` from INFORMATION_SCHEMA.COLUMNS " + + "WHERE table_name = 'responses' AND COLUMN_NAME = 'isp';")) { + statement.execute(set -> { + if(set.getObject("DATA_TYPE").toString().contains("varchar")) { + AntiVPN.getInstance().getExecutor().log("Using old database format for storing responses! " + + "Dropping table and creating a new one..."); + try(var state = Query.prepare("drop table `responses`")) { + if(state.execute() > 0) { + AntiVPN.getInstance().getExecutor().log("Successfully dropped table!"); + } + } + + + } + }); + } catch (SQLException e) { + throw new DatabaseException("Could not update MySQL database", e); + } + super.update(database); + } +} diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/database/version/Version.java b/Common/Source/src/main/java/dev/brighten/antivpn/database/version/Version.java new file mode 100644 index 0000000..f9340b9 --- /dev/null +++ b/Common/Source/src/main/java/dev/brighten/antivpn/database/version/Version.java @@ -0,0 +1,38 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.brighten.antivpn.database.version; + +import dev.brighten.antivpn.database.DatabaseException; +import dev.brighten.antivpn.database.local.H2VPN; +import dev.brighten.antivpn.database.local.version.First; +import dev.brighten.antivpn.database.local.version.Second; +import dev.brighten.antivpn.database.mongo.MongoVPN; +import dev.brighten.antivpn.database.mongo.version.MongoFirst; +import dev.brighten.antivpn.database.mongo.version.MongoSecond; +import dev.brighten.antivpn.database.sql.MySqlVPN; +import dev.brighten.antivpn.database.sql.version.MySQLFirst; + + +public interface Version { + void update(DB database) throws DatabaseException; + int versionNumber(); + boolean needsUpdate(DB database); + + Version[] mongoDbVersions = new Version[] {new MongoFirst(), new MongoSecond()}; + Version[] mysqlVersions = new Version[] {new MySQLFirst(), new Second()}; + Version[] h2Versions = new Version[] {new First(), new Second()}; +} \ No newline at end of file diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/depends/LibraryLoader.java b/Common/Source/src/main/java/dev/brighten/antivpn/depends/LibraryLoader.java index 8f16b26..913aada 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/depends/LibraryLoader.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/depends/LibraryLoader.java @@ -1,26 +1,17 @@ /* - * This file is part of helper, licensed under the MIT License. + * Copyright 2026 Dawson Hessler * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * http://www.apache.org/licenses/LICENSE-2.0 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.depends; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/depends/MavenLibraries.java b/Common/Source/src/main/java/dev/brighten/antivpn/depends/MavenLibraries.java index 189f737..4f11cef 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/depends/MavenLibraries.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/depends/MavenLibraries.java @@ -1,26 +1,17 @@ /* - * This file is part of helper, licensed under the MIT License. + * Copyright 2026 Dawson Hessler * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * http://www.apache.org/licenses/LICENSE-2.0 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.depends; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/depends/MavenLibrary.java b/Common/Source/src/main/java/dev/brighten/antivpn/depends/MavenLibrary.java index eed8117..f2caf49 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/depends/MavenLibrary.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/depends/MavenLibrary.java @@ -1,26 +1,17 @@ /* - * This file is part of helper, licensed under the MIT License. + * Copyright 2026 Dawson Hessler * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * http://www.apache.org/licenses/LICENSE-2.0 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.depends; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/depends/Relocate.java b/Common/Source/src/main/java/dev/brighten/antivpn/depends/Relocate.java index 32b8af5..2d4d910 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/depends/Relocate.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/depends/Relocate.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.depends; import java.lang.annotation.Documented; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/depends/Repository.java b/Common/Source/src/main/java/dev/brighten/antivpn/depends/Repository.java index 4381225..716c291 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/depends/Repository.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/depends/Repository.java @@ -1,26 +1,17 @@ /* - * This file is part of helper, licensed under the MIT License. + * Copyright 2026 Dawson Hessler * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * http://www.apache.org/licenses/LICENSE-2.0 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.depends; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/depends/URLClassLoaderAccess.java b/Common/Source/src/main/java/dev/brighten/antivpn/depends/URLClassLoaderAccess.java index a0159f0..1146da8 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/depends/URLClassLoaderAccess.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/depends/URLClassLoaderAccess.java @@ -1,26 +1,17 @@ /* - * This file is part of helper, licensed under the MIT License. + * Copyright 2026 Dawson Hessler * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * http://www.apache.org/licenses/LICENSE-2.0 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.depends; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/message/MessageHandler.java b/Common/Source/src/main/java/dev/brighten/antivpn/message/MessageHandler.java index 7649a36..be1f4e3 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/message/MessageHandler.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/message/MessageHandler.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.message; import dev.brighten.antivpn.AntiVPN; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/message/VpnString.java b/Common/Source/src/main/java/dev/brighten/antivpn/message/VpnString.java index fa6e118..8ea7865 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/message/VpnString.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/message/VpnString.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.message; import dev.brighten.antivpn.api.APIPlayer; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/CIDRUtils.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/CIDRUtils.java new file mode 100644 index 0000000..94cb251 --- /dev/null +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/CIDRUtils.java @@ -0,0 +1,131 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.brighten.antivpn.utils; + +import lombok.Getter; + +import java.math.BigInteger; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + +/** + * A class that enables to get an IP range from CIDR specification. It supports + * both IPv4 and IPv6. + */ +@Getter +public class CIDRUtils { + private final String cidr; + + private final InetAddress inetAddress; + + private InetAddress startAddress; + private BigInteger startIpInt, endIpInt; + private InetAddress endAddress; + private final int prefixLength; + + + public CIDRUtils(String cidr) throws UnknownHostException { + + this.cidr = cidr; + + /* split CIDR to address and prefix part */ + if (this.cidr.contains("/")) { + int index = this.cidr.indexOf("/"); + String addressPart = this.cidr.substring(0, index); + String networkPart = this.cidr.substring(index + 1); + + inetAddress = InetAddress.getByName(addressPart); + prefixLength = Integer.parseInt(networkPart); + + calculate(); + } else { + throw new IllegalArgumentException("not an valid CIDR format!"); + } + } + + + private void calculate() throws UnknownHostException { + + ByteBuffer maskBuffer; + int targetSize; + if (inetAddress.getAddress().length == 4) { + maskBuffer = + ByteBuffer + .allocate(4) + .putInt(-1); + targetSize = 4; + } else { + maskBuffer = ByteBuffer.allocate(16) + .putLong(-1L) + .putLong(-1L); + targetSize = 16; + } + + BigInteger mask = (new BigInteger(1, maskBuffer.array())).not().shiftRight(prefixLength); + + ByteBuffer buffer = ByteBuffer.wrap(inetAddress.getAddress()); + BigInteger ipVal = new BigInteger(1, buffer.array()); + + BigInteger startIp = ipVal.and(mask); + this.startIpInt = startIp; + BigInteger endIp = startIp.add(mask.not()); + this.endIpInt = endIp; + + byte[] startIpArr = toBytes(startIp.toByteArray(), targetSize); + byte[] endIpArr = toBytes(endIp.toByteArray(), targetSize); + + this.startAddress = InetAddress.getByAddress(startIpArr); + this.endAddress = InetAddress.getByAddress(endIpArr); + + } + + private byte[] toBytes(byte[] array, int targetSize) { + int counter = 0; + List newArr = new ArrayList(); + while (counter < targetSize && (array.length - 1 - counter >= 0)) { + newArr.add(0, array[array.length - 1 - counter]); + counter++; + } + + int size = newArr.size(); + for (int i = 0; i < (targetSize - size); i++) { + + newArr.add(0, (byte) 0); + } + + byte[] ret = new byte[newArr.size()]; + for (int i = 0; i < newArr.size(); i++) { + ret[i] = newArr.get(i); + } + return ret; + } + + public boolean isInRange(String ipAddress) throws UnknownHostException { + InetAddress address = InetAddress.getByName(ipAddress); + BigInteger start = new BigInteger(1, this.startAddress.getAddress()); + BigInteger end = new BigInteger(1, this.endAddress.getAddress()); + BigInteger target = new BigInteger(1, address.getAddress()); + + int st = start.compareTo(target); + int te = target.compareTo(end); + + return (st < 0 || st == 0) && (te < 0 || te == 0); + } +} \ No newline at end of file diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/ConfigDefault.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/ConfigDefault.java index 9a2ec06..5fe30e7 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/ConfigDefault.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/ConfigDefault.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils; import dev.brighten.antivpn.AntiVPN; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/EvictingMap.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/EvictingMap.java index 02b8a8c..46bacc6 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/EvictingMap.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/EvictingMap.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils; import lombok.Getter; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/ExtraObjectsMethodsForWeb.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/ExtraObjectsMethodsForWeb.java index 484f35e..2e50bae 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/ExtraObjectsMethodsForWeb.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/ExtraObjectsMethodsForWeb.java @@ -1,15 +1,17 @@ /* - * Copyright (C) 2016 The Guava Authors + * Copyright 2026 Dawson Hessler * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.utils; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/IpUtils.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/IpUtils.java new file mode 100644 index 0000000..bb982ec --- /dev/null +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/IpUtils.java @@ -0,0 +1,109 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.brighten.antivpn.utils; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.Inet4Address; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Optional; + +public class IpUtils { + public static Optional getIpDecimal(String address) { + try { + InetAddress inet = InetAddress.getByName(address); + + if(inet instanceof Inet4Address) { + return Optional.of(BigDecimal.valueOf(ipv4ToLong(address))); + } return Optional.of(new BigDecimal(ipv6ToDecimalFormat(address))); + } catch(Exception e) { + return Optional.empty(); + } + } + + public static long ipv4ToLong(String address) { + String[] addrArray = address.split("\\."); + + long ipDecimal = 0; + + for (int i = 0; i < addrArray.length; i++) { + + int power = 3 - i; + ipDecimal += ((Integer.parseInt(addrArray[i]) % 256 * Math.pow(256, power))); + } + + return ipDecimal; + } + + public static String getIpv4(long ip) { + StringBuilder sb = new StringBuilder(15); + + for (int i = 0; i < 4; i++) { + sb.insert(0, ip & 0xff); + + if (i < 3) { + sb.insert(0, '.'); + } + + ip >>= 8; + } + + return sb.toString(); + } + + public static boolean isIpv4(BigDecimal ip) { + return ip.compareTo(BigDecimal.valueOf(4294967295L)) <= 0; + } + + public static boolean isIpv6(BigDecimal ip) { + return ip.compareTo(BigDecimal.valueOf(4294967295L)) > 0; + } + public static boolean isIpv4(String ip) { + return ip.matches("^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$"); + } + + public static boolean isNotIp(String ip) { + return !isIpv4(ip) && !isIpv6(ip); + } + + public static boolean isIpv6(String ip) { + return ip.matches("^([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4}|:)$|^(([0-9a-fA-F]{1,4}:){0,6}([0-9a-fA-F]{1,4}|:))?(::([0-9a-fA-F]{1,4}:){0,5}([0-9a-fA-F]{1,4}|:))?$"); + } + + public static String getIpv4(BigDecimal ip) { + try { + return Inet4Address.getByAddress(ip.toBigInteger().toByteArray()).getHostAddress(); + } catch (UnknownHostException e) { + return "Error"; + } + } + + public static String getIpv6(BigDecimal ip) { + try { + return Inet6Address.getByAddress(ip.toBigInteger().toByteArray()).getHostAddress(); + } catch (UnknownHostException e) { + return "Error"; + } + } + + public static BigInteger ipv6ToDecimalFormat(String ipAddress) throws UnknownHostException { + return new BigInteger(1, Inet6Address.getByName(ipAddress).getAddress()); + } + +} diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/MiscUtils.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/MiscUtils.java index 77cde0b..28d0735 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/MiscUtils.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/MiscUtils.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils; import dev.brighten.antivpn.AntiVPN; @@ -56,18 +72,6 @@ public class MiscUtils { }; } - public static UUID formatFromMojangUUID(String mojangUUID) { - StringBuilder uuid = new StringBuilder(); - for(int i = 0; i <= 31; i++) { - uuid.append(mojangUUID.charAt(i)); - if(i == 7 || i == 11 || i == 15 || i == 19) { - uuid.append("-"); - } - } - - return UUID.fromString(uuid.toString()); - } - public static UUID lookupUUID(String playername) { try { JSONObject object = JsonReader @@ -77,12 +81,26 @@ public class MiscUtils { return UUID.fromString(object.getString("uuid")); } } catch (IOException | JSONException e) { - AntiVPN.getInstance().getExecutor().logException("Error while looking up UUID for " + playername, e); + AntiVPN.getInstance().getExecutor().logException("Error while looking up UUID for " + playername + "! Falling back to Mojang API", e); + return lookupMojangUuid(playername); } return null; } + private static UUID lookupMojangUuid(String playerName) { + try { + JSONObject object = JsonReader.readJsonFromUrl("https://api.mojang.com/users/profiles/minecraft/" + playerName); + + if(object.has("id")) { + return UUID.fromString(object.getString("id")); + } + } catch (IOException | JSONException e) { + AntiVPN.getInstance().getExecutor().logException("Error while looking up UUID for " + playerName + " from Mojang!:", e); + } + + return null; + } public static boolean isIpv4(String ip) { return ipv4.matcher(ip).matches(); diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/NonnullByDefault.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/NonnullByDefault.java index 48a1f73..33d759f 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/NonnullByDefault.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/NonnullByDefault.java @@ -1,26 +1,17 @@ /* - * This file is part of helper, licensed under the MIT License. + * Copyright 2026 Dawson Hessler * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * http://www.apache.org/licenses/LICENSE-2.0 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.utils; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/NullnessCasts.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/NullnessCasts.java index 24d68c9..59710b6 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/NullnessCasts.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/NullnessCasts.java @@ -1,15 +1,17 @@ /* - * Copyright (C) 2021 The Guava Authors + * Copyright 2026 Dawson Hessler * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.utils; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/Preconditions.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/Preconditions.java index 7d24918..ba96d8b 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/Preconditions.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/Preconditions.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/StringUtil.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/StringUtil.java index 5081aa3..2fe79fe 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/StringUtil.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/StringUtil.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils; import dev.brighten.antivpn.api.APIPlayer; @@ -12,15 +28,11 @@ public class StringUtil { return "&m-----------------------------------------------------"; } - public static String lineNoStrike(String color) { - return color + "-----------------------------------------------------"; - } - public static String varReplace(String input, APIPlayer player, VPNResponse result) { - return input.replace("%player%", player.getName()) + return translateAlternateColorCodes('&', input.replace("%player%", player.getName()) .replace("%reason%", result.getMethod()) .replace("%country%", result.getCountryName()) - .replace("%city%", result.getCity()); + .replace("%city%", result.getCity())); } public static String translateAlternateColorCodes(char altColorChar, String textToTranslate) { diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/Supplier.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/Supplier.java index c1f7365..159386e 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/Supplier.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/Supplier.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/Suppliers.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/Suppliers.java index d380307..13fef69 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/Suppliers.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/Suppliers.java @@ -1,15 +1,17 @@ /* - * Copyright (C) 2007 The Guava Authors + * Copyright 2026 Dawson Hessler * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.utils; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/Tuple.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/Tuple.java index 0e54854..1e650c6 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/Tuple.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/Tuple.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils; public record Tuple(F first, S second) { diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/Configuration.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/Configuration.java index a84a372..8bfd3a7 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/Configuration.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/Configuration.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils.config; import java.util.*; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/ConfigurationProvider.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/ConfigurationProvider.java index 47f8a48..0e12ccd 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/ConfigurationProvider.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/ConfigurationProvider.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils.config; import java.io.*; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/YamlConfiguration.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/YamlConfiguration.java index 8dcf5c9..13a88fa 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/YamlConfiguration.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/config/YamlConfiguration.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils.config; import lombok.AccessLevel; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/CDL.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/CDL.java index 6af74b3..13da975 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/CDL.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/CDL.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2002 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; /** * This provides static methods to convert comma delimited text into a diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/Cookie.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/Cookie.java index 6a6f892..8525a26 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/Cookie.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/Cookie.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2002 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; /** * Convert a web browser cookie specification to a JSONObject and back. diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/CookieList.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/CookieList.java index ba7ef02..9a2ba97 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/CookieList.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/CookieList.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2002 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; import java.util.Iterator; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/HTTP.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/HTTP.java index ac2ef25..12f596d 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/HTTP.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/HTTP.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2002 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; import java.util.Iterator; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/HTTPTokener.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/HTTPTokener.java index 7304422..d318384 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/HTTPTokener.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/HTTPTokener.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2002 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; /** * The HTTPTokener extends the JSONTokener to provide additional methods diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONArray.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONArray.java index 3f65d9b..8ab4bfc 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONArray.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONArray.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2002 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; import java.io.IOException; import java.io.Writer; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONException.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONException.java index 36fcfaa..599e3b2 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONException.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONException.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils.json; /** diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONML.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONML.java index 3001fc3..f31c6f7 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONML.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONML.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2008 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; import java.util.Iterator; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONObject.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONObject.java index e66aaea..3d487d4 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONObject.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONObject.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2002 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; import java.io.IOException; import java.io.Writer; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONString.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONString.java index 55d1c30..37c656e 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONString.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONString.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils.json; /** diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONStringer.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONStringer.java index 6287010..052c6e0 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONStringer.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONStringer.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2006 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; import java.io.StringWriter; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONTokener.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONTokener.java index a02da99..e0235b7 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONTokener.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONTokener.java @@ -1,31 +1,23 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils.json; import java.io.*; -/* -Copyright (c) 2002 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - /** * A JSONTokener takes a source string and extracts characters and tokens from * it. It is used by the JSONObject and JSONArray constructors to parse diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONWriter.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONWriter.java index aa1ec08..e57b81f 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONWriter.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JSONWriter.java @@ -1,32 +1,24 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils.json; import java.io.IOException; import java.io.Writer; -/* -Copyright (c) 2006 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - /** * JSONWriter provides a quick and convenient way of producing JSON text. * The texts produced strictly conform to JSON syntax rules. No whitespace is diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JsonReader.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JsonReader.java index dfcec2c..25d667c 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JsonReader.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/JsonReader.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.utils.json; import java.io.*; import java.net.URL; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/XML.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/XML.java index 782a908..96852ad 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/XML.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/XML.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2002 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; import java.util.Iterator; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/XMLTokener.java b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/XMLTokener.java index 9c155fa..f67c5e5 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/XMLTokener.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/utils/json/XMLTokener.java @@ -1,28 +1,20 @@ -package dev.brighten.antivpn.utils.json; - /* -Copyright (c) 2002 JSON.org + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +package dev.brighten.antivpn.utils.json; /** * The XMLTokener extends the JSONTokener to provide additional methods diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/web/FunkemunkyAPI.java b/Common/Source/src/main/java/dev/brighten/antivpn/web/FunkemunkyAPI.java index 7710325..38a5933 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/web/FunkemunkyAPI.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/web/FunkemunkyAPI.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.web; import dev.brighten.antivpn.utils.json.JSONException; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/web/objects/QueryResponse.java b/Common/Source/src/main/java/dev/brighten/antivpn/web/objects/QueryResponse.java index 3dc96bb..a44e186 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/web/objects/QueryResponse.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/web/objects/QueryResponse.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.web.objects; import dev.brighten.antivpn.utils.json.JSONException; diff --git a/Common/Source/src/main/java/dev/brighten/antivpn/web/objects/VPNResponse.java b/Common/Source/src/main/java/dev/brighten/antivpn/web/objects/VPNResponse.java index 645200e..13674e7 100644 --- a/Common/Source/src/main/java/dev/brighten/antivpn/web/objects/VPNResponse.java +++ b/Common/Source/src/main/java/dev/brighten/antivpn/web/objects/VPNResponse.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.web.objects; import dev.brighten.antivpn.utils.json.JSONException; diff --git a/Common/loader-utils/pom.xml b/Common/loader-utils/pom.xml index 9763696..2a97bec 100644 --- a/Common/loader-utils/pom.xml +++ b/Common/loader-utils/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn Common - 1.9.4 + 1.10.0 loader-utils diff --git a/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/JarInJarClassLoader.java b/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/JarInJarClassLoader.java index 4d8a4c3..3d1ccb4 100644 --- a/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/JarInJarClassLoader.java +++ b/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/JarInJarClassLoader.java @@ -1,26 +1,17 @@ /* - * This file is part of LuckPerms, licensed under the MIT License. + * Copyright 2026 Dawson Hessler * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * http://www.apache.org/licenses/LICENSE-2.0 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.loader; diff --git a/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/LoaderBootstrap.java b/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/LoaderBootstrap.java index 38cbb29..38e669c 100644 --- a/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/LoaderBootstrap.java +++ b/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/LoaderBootstrap.java @@ -1,26 +1,17 @@ /* - * This file is part of LuckPerms, licensed under the MIT License. + * Copyright 2026 Dawson Hessler * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * http://www.apache.org/licenses/LICENSE-2.0 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.loader; diff --git a/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/LoadingException.java b/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/LoadingException.java index 191ae03..85f69ac 100644 --- a/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/LoadingException.java +++ b/Common/loader-utils/src/main/java/dev/brighten/antivpn/loader/LoadingException.java @@ -1,26 +1,17 @@ /* - * This file is part of LuckPerms, licensed under the MIT License. + * Copyright 2026 Dawson Hessler * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * http://www.apache.org/licenses/LICENSE-2.0 * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package dev.brighten.antivpn.loader; diff --git a/Common/pom.xml b/Common/pom.xml index dff27de..e2c9efc 100644 --- a/Common/pom.xml +++ b/Common/pom.xml @@ -1,11 +1,27 @@ + + AntiVPN dev.brighten.antivpn - 1.9.4 + 1.10.0 pom diff --git a/Sponge/SpongeLoader/pom.xml b/Sponge/SpongeLoader/pom.xml index ba2f189..c4c6604 100644 --- a/Sponge/SpongeLoader/pom.xml +++ b/Sponge/SpongeLoader/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn Sponge - 1.9.4 + 1.10.0 ../pom.xml @@ -88,7 +104,7 @@ dev.brighten.antivpn loader-utils - 1.9.4 + 1.10.0 compile diff --git a/Sponge/SpongeLoader/src/main/java/dev/brighten/antivpn/sponge/SpongeLoaderPlugin.java b/Sponge/SpongeLoader/src/main/java/dev/brighten/antivpn/sponge/SpongeLoaderPlugin.java index d77a1eb..00ec663 100644 --- a/Sponge/SpongeLoader/src/main/java/dev/brighten/antivpn/sponge/SpongeLoaderPlugin.java +++ b/Sponge/SpongeLoader/src/main/java/dev/brighten/antivpn/sponge/SpongeLoaderPlugin.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.sponge; import com.google.inject.Inject; diff --git a/Sponge/SpongePlugin/pom.xml b/Sponge/SpongePlugin/pom.xml index d27ce7c..21fecf6 100644 --- a/Sponge/SpongePlugin/pom.xml +++ b/Sponge/SpongePlugin/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn Sponge - 1.9.4 + 1.10.0 ../pom.xml @@ -33,13 +49,13 @@ dev.brighten.antivpn loader-utils - 1.9.4 + 1.10.0 provided dev.brighten.antivpn Source - 1.9.4 + 1.10.0 provided diff --git a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongeListener.java b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongeListener.java index 47b6664..6c38d97 100644 --- a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongeListener.java +++ b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongeListener.java @@ -1,9 +1,24 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.sponge; import dev.brighten.antivpn.AntiVPN; import dev.brighten.antivpn.api.*; -import dev.brighten.antivpn.sponge.util.StringUtil; -import dev.brighten.antivpn.utils.Tuple; +import dev.brighten.antivpn.utils.StringUtil; import net.kyori.adventure.text.Component; import org.spongepowered.api.Sponge; import org.spongepowered.api.command.exception.CommandException; @@ -26,44 +41,22 @@ public class SpongeListener extends VPNExecutor { event.connection().address().getAddress() ))); - CheckResult instantResult = player.get().checkPlayer(result -> { - if(result.resultType().isShouldBlock()) { - AntiVPN.getInstance().getExecutor().getToKick().add(new Tuple<>(result, player.get().getUuid())); + player.get().checkPlayer(result -> { + if(!result.resultType().isShouldBlock()) return; + + if(!AntiVPN.getInstance().getVpnConfig().isKickPlayers()) { + return; } + + event.setCancelled(true); + event.setMessage(Component.text(switch (result.resultType()) { + case DENIED_PROXY -> StringUtil.varReplace(AntiVPN.getInstance().getVpnConfig() + .getKickMessage(), player.get(), result.response()); + case DENIED_COUNTRY -> StringUtil.varReplace(AntiVPN.getInstance().getVpnConfig() + .getCountryVanillaKickReason(), player.get(), result.response()); + default -> "You were kicked by KauriVPN for an unknown reason!"; + })); }); - - if(!instantResult.resultType().isShouldBlock()) { - return; - } - - AntiVPN.getInstance().getExecutor().getToKick().add(new Tuple<>(instantResult, player.get().getUuid())); - - if(!AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect()) { - return; - } - - AntiVPN.getInstance().getExecutor().log(Level.INFO, "%s was kicked from cache with IP %s", player.get().getName(), instantResult.response().getIp()); - - event.setCancelled(true); - switch (instantResult.resultType()) { - case DENIED_PROXY -> { - AntiVPN.getInstance().getExecutor().log(Level.INFO, player.get().getName() - + " joined on a VPN/Proxy (" + instantResult.response().getMethod() + ")"); - event.setMessage(Component.text(StringUtil - .translateColorCodes('&', AntiVPN.getInstance().getVpnConfig() - .getKickString() - .replace("%player%", player.get().getName()) - .replace("%country%", instantResult.response().getCountryName()) - .replace("%code%", instantResult.response().getCountryCode())))); - } - case DENIED_COUNTRY -> - event.setMessage(Component.text(StringUtil - .translateColorCodes('&', AntiVPN.getInstance().getVpnConfig() - .countryVanillaKickReason() - .replace("%player%", player.get().getName()) - .replace("%country%", instantResult.response().getCountryName()) - .replace("%code%", instantResult.response().getCountryCode())))); - } } @Listener @@ -90,7 +83,7 @@ public class SpongeListener extends VPNExecutor { @Override public void log(String log, Object... objects) { - log(Level.INFO, String.format(log, objects)); + log(Level.INFO, log, objects); } @Override diff --git a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlayer.java b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlayer.java index 2052eea..595bc4d 100644 --- a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlayer.java +++ b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlayer.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.sponge; import dev.brighten.antivpn.api.APIPlayer; diff --git a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlayerExecutor.java b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlayerExecutor.java index 3904633..6ac58f1 100644 --- a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlayerExecutor.java +++ b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlayerExecutor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.sponge; import com.github.benmanes.caffeine.cache.Cache; diff --git a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlugin.java b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlugin.java index 2e2f9bb..812c498 100644 --- a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlugin.java +++ b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/SpongePlugin.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.sponge; import dev.brighten.antivpn.AntiVPN; diff --git a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/command/SpongeCommand.java b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/command/SpongeCommand.java index 06ea090..281e318 100644 --- a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/command/SpongeCommand.java +++ b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/command/SpongeCommand.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.sponge.command; import dev.brighten.antivpn.AntiVPN; diff --git a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/command/SpongeCommandExecutor.java b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/command/SpongeCommandExecutor.java index de96dd5..8ccaccb 100644 --- a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/command/SpongeCommandExecutor.java +++ b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/command/SpongeCommandExecutor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.sponge.command; import dev.brighten.antivpn.AntiVPN; diff --git a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/util/StringUtil.java b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/util/StringUtil.java index 22d1a5a..bd533c6 100644 --- a/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/util/StringUtil.java +++ b/Sponge/SpongePlugin/src/main/java/dev/brighten/antivpn/sponge/util/StringUtil.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.sponge.util; public class StringUtil { diff --git a/Sponge/pom.xml b/Sponge/pom.xml index e3a38e5..2b0d1f2 100644 --- a/Sponge/pom.xml +++ b/Sponge/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn AntiVPN - 1.9.4 + 1.10.0 pom diff --git a/Universal/pom.xml b/Universal/pom.xml index 44ff3b2..e092308 100644 --- a/Universal/pom.xml +++ b/Universal/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn AntiVPN - 1.9.4 + 1.10.0 Universal diff --git a/Velocity/VelocityLoader/pom.xml b/Velocity/VelocityLoader/pom.xml index 1a52d54..1d9598b 100644 --- a/Velocity/VelocityLoader/pom.xml +++ b/Velocity/VelocityLoader/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn Velocity - 1.9.4 + 1.10.0 ../pom.xml @@ -41,13 +57,13 @@ dev.brighten.antivpn loader-utils - 1.9.4 + 1.10.0 compile dev.brighten.antivpn VelocityPlugin - 1.9.4 + 1.10.0 provided diff --git a/Velocity/VelocityLoader/src/main/java/dev/brighten/antivpn/velocity/VelocityPluginLoader.java b/Velocity/VelocityLoader/src/main/java/dev/brighten/antivpn/velocity/VelocityPluginLoader.java index 9c7add0..9bf68ba 100644 --- a/Velocity/VelocityLoader/src/main/java/dev/brighten/antivpn/velocity/VelocityPluginLoader.java +++ b/Velocity/VelocityLoader/src/main/java/dev/brighten/antivpn/velocity/VelocityPluginLoader.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.velocity; import com.google.inject.Inject; diff --git a/Velocity/VelocityPlugin/pom.xml b/Velocity/VelocityPlugin/pom.xml index d475480..45317d0 100644 --- a/Velocity/VelocityPlugin/pom.xml +++ b/Velocity/VelocityPlugin/pom.xml @@ -1,4 +1,20 @@ + + @@ -6,7 +22,7 @@ dev.brighten.antivpn AntiVPN - 1.9.4 + 1.10.0 ../../pom.xml @@ -35,7 +51,7 @@ dev.brighten.antivpn Source - 1.9.4 + 1.10.0 provided @@ -47,7 +63,7 @@ dev.brighten.antivpn loader-utils - 1.9.4 + 1.10.0 provided diff --git a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityListener.java b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityListener.java index 242379b..66e0c50 100644 --- a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityListener.java +++ b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityListener.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.velocity; import com.velocitypowered.api.event.ResultedEvent; @@ -5,14 +21,11 @@ import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.LoginEvent; import dev.brighten.antivpn.AntiVPN; import dev.brighten.antivpn.api.APIPlayer; -import dev.brighten.antivpn.api.CheckResult; import dev.brighten.antivpn.api.OfflinePlayer; import dev.brighten.antivpn.api.VPNExecutor; import dev.brighten.antivpn.utils.StringUtil; -import dev.brighten.antivpn.web.objects.VPNResponse; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import java.util.concurrent.TimeUnit; import java.util.logging.Level; public class VelocityListener extends VPNExecutor { @@ -36,135 +49,38 @@ public class VelocityListener extends VPNExecutor { event.getPlayer().getRemoteAddress().getAddress() )); - CheckResult instantResult = player.checkPlayer(result -> { + player.checkPlayer(result -> { if(!result.resultType().isShouldBlock()) return; - handleDeniedTasks(event, result); - }); + if(!AntiVPN.getInstance().getVpnConfig().isKickPlayers()) { + return; + } - if(!instantResult.resultType().isShouldBlock()) return; - - switch (instantResult.resultType()) { - case DENIED_COUNTRY -> event.setResult(ResultedEvent.ComponentResult.denied( - LegacyComponentSerializer.builder() + switch (result.resultType()) { + case DENIED_COUNTRY -> event.setResult(ResultedEvent.ComponentResult.denied( + LegacyComponentSerializer.builder() + .character('&') + .build().deserialize(AntiVPN.getInstance().getVpnConfig() + .getCountryVanillaKickReason() + .replace("%player%", event.getPlayer().getUsername()) + .replace("%country%", result.response().getCountryName()) + .replace("%code%", result.response().getCountryCode())))); + case DENIED_PROXY -> { + VelocityPlugin.INSTANCE.getLogger().info(event.getPlayer().getUsername() + + " joined on a VPN/Proxy (" + result.response().getMethod() + ")"); + event.setResult(ResultedEvent.ComponentResult.denied(LegacyComponentSerializer.builder() .character('&') .build().deserialize(AntiVPN.getInstance().getVpnConfig() - .countryVanillaKickReason() + .getKickMessage() .replace("%player%", event.getPlayer().getUsername()) - .replace("%country%", instantResult.response().getCountryName()) - .replace("%code%", instantResult.response().getCountryCode())))); - case DENIED_PROXY -> { - VelocityPlugin.INSTANCE.getLogger().info(event.getPlayer().getUsername() - + " joined on a VPN/Proxy (" + instantResult.response().getMethod() + ")"); - event.setResult(ResultedEvent.ComponentResult.denied(LegacyComponentSerializer.builder() - .character('&') - .build().deserialize(AntiVPN.getInstance().getVpnConfig() - .getKickString() - .replace("%player%", event.getPlayer().getUsername()) - .replace("%country%", instantResult.response().getCountryName()) - .replace("%code%", instantResult.response().getCountryCode())))); + .replace("%country%", result.response().getCountryName()) + .replace("%code%", result.response().getCountryCode())))); + } } - } - - handleDeniedTasks(event, instantResult, true); + }); }); } - private void handleDeniedTasks(LoginEvent event, CheckResult result) { - handleDeniedTasks(event, result, false); - } - - private void handleDeniedTasks(LoginEvent event, CheckResult checkResult, boolean deniedOnLogin) { - VPNResponse result = checkResult.response(); - //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(dev.brighten.antivpn.AntiVPN.getInstance().getVpnConfig() - .alertMessage() - .replace("%player%", - event.getPlayer().getUsername()) - .replace("%reason%", - result.getMethod()) - .replace("%country%", - result.getCountryName()) - .replace("%city%", - result.getCity()))); - - if(deniedOnLogin) return; - - //In case the user wants to run their own commands instead of using the - // built in kicking - - if(AntiVPN.getInstance().getVpnConfig().kickPlayersOnDetect()) { - switch (checkResult.resultType()) { - case DENIED_PROXY -> VelocityPlugin.INSTANCE.getServer().getScheduler() - .buildTask(VelocityPlugin.INSTANCE.getPluginInstance(), () -> - event.getPlayer().disconnect(LegacyComponentSerializer.builder() - .character('&') - .build().deserialize(AntiVPN.getInstance().getVpnConfig() - .getKickString() - .replace("%player%", event.getPlayer().getUsername()) - .replace("%country%", result.getCountryName()) - .replace("%code%", result.getCountryCode())))) - .delay(1, TimeUnit.SECONDS).schedule(); - case DENIED_COUNTRY -> VelocityPlugin.INSTANCE.getServer().getScheduler() - .buildTask(VelocityPlugin.INSTANCE.getPluginInstance(), () -> - event.getPlayer().disconnect(LegacyComponentSerializer.builder() - .character('&') - .build().deserialize(AntiVPN.getInstance().getVpnConfig() - .countryVanillaKickReason() - .replace("%player%", event.getPlayer().getUsername()) - .replace("%country%", result.getCountryName()) - .replace("%code%", result.getCountryCode())))) - .delay(1, TimeUnit.SECONDS).schedule(); - } - } - - if(!AntiVPN.getInstance().getVpnConfig().runCommands()) return; - - switch (checkResult.resultType()) { - case DENIED_PROXY -> { - for (String command : AntiVPN.getInstance().getVpnConfig().commands()) { - VelocityPlugin.INSTANCE.getServer().getCommandManager() - .executeAsync(VelocityPlugin.INSTANCE.getServer() - .getConsoleCommandSource(), - StringUtil.translateAlternateColorCodes('&', - StringUtil.varReplace( - command, - AntiVPN.getInstance().getPlayerExecutor() - .getPlayer(event.getPlayer().getUniqueId()) - .orElse(new OfflinePlayer( - event.getPlayer().getUniqueId(), - event.getPlayer().getUsername(), - event.getPlayer().getRemoteAddress().getAddress()) - ), - result))); - } - } - case DENIED_COUNTRY -> { - for (String cmd : AntiVPN.getInstance().getVpnConfig().countryKickCommands()) { - final String formattedCommand = StringUtil - .translateAlternateColorCodes('&', - StringUtil.varReplace( - cmd, - AntiVPN.getInstance().getPlayerExecutor() - .getPlayer(event.getPlayer().getUniqueId()) - .orElse(new OfflinePlayer( - event.getPlayer().getUniqueId(), - event.getPlayer().getUsername(), - event.getPlayer().getRemoteAddress().getAddress()) - ), - result)); - // Running the command from console - runCommand(formattedCommand); - } - } - } - - } - @Override public void log(Level level, String log, Object... objects) { VelocityPlugin.INSTANCE.getLogger().log(level, String.format(log, objects)); diff --git a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlayer.java b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlayer.java index b247714..eb613e4 100644 --- a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlayer.java +++ b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlayer.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.velocity; import com.velocitypowered.api.proxy.Player; @@ -28,4 +44,6 @@ public class VelocityPlayer extends APIPlayer { public boolean hasPermission(String permission) { return player.hasPermission(permission); } + + } diff --git a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlayerExecutor.java b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlayerExecutor.java index 6c589ee..f137ba6 100644 --- a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlayerExecutor.java +++ b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlayerExecutor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.velocity; import com.velocitypowered.api.proxy.Player; diff --git a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlugin.java b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlugin.java index 29d3dc4..10760a1 100644 --- a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlugin.java +++ b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/VelocityPlugin.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.velocity; import com.velocitypowered.api.proxy.ProxyServer; @@ -45,12 +61,11 @@ public class VelocityPlugin implements LoaderBootstrap { private String getDatabaseType() { VPNDatabase database = AntiVPN.getInstance().getDatabase(); - - if(database instanceof H2VPN) { - return "H2"; - } else if(database instanceof MySqlVPN) { + if(database instanceof MySqlVPN) { return "MySQL"; - } else if(database instanceof MongoVPN) { + } else if(database instanceof H2VPN) { + return "H2"; + } else if(database instanceof MongoVPN) { return "MongoDB"; } else { return "No-Database"; @@ -88,7 +103,6 @@ public class VelocityPlugin implements LoaderBootstrap { @Override public void onDisable() { - logger.info("Disabling AntiVPN..."); AntiVPN.getInstance().getExecutor().log("Disabling AntiVPN..."); if (AntiVPN.getInstance().getDatabase() != null) { diff --git a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/command/VelocityCommand.java b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/command/VelocityCommand.java index dc49c65..b372f0b 100644 --- a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/command/VelocityCommand.java +++ b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/command/VelocityCommand.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.velocity.command; import com.velocitypowered.api.command.CommandSource; diff --git a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/command/VelocityCommandExecutor.java b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/command/VelocityCommandExecutor.java index b581543..1a08dbf 100644 --- a/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/command/VelocityCommandExecutor.java +++ b/Velocity/VelocityPlugin/src/main/java/dev/brighten/antivpn/velocity/command/VelocityCommandExecutor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2026 Dawson Hessler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package dev.brighten.antivpn.velocity.command; import com.velocitypowered.api.command.CommandSource; diff --git a/Velocity/pom.xml b/Velocity/pom.xml index a88309c..d126240 100644 --- a/Velocity/pom.xml +++ b/Velocity/pom.xml @@ -1,11 +1,27 @@ + + AntiVPN dev.brighten.antivpn - 1.9.4 + 1.10.0 pom 4.0.0 diff --git a/pom.xml b/pom.xml index f895638..8916900 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,20 @@ + + @@ -7,7 +23,7 @@ dev.brighten.antivpn AntiVPN pom - 1.9.4 + 1.10.0 Common