mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-06-04 10:52:20 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d46d25db1 | |||
| 89b20df703 | |||
| aa0dc4001a | |||
| 2e079079d7 | |||
|
8185c9aad0
|
|||
|
5f07b2393a
|
|||
|
775d29114a
|
|||
| ee07deb68f | |||
| 1acdfe8c4b | |||
| 57109e4c97 |
@@ -5,31 +5,28 @@ jobs:
|
|||||||
build-and-release:
|
build-and-release:
|
||||||
name: Build and Release
|
name: Build and Release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
JAVA_TOOL_OPTIONS: -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -Djavax.net.ssl.trustStorePassword=changeit
|
||||||
steps:
|
steps:
|
||||||
- name: Cache local Maven repository
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: ~/.m2/repository
|
|
||||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-maven-
|
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- name: Set up JDK 21
|
- name: Set up JDK 21
|
||||||
uses: actions/setup-java@v5
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
distribution: 'zulu'
|
distribution: 'zulu'
|
||||||
- name: Set up Maven
|
- name: Set up Gradle
|
||||||
uses: stCarolas/setup-maven@v5
|
uses: gradle/actions/setup-gradle@v4
|
||||||
with:
|
with:
|
||||||
maven-version: 3.9.6
|
gradle-version: '9.4.1'
|
||||||
- name: Compile
|
- name: Build
|
||||||
run: mvn -B package --file pom.xml
|
run: gradle build --no-daemon
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Get Version Number from Pom
|
- name: Get Version Number from Gradle
|
||||||
id: get_version
|
id: get_version
|
||||||
run: echo "VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
|
run: |
|
||||||
|
VERSION=$(gradle properties -q | awk -F': ' '/^version:/ {print $2; exit}')
|
||||||
|
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
|
||||||
- name: Extract latest CHANGELOG entry
|
- name: Extract latest CHANGELOG entry
|
||||||
id: changelog
|
id: changelog
|
||||||
run: |
|
run: |
|
||||||
@@ -37,7 +34,7 @@ jobs:
|
|||||||
CHANGELOG_ESCAPED=$(echo "$CHANGELOG_CONTENT" | sed ':a;N;$!ba;s/\n/%0A/g')
|
CHANGELOG_ESCAPED=$(echo "$CHANGELOG_CONTENT" | sed ':a;N;$!ba;s/\n/%0A/g')
|
||||||
echo "Extracted latest release notes from CHANGELOG.md:"
|
echo "Extracted latest release notes from CHANGELOG.md:"
|
||||||
echo -e "$CHANGELOG_CONTENT"
|
echo -e "$CHANGELOG_CONTENT"
|
||||||
echo "::set-output name=content::$CHANGELOG_ESCAPED"
|
echo "content=$CHANGELOG_ESCAPED" >> "$GITHUB_OUTPUT"
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
id: create_release
|
id: create_release
|
||||||
@@ -54,6 +51,6 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
asset_path: ./Universal/target/AntiVPN-${{ env.VERSION }}-universal.jar
|
asset_path: ./build/libs/AntiVPN-${{ env.VERSION }}-universal.jar
|
||||||
asset_name: AntiVPN-v${{ env.VERSION }}.jar
|
asset_name: AntiVPN-v${{ env.VERSION }}.jar
|
||||||
asset_content_type: application/java-archive
|
asset_content_type: application/java-archive
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
pull_request:
|
||||||
|
branches: [master]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build and Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
JAVA_TOOL_OPTIONS: -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -Djavax.net.ssl.trustStorePassword=changeit
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Set up JDK 21
|
||||||
|
uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
java-version: '21'
|
||||||
|
distribution: 'zulu'
|
||||||
|
- name: Set up Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v4
|
||||||
|
with:
|
||||||
|
gradle-version: '9.4.1'
|
||||||
|
- name: Build
|
||||||
|
run: gradle build -x test --no-daemon
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Upload AntiVPN
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: AntiVPN-Universal
|
||||||
|
path: build/libs/AntiVPN-*-universal.jar
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [master]
|
|
||||||
pull_request:
|
|
||||||
branches: [master]
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build and Test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Cache local Maven repository
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: ~/.m2/repository
|
|
||||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-maven-
|
|
||||||
- uses: actions/checkout@v5
|
|
||||||
- name: Set up JDK 21
|
|
||||||
uses: actions/setup-java@v5
|
|
||||||
with:
|
|
||||||
java-version: '21'
|
|
||||||
distribution: 'zulu'
|
|
||||||
- name: Set up Maven
|
|
||||||
uses: stCarolas/setup-maven@v5
|
|
||||||
with:
|
|
||||||
maven-version: 3.9.6
|
|
||||||
- name: Compile
|
|
||||||
run: mvn -B package --file pom.xml
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
- name: Upload AntiVPN
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: AntiVPN-Universal
|
|
||||||
path: Universal/target/AntiVPN-*.jar
|
|
||||||
- name: Upload Sponge plugin
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: AntiVPN-Sponge
|
|
||||||
path: Sponge/target/Sponge-*.jar
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
JAVA_TOOL_OPTIONS: -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -Djavax.net.ssl.trustStorePassword=changeit
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Set up JDK 21
|
||||||
|
uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
java-version: '21'
|
||||||
|
distribution: 'zulu'
|
||||||
|
- name: Set up Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v4
|
||||||
|
with:
|
||||||
|
gradle-version: '9.4.1'
|
||||||
|
- name: Build
|
||||||
|
run: gradle build -x test --no-daemon
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Upload AntiVPN
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: AntiVPN-Universal
|
||||||
|
path: build/libs/AntiVPN-*-universal.jar
|
||||||
|
|
||||||
|
build-and-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
JAVA_TOOL_OPTIONS: -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -Djavax.net.ssl.trustStorePassword=changeit
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Set up JDK 21
|
||||||
|
uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
java-version: '21'
|
||||||
|
distribution: 'zulu'
|
||||||
|
- name: Set up Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v4
|
||||||
|
with:
|
||||||
|
gradle-version: '9.4.1'
|
||||||
|
- name: Build and Test
|
||||||
|
run: gradle build --no-daemon
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
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 }}
|
|
||||||
@@ -188,6 +188,7 @@ fabric.properties
|
|||||||
|
|
||||||
# Package Files #
|
# Package Files #
|
||||||
*.jar
|
*.jar
|
||||||
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
*.war
|
*.war
|
||||||
*.nar
|
*.nar
|
||||||
*.ear
|
*.ear
|
||||||
@@ -293,3 +294,5 @@ $RECYCLE.BIN/
|
|||||||
*.lnk
|
*.lnk
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/windows,macos,linux,maven,java,intellij,eclipse,netbeans
|
# End of https://www.toptal.com/developers/gitignore/api/windows,macos,linux,maven,java,intellij,eclipse,netbeans
|
||||||
|
/.gradle/
|
||||||
|
.grade/**
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.gradleup.shadow'
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluationDependsOn(':Bukkit:Plugin')
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT'
|
||||||
|
compileOnly project(':Bukkit:Plugin')
|
||||||
|
implementation project(':Common:loader-utils')
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set('')
|
||||||
|
|
||||||
|
// Include the shaded plugin jar as a single resource file
|
||||||
|
from(project(':Bukkit:Plugin').tasks.shadowJar) {
|
||||||
|
rename { 'antivpn-bukkit.jarinjar' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the plugin is built before packaging the loader
|
||||||
|
tasks.named('shadowJar') {
|
||||||
|
dependsOn(':Bukkit:Plugin:shadowJar')
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.build.dependsOn shadowJar
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Bukkit</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</parent>
|
|
||||||
<groupId>dev.brighten.antivpn.bukkit</groupId>
|
|
||||||
<artifactId>Loader</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>spigot-repo</id>
|
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<minimizeJar>false</minimizeJar>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
|
|
||||||
<resource>antivpn-bukkit.jarinjar</resource>
|
|
||||||
<file>${project.parent.basedir}/Plugin/target/Plugin-${project.version}.jar</file>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot-api</artifactId>
|
|
||||||
<version>1.20.2-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Plugin</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>loader-utils</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.gradleup.shadow'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT'
|
||||||
|
implementation project(':Common:Source')
|
||||||
|
implementation project(':Common:loader-utils')
|
||||||
|
implementation 'org.bstats:bstats-bukkit:2.2.1'
|
||||||
|
testImplementation 'com.github.seeseemelk:MockBukkit-v1.20:3.84.0'
|
||||||
|
testImplementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
|
||||||
|
testImplementation 'org.mockito:mockito-core:5.11.0'
|
||||||
|
testImplementation 'org.mockito:mockito-subclass:5.11.0'
|
||||||
|
testImplementation 'org.mockito:mockito-junit-jupiter:5.11.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set('')
|
||||||
|
relocate 'org.bstats', 'dev.brighten.antivpn.bukkit.org.bstats'
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
systemProperty 'mockito.mockmaker', 'subclass'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.build.dependsOn shadowJar
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Bukkit</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>Plugin</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>spigot-repo</id>
|
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<minimizeJar>false</minimizeJar>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.bstats</pattern>
|
|
||||||
<!-- Replace this with your package! -->
|
|
||||||
<shadedPattern>dev.brighten.antivpn.bukkit.org.bstats</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.yaml.snakeyaml</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.yaml.snakeyaml</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot-api</artifactId>
|
|
||||||
<version>1.20.2-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Source</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bstats</groupId>
|
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
|
||||||
<version>2.2.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>loader-utils</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -30,6 +30,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@@ -58,8 +59,12 @@ public class BukkitListener extends VPNExecutor implements Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runCommand(String command) {
|
public void runCommand(String command) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
new BukkitRunnable() {
|
||||||
ChatColor.translateAlternateColorCodes('&', command));
|
public void run() {
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
||||||
|
ChatColor.translateAlternateColorCodes('&', command));
|
||||||
|
}
|
||||||
|
}.runTask(BukkitPlugin.pluginInstance.getPlugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package dev.brighten.antivpn.bukkit;
|
package dev.brighten.antivpn.bukkit;
|
||||||
|
|
||||||
import dev.brighten.antivpn.api.APIPlayer;
|
import dev.brighten.antivpn.api.APIPlayer;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
@@ -26,7 +25,7 @@ public class BukkitPlayer extends APIPlayer {
|
|||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
public BukkitPlayer(Player player) {
|
public BukkitPlayer(Player player) {
|
||||||
super(player.getUniqueId(), player.getName(), player.getAddress().getAddress());
|
super(player.getUniqueId(), player.getName(), player.getAddress() != null ? player.getAddress().getAddress() : null);
|
||||||
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
@@ -38,13 +37,11 @@ public class BukkitPlayer extends APIPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kickPlayer(String reason) {
|
public void kickPlayer(String reason) {
|
||||||
if(!Bukkit.isPrimaryThread()) {
|
new BukkitRunnable() {
|
||||||
new BukkitRunnable() {
|
public void run() {
|
||||||
public void run() {
|
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', reason));
|
||||||
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', reason));
|
}
|
||||||
}
|
}.runTask(BukkitPlugin.pluginInstance.getPlugin());
|
||||||
}.runTask(BukkitPlugin.pluginInstance.getPlugin());
|
|
||||||
} else player.kickPlayer(ChatColor.translateAlternateColorCodes('&', reason));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,200 @@
|
|||||||
|
package dev.brighten.antivpn.bukkit;
|
||||||
|
|
||||||
|
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||||
|
import be.seeseemelk.mockbukkit.ServerMock;
|
||||||
|
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||||
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
import dev.brighten.antivpn.api.PlayerExecutor;
|
||||||
|
import dev.brighten.antivpn.api.VPNConfig;
|
||||||
|
import dev.brighten.antivpn.api.VPNExecutor;
|
||||||
|
import dev.brighten.antivpn.message.MessageHandler;
|
||||||
|
import dev.brighten.antivpn.message.VpnString;
|
||||||
|
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
public class BukkitListenerTest {
|
||||||
|
|
||||||
|
private ServerMock server;
|
||||||
|
private BukkitListener listener;
|
||||||
|
private VPNExecutor vpnExecutor;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
server = MockBukkit.mock(new RecordingServerMock());
|
||||||
|
JavaPlugin plugin = MockBukkit.loadWith(
|
||||||
|
TestPlugin.class,
|
||||||
|
new PluginDescriptionFile("AntiVPNTest", "1.0.0", TestPlugin.class.getName())
|
||||||
|
);
|
||||||
|
BukkitPlugin.pluginInstance = new BukkitPlugin(plugin);
|
||||||
|
|
||||||
|
AntiVPN antiVPN = mock(AntiVPN.class);
|
||||||
|
VPNConfig config = mock(VPNConfig.class);
|
||||||
|
PlayerExecutor playerExecutor = mock(PlayerExecutor.class);
|
||||||
|
vpnExecutor = mock(VPNExecutor.class);
|
||||||
|
MessageHandler messageHandler = mock(MessageHandler.class);
|
||||||
|
|
||||||
|
when(antiVPN.getVpnConfig()).thenReturn(config);
|
||||||
|
when(antiVPN.getPlayerExecutor()).thenReturn(playerExecutor);
|
||||||
|
when(antiVPN.getExecutor()).thenReturn(vpnExecutor);
|
||||||
|
when(antiVPN.getMessageHandler()).thenReturn(messageHandler);
|
||||||
|
|
||||||
|
when(playerExecutor.getPlayer(any(UUID.class))).thenReturn(Optional.empty());
|
||||||
|
when(config.getPrefixWhitelists()).thenReturn(java.util.Collections.emptyList());
|
||||||
|
when(config.getCountryList()).thenReturn(java.util.Collections.emptyList());
|
||||||
|
when(config.isKickPlayers()).thenReturn(true);
|
||||||
|
when(config.getKickMessage()).thenReturn("Blocked!");
|
||||||
|
|
||||||
|
VpnString mockVpnString = mock(VpnString.class);
|
||||||
|
when(mockVpnString.getFormattedMessage(any())).thenReturn("Blocked!");
|
||||||
|
when(messageHandler.getString(anyString())).thenReturn(mockVpnString);
|
||||||
|
|
||||||
|
when(vpnExecutor.checkIp(anyString())).thenReturn(CompletableFuture.completedFuture(
|
||||||
|
VPNResponse.builder().success(true).proxy(false).ip("127.0.0.1")
|
||||||
|
.method("N/A").countryName("N/A").city("N/A").build()
|
||||||
|
));
|
||||||
|
|
||||||
|
// Use reflection to set the private static INSTANCE field
|
||||||
|
Field instanceField = AntiVPN.class.getDeclaredField("INSTANCE");
|
||||||
|
instanceField.setAccessible(true);
|
||||||
|
instanceField.set(null, antiVPN);
|
||||||
|
|
||||||
|
listener = new BukkitListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
// Reset the singleton
|
||||||
|
Field instanceField = AntiVPN.class.getDeclaredField("INSTANCE");
|
||||||
|
instanceField.setAccessible(true);
|
||||||
|
instanceField.set(null, null);
|
||||||
|
BukkitPlugin.pluginInstance = null;
|
||||||
|
|
||||||
|
MockBukkit.unmock();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoginEventAllowed() throws Exception {
|
||||||
|
PlayerMock player = server.addPlayer("TestPlayer");
|
||||||
|
InetAddress address = InetAddress.getByName("127.0.0.1");
|
||||||
|
|
||||||
|
PlayerLoginEvent event = new PlayerLoginEvent(player, "localhost", address);
|
||||||
|
|
||||||
|
listener.onLogin(event);
|
||||||
|
|
||||||
|
assertEquals(PlayerLoginEvent.Result.ALLOWED, event.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoginEventBlocked() throws Exception {
|
||||||
|
PlayerMock player = server.addPlayer("ProxyPlayer");
|
||||||
|
InetAddress address = InetAddress.getByName("1.1.1.1");
|
||||||
|
|
||||||
|
// Mock proxy response
|
||||||
|
when(vpnExecutor.checkIp("1.1.1.1")).thenReturn(CompletableFuture.completedFuture(
|
||||||
|
VPNResponse.builder().success(true).proxy(true).ip("1.1.1.1")
|
||||||
|
.method("N/A").countryName("N/A").countryCode("N/A").city("N/A").build()
|
||||||
|
));
|
||||||
|
|
||||||
|
PlayerLoginEvent event = new PlayerLoginEvent(player, "localhost", address);
|
||||||
|
|
||||||
|
listener.onLogin(event);
|
||||||
|
|
||||||
|
assertEquals(PlayerLoginEvent.Result.KICK_BANNED, event.getResult());
|
||||||
|
assertEquals("Blocked!", net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(event.kickMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoginPipelineProxyPlayerIsKickedWithoutErrors() throws Exception {
|
||||||
|
PlayerMock player = server.addPlayer("PipelineProxyPlayer");
|
||||||
|
InetAddress address = InetAddress.getByName("1.1.1.1");
|
||||||
|
|
||||||
|
when(vpnExecutor.checkIp("1.1.1.1")).thenReturn(CompletableFuture.completedFuture(
|
||||||
|
VPNResponse.builder().success(true).proxy(true).ip("1.1.1.1")
|
||||||
|
.method("N/A").countryName("N/A").countryCode("N/A").city("N/A").build()
|
||||||
|
));
|
||||||
|
|
||||||
|
PlayerLoginEvent event = new PlayerLoginEvent(player, "localhost", address);
|
||||||
|
|
||||||
|
assertDoesNotThrow(() -> listener.onLogin(event));
|
||||||
|
|
||||||
|
assertEquals(PlayerLoginEvent.Result.KICK_BANNED, event.getResult());
|
||||||
|
assertEquals("Blocked!", net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(event.kickMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRunCommandDispatchesOnPrimaryThreadWhenCalledAsynchronously() {
|
||||||
|
RecordingServerMock recordingServer = (RecordingServerMock) server;
|
||||||
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
|
try {
|
||||||
|
CompletableFuture<Void> asyncCall = CompletableFuture.runAsync(
|
||||||
|
() -> listener.runCommand("antivpn-test &aok"),
|
||||||
|
executor
|
||||||
|
);
|
||||||
|
|
||||||
|
assertDoesNotThrow(() -> asyncCall.get(5, TimeUnit.SECONDS));
|
||||||
|
assertFalse(recordingServer.commandDispatched(), "Command should be scheduled, not dispatched asynchronously");
|
||||||
|
|
||||||
|
server.getScheduler().performOneTick();
|
||||||
|
|
||||||
|
assertTrue(recordingServer.commandDispatched(), "Scheduled command should be dispatched on the next server tick");
|
||||||
|
assertTrue(recordingServer.dispatchedOnPrimaryThread(), "Command dispatch must happen on Bukkit's primary thread");
|
||||||
|
assertEquals("antivpn-test §aok", recordingServer.dispatchedCommand());
|
||||||
|
} finally {
|
||||||
|
executor.shutdownNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TestPlugin extends JavaPlugin {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class RecordingServerMock extends ServerMock {
|
||||||
|
private final AtomicBoolean commandDispatched = new AtomicBoolean();
|
||||||
|
private final AtomicBoolean dispatchedOnPrimaryThread = new AtomicBoolean();
|
||||||
|
private final AtomicReference<String> dispatchedCommand = new AtomicReference<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dispatchCommand(@NotNull CommandSender sender, @NotNull String commandLine) {
|
||||||
|
commandDispatched.set(true);
|
||||||
|
dispatchedOnPrimaryThread.set(isPrimaryThread());
|
||||||
|
dispatchedCommand.set(commandLine);
|
||||||
|
return super.dispatchCommand(sender, commandLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean commandDispatched() {
|
||||||
|
return commandDispatched.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean dispatchedOnPrimaryThread() {
|
||||||
|
return dispatchedOnPrimaryThread.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String dispatchedCommand() {
|
||||||
|
return dispatchedCommand.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package dev.brighten.antivpn.bukkit;
|
||||||
|
|
||||||
|
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||||
|
import be.seeseemelk.mockbukkit.ServerMock;
|
||||||
|
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
class BukkitPlayerTest {
|
||||||
|
|
||||||
|
private ServerMock server;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
server = MockBukkit.mock();
|
||||||
|
|
||||||
|
BukkitPlugin pluginBootstrap = mock(BukkitPlugin.class);
|
||||||
|
JavaPlugin plugin = MockBukkit.createMockPlugin();
|
||||||
|
when(pluginBootstrap.getPlugin()).thenReturn(plugin);
|
||||||
|
BukkitPlugin.pluginInstance = pluginBootstrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDown() {
|
||||||
|
BukkitPlugin.pluginInstance = null;
|
||||||
|
MockBukkit.unmock();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void kickPlayerCalledFromAsyncContext_isScheduledAndExecutedOnMainThread() {
|
||||||
|
PlayerMock player = server.addPlayer("AsyncKickPlayer");
|
||||||
|
BukkitPlayer bukkitPlayer = new BukkitPlayer(player);
|
||||||
|
|
||||||
|
assertTrue(player.isOnline());
|
||||||
|
|
||||||
|
CompletableFuture<Void> asyncKick = CompletableFuture.runAsync(() -> bukkitPlayer.kickPlayer("&cBlocked!"));
|
||||||
|
assertDoesNotThrow(() -> asyncKick.get(1, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
assertTrue(player.isOnline(), "Kick should be deferred to the server scheduler");
|
||||||
|
|
||||||
|
server.getScheduler().performTicks(1);
|
||||||
|
|
||||||
|
assertFalse(player.isOnline(), "Player should be kicked when scheduled task runs");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>AntiVPN</artifactId>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</parent>
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
<modules>
|
|
||||||
<module>Plugin</module>
|
|
||||||
<module>Loader</module>
|
|
||||||
</modules>
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>Bukkit</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.gradleup.shadow'
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluationDependsOn(':Bungee:BungeePlugin')
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'net.md-5:bungeecord-api:1.21-R0.2'
|
||||||
|
compileOnly project(':Bungee:BungeePlugin')
|
||||||
|
implementation project(':Common:loader-utils')
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set('')
|
||||||
|
|
||||||
|
// Include the shaded plugin jar as a single resource file
|
||||||
|
from(project(':Bungee:BungeePlugin').tasks.shadowJar) {
|
||||||
|
rename { 'antivpn-bungee.jarinjar' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('shadowJar') {
|
||||||
|
dependsOn(':Bungee:BungeePlugin:shadowJar')
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.build.dependsOn shadowJar
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Bungee</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<groupId>dev.brighten.antivpn.bungee</groupId>
|
|
||||||
<artifactId>BungeeLoader</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<minimizeJar>false</minimizeJar>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
|
|
||||||
<resource>antivpn-bungee.jarinjar</resource>
|
|
||||||
<file>${project.parent.basedir}/BungeePlugin/target/BungeePlugin-${project.version}.jar</file>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.md-5</groupId>
|
|
||||||
<artifactId>bungeecord-api</artifactId>
|
|
||||||
<version>1.21-R0.2</version>
|
|
||||||
<type>jar</type>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Plugin</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>loader-utils</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.gradleup.shadow'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'net.md-5:bungeecord-api:1.21-R0.2'
|
||||||
|
testImplementation 'net.md-5:bungeecord-api:1.21-R0.2'
|
||||||
|
implementation project(':Common:Source')
|
||||||
|
implementation project(':Common:loader-utils')
|
||||||
|
implementation 'org.bstats:bstats-bungeecord:2.2.1'
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
|
||||||
|
testImplementation 'org.mockito:mockito-core:5.11.0'
|
||||||
|
testImplementation 'org.mockito:mockito-subclass:5.11.0'
|
||||||
|
testImplementation 'org.mockito:mockito-junit-jupiter:5.11.0'
|
||||||
|
testImplementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
|
||||||
|
}
|
||||||
|
tasks.compileJava.dependsOn(':Common:Source:jar')
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
systemProperty 'mockito.mockmaker', 'subclass'
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set('')
|
||||||
|
relocate 'org.bstats', 'dev.brighten.antivpn.bungee.org.bstats'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.build.dependsOn shadowJar
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Bungee</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>BungeePlugin</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<configuration>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.bstats</pattern>
|
|
||||||
<!-- Replace this with your package! -->
|
|
||||||
<shadedPattern>dev.brighten.antivpn.bungee.org.bstats</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.yaml.snakeyaml</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.yaml.snakeyaml</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Source</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.md-5</groupId>
|
|
||||||
<artifactId>bungeecord-api</artifactId>
|
|
||||||
<version>1.21-R0.2</version>
|
|
||||||
<type>jar</type>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bstats</groupId>
|
|
||||||
<artifactId>bstats-bungeecord</artifactId>
|
|
||||||
<version>2.2.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>loader-utils</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
package dev.brighten.antivpn.bungee;
|
||||||
|
|
||||||
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
import dev.brighten.antivpn.api.PlayerExecutor;
|
||||||
|
import dev.brighten.antivpn.api.VPNConfig;
|
||||||
|
import dev.brighten.antivpn.api.VPNExecutor;
|
||||||
|
import dev.brighten.antivpn.message.MessageHandler;
|
||||||
|
import dev.brighten.antivpn.message.VpnString;
|
||||||
|
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||||
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
|
import net.md_5.bungee.api.event.PreLoginEvent;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
public class BungeeListenerTest {
|
||||||
|
|
||||||
|
private BungeeListener listener;
|
||||||
|
private VPNExecutor vpnExecutor;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
AntiVPN antiVPN = mock(AntiVPN.class);
|
||||||
|
VPNConfig config = mock(VPNConfig.class);
|
||||||
|
PlayerExecutor playerExecutor = mock(PlayerExecutor.class);
|
||||||
|
vpnExecutor = mock(VPNExecutor.class);
|
||||||
|
MessageHandler messageHandler = mock(MessageHandler.class);
|
||||||
|
|
||||||
|
when(antiVPN.getVpnConfig()).thenReturn(config);
|
||||||
|
when(antiVPN.getPlayerExecutor()).thenReturn(playerExecutor);
|
||||||
|
when(antiVPN.getExecutor()).thenReturn(vpnExecutor);
|
||||||
|
when(antiVPN.getMessageHandler()).thenReturn(messageHandler);
|
||||||
|
|
||||||
|
when(playerExecutor.getPlayer(any(UUID.class))).thenReturn(Optional.empty());
|
||||||
|
when(config.getPrefixWhitelists()).thenReturn(java.util.Collections.emptyList());
|
||||||
|
when(config.getCountryList()).thenReturn(java.util.Collections.emptyList());
|
||||||
|
when(config.isKickPlayers()).thenReturn(true);
|
||||||
|
when(config.getKickMessage()).thenReturn("Blocked!");
|
||||||
|
|
||||||
|
VpnString mockVpnString = mock(VpnString.class);
|
||||||
|
when(mockVpnString.getFormattedMessage(any())).thenReturn("Blocked!");
|
||||||
|
when(messageHandler.getString(anyString())).thenReturn(mockVpnString);
|
||||||
|
|
||||||
|
when(vpnExecutor.checkIp(anyString())).thenReturn(CompletableFuture.completedFuture(
|
||||||
|
VPNResponse.builder().success(true).proxy(false).ip("127.0.0.1")
|
||||||
|
.method("N/A").countryName("N/A").city("N/A").build()
|
||||||
|
));
|
||||||
|
|
||||||
|
// Use reflection to set the private static INSTANCE field
|
||||||
|
Field instanceField = AntiVPN.class.getDeclaredField("INSTANCE");
|
||||||
|
instanceField.setAccessible(true);
|
||||||
|
instanceField.set(null, antiVPN);
|
||||||
|
|
||||||
|
listener = new BungeeListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
// Reset the singleton
|
||||||
|
Field instanceField = AntiVPN.class.getDeclaredField("INSTANCE");
|
||||||
|
instanceField.setAccessible(true);
|
||||||
|
instanceField.set(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPreLoginEventAllowed() {
|
||||||
|
PreLoginEvent event = mock(PreLoginEvent.class);
|
||||||
|
PendingConnection connection = mock(PendingConnection.class);
|
||||||
|
|
||||||
|
when(event.getConnection()).thenReturn(connection);
|
||||||
|
when(connection.getUniqueId()).thenReturn(UUID.randomUUID());
|
||||||
|
when(connection.getName()).thenReturn("TestPlayer");
|
||||||
|
when(connection.getSocketAddress()).thenReturn(new InetSocketAddress("127.0.0.1", 12345));
|
||||||
|
|
||||||
|
listener.onListener(event);
|
||||||
|
|
||||||
|
verify(event, never()).setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPreLoginEventBlocked() {
|
||||||
|
PreLoginEvent event = mock(PreLoginEvent.class);
|
||||||
|
PendingConnection connection = mock(PendingConnection.class);
|
||||||
|
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
when(event.getConnection()).thenReturn(connection);
|
||||||
|
when(connection.getUniqueId()).thenReturn(uuid);
|
||||||
|
when(connection.getName()).thenReturn("ProxyPlayer");
|
||||||
|
when(connection.getSocketAddress()).thenReturn(new InetSocketAddress("1.1.1.1", 12345));
|
||||||
|
|
||||||
|
// Mock proxy response
|
||||||
|
when(vpnExecutor.checkIp("1.1.1.1")).thenReturn(CompletableFuture.completedFuture(
|
||||||
|
VPNResponse.builder().success(true).proxy(true).ip("1.1.1.1")
|
||||||
|
.method("N/A").countryName("N/A").countryCode("N/A").city("N/A").build()
|
||||||
|
));
|
||||||
|
|
||||||
|
listener.onListener(event);
|
||||||
|
|
||||||
|
verify(event).setCancelled(true);
|
||||||
|
verify(event).setReason(any());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>AntiVPN</artifactId>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</parent>
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>Bungee</artifactId>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.gradleup.shadow'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'org.ow2.asm:asm:9.8'
|
||||||
|
implementation 'org.ow2.asm:asm-commons:9.8'
|
||||||
|
implementation 'org.yaml:snakeyaml:2.2'
|
||||||
|
implementation 'org.jetbrains:annotations:26.0.2'
|
||||||
|
|
||||||
|
compileOnly 'com.mysql:mysql-connector-j:9.3.0'
|
||||||
|
compileOnly 'com.h2database:h2:2.2.220'
|
||||||
|
implementation'com.github.ben-manes.caffeine:caffeine:3.1.8'
|
||||||
|
compileOnly 'org.mongodb:mongo-java-driver:3.12.14'
|
||||||
|
|
||||||
|
testImplementation 'org.mockito:mockito-core:5.11.0'
|
||||||
|
testImplementation "org.junit.jupiter:junit-jupiter:5.8.1"
|
||||||
|
testImplementation "org.testcontainers:testcontainers:2.0.4"
|
||||||
|
testImplementation "org.testcontainers:testcontainers-junit-jupiter:2.0.4"
|
||||||
|
testImplementation 'org.testcontainers:mysql:1.20.4'
|
||||||
|
testImplementation 'org.testcontainers:mongodb:1.20.4'
|
||||||
|
testRuntimeOnly 'org.slf4j:slf4j-simple:2.0.16'
|
||||||
|
testImplementation 'com.mysql:mysql-connector-j:9.3.0'
|
||||||
|
testImplementation 'com.h2database:h2:2.2.220'
|
||||||
|
testImplementation 'org.mongodb:mongo-java-driver:3.12.14'
|
||||||
|
testImplementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set('')
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
exclude 'dev/brighten/antivpn/depends/Relocate*'
|
||||||
|
exclude 'dev/brighten/antivpn/depends/MavenLibraries*'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.build.dependsOn shadowJar
|
||||||
|
components.java.withVariantsFromConfiguration(configurations.shadowRuntimeElements) {
|
||||||
|
skip()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
archiveClassifier.set('raw')
|
||||||
|
}
|
||||||
@@ -1,199 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Common</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>Source</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
<annotationProcessorPaths>
|
|
||||||
<path>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>1.18.44</version>
|
|
||||||
</path>
|
|
||||||
</annotationProcessorPaths>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<minimizeJar>false</minimizeJar>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.yaml.snakeyaml</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.yaml.snakeyaml</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.github.benmanes.caffeine</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.com.github.benmanes.caffeine</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.h2</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.h2</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.bson</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.bson</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.mongodb</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.com.mongodb</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.mysql.cj</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.com.mysql.cj</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.mysql.jdbc</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.com.mysql.jdbc</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>funkemunky-releases</id>
|
|
||||||
<url>https://nexus.funkemunky.cc/content/repositories/releases/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
|
||||||
<version>9.3.0</version>
|
|
||||||
<type>jar</type>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.h2database</groupId>
|
|
||||||
<artifactId>h2</artifactId>
|
|
||||||
<version>2.2.220</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.ow2.asm</groupId>
|
|
||||||
<artifactId>asm</artifactId>
|
|
||||||
<version>9.8</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.ow2.asm</groupId>
|
|
||||||
<artifactId>asm-commons</artifactId>
|
|
||||||
<version>9.8</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.yaml</groupId>
|
|
||||||
<artifactId>snakeyaml</artifactId>
|
|
||||||
<version>2.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
|
||||||
<artifactId>caffeine</artifactId>
|
|
||||||
<version>3.1.8</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mongodb</groupId>
|
|
||||||
<artifactId>mongo-java-driver</artifactId>
|
|
||||||
<version>3.12.14</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jetbrains</groupId>
|
|
||||||
<artifactId>annotations</artifactId>
|
|
||||||
<version>26.0.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -27,7 +27,6 @@ import dev.brighten.antivpn.database.mongo.MongoVPN;
|
|||||||
import dev.brighten.antivpn.database.sql.MySqlVPN;
|
import dev.brighten.antivpn.database.sql.MySqlVPN;
|
||||||
import dev.brighten.antivpn.depends.LibraryLoader;
|
import dev.brighten.antivpn.depends.LibraryLoader;
|
||||||
import dev.brighten.antivpn.depends.MavenLibrary;
|
import dev.brighten.antivpn.depends.MavenLibrary;
|
||||||
import dev.brighten.antivpn.depends.Relocate;
|
|
||||||
import dev.brighten.antivpn.message.MessageHandler;
|
import dev.brighten.antivpn.message.MessageHandler;
|
||||||
import dev.brighten.antivpn.utils.ConfigDefault;
|
import dev.brighten.antivpn.utils.ConfigDefault;
|
||||||
import dev.brighten.antivpn.utils.MiscUtils;
|
import dev.brighten.antivpn.utils.MiscUtils;
|
||||||
@@ -48,25 +47,13 @@ import java.util.List;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter(AccessLevel.PRIVATE)
|
@Setter(AccessLevel.PRIVATE)
|
||||||
@MavenLibrary(groupId = "com.h2database", artifactId ="h2", version = "2.2.220", relocations = {
|
@MavenLibrary(groupId = "com.h2database", artifactId ="h2", version = "2.2.220")
|
||||||
@Relocate(from ="org" + ".\\h2", to ="dev.brighten.antivpn.shaded.org.h2")})
|
@MavenLibrary(groupId = "org.mongodb", artifactId = "mongo-java-driver", version = "3.12.14")
|
||||||
@MavenLibrary(groupId = "org.mongodb", artifactId = "mongo-java-driver", version = "3.12.14", relocations = {
|
|
||||||
@Relocate(from = "com." + "\\mongodb", to = "dev.brighten.antivpn.shaded.com.mongodb"),
|
|
||||||
@Relocate(from = "org" + "\\.bson", to = "dev.brighten.antivpn.shaded.org.bson")
|
|
||||||
})
|
|
||||||
@MavenLibrary(
|
@MavenLibrary(
|
||||||
groupId = "com.mysql",
|
groupId = "com.mysql",
|
||||||
artifactId = "mysql-connector-j",
|
artifactId = "mysql-connector-j",
|
||||||
version = "9.3.0",
|
version = "9.3.0"
|
||||||
relocations = {
|
|
||||||
@Relocate(from = "com.my\\" + "sql.cj", to = "dev.brighten.antivpn.shaded.com.mysql.cj"),
|
|
||||||
@Relocate(from = "com.my\\" + "sql.jdbc", to = "dev.brighten.antivpn.shaded.com.mysql.jdbc"),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
@MavenLibrary(groupId = "com.\\github\\.ben-manes\\.caffeine", artifactId = "caffeine", version = "3.1.8",
|
|
||||||
relocations = {
|
|
||||||
@Relocate(from = "com\\.github\\.benmanes\\.caffeine", to = "dev.brighten.antivpn.shaded.com.github.benmanes.caffeine"),
|
|
||||||
})
|
|
||||||
public class AntiVPN {
|
public class AntiVPN {
|
||||||
|
|
||||||
private static AntiVPN INSTANCE;
|
private static AntiVPN INSTANCE;
|
||||||
@@ -206,8 +193,12 @@ public class AntiVPN {
|
|||||||
executor.log("Failed to deregister H2 driver: " + e.getMessage());
|
executor.log("Failed to deregister H2 driver: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AntiVPN.getInstance().getExecutor().getThreadExecutor().shutdown();
|
if (executor != null && executor.getThreadExecutor() != null) {
|
||||||
|
executor.getThreadExecutor().shutdown();
|
||||||
|
}
|
||||||
if(database != null) database.shutdown();
|
if(database != null) database.shutdown();
|
||||||
|
|
||||||
|
INSTANCE = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadDatabase() {
|
public void reloadDatabase() {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package dev.brighten.antivpn.api;
|
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.AntiVPN;
|
||||||
import dev.brighten.antivpn.utils.CIDRUtils;
|
import dev.brighten.antivpn.utils.CIDRUtils;
|
||||||
import dev.brighten.antivpn.utils.StringUtil;
|
import dev.brighten.antivpn.utils.StringUtil;
|
||||||
@@ -146,7 +148,18 @@ public abstract class VPNExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Cache<String, VPNResponse> cachedResponses = Caffeine.newBuilder()
|
||||||
|
.expireAfterWrite(20, TimeUnit.MINUTES)
|
||||||
|
.maximumSize(4000)
|
||||||
|
.build();
|
||||||
|
|
||||||
public CompletableFuture<VPNResponse> checkIp(String ip) {
|
public CompletableFuture<VPNResponse> checkIp(String ip) {
|
||||||
|
VPNResponse cached = cachedResponses.getIfPresent(ip);
|
||||||
|
|
||||||
|
if(cached != null) {
|
||||||
|
return CompletableFuture.completedFuture(cached);
|
||||||
|
}
|
||||||
|
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
Optional<VPNResponse> cachedRes = AntiVPN.getInstance().getDatabase().getStoredResponse(ip);
|
Optional<VPNResponse> cachedRes = AntiVPN.getInstance().getDatabase().getStoredResponse(ip);
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class AllowlistCommand extends Command {
|
|||||||
page = Integer.parseInt(args[1]);
|
page = Integer.parseInt(args[1]);
|
||||||
if (page < 1) page = 1;
|
if (page < 1) page = 1;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
page = 1;
|
return "&cUsage: /antivpn allowlist show [page]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,12 +242,14 @@ public class AllowlistCommand extends Command {
|
|||||||
uuid = UUID.fromString(args[1]);
|
uuid = UUID.fromString(args[1]);
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
Optional<APIPlayer> player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(args[1]);
|
Optional<APIPlayer> player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(args[1]);
|
||||||
|
if (player.isPresent()) {
|
||||||
if(player.isEmpty()) {
|
uuid = player.get().getUuid();
|
||||||
return "&cThe player \"" + args[1] + "\" is not online, so please provide a UUID.";
|
} else {
|
||||||
|
uuid = MiscUtils.lookupUUID(args[1]);
|
||||||
|
if (uuid == null) {
|
||||||
|
return "&cCould not find a UUID for \"" + args[1] + "\". They might not have provided a valid username.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid = player.get().getUuid();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!databaseEnabled) {
|
if(!databaseEnabled) {
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package dev.brighten.antivpn.database.local;
|
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.AntiVPN;
|
||||||
import dev.brighten.antivpn.database.VPNDatabase;
|
import dev.brighten.antivpn.database.VPNDatabase;
|
||||||
import dev.brighten.antivpn.database.sql.utils.ExecutableStatement;
|
import dev.brighten.antivpn.database.sql.utils.ExecutableStatement;
|
||||||
@@ -40,11 +38,6 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class H2VPN implements VPNDatabase {
|
public class H2VPN implements VPNDatabase {
|
||||||
|
|
||||||
private final Cache<String, VPNResponse> cachedResponses = Caffeine.newBuilder()
|
|
||||||
.expireAfterWrite(20, TimeUnit.MINUTES)
|
|
||||||
.maximumSize(4000)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
|
|
||||||
public H2VPN() {
|
public H2VPN() {
|
||||||
AntiVPN.getInstance().getExecutor().getThreadExecutor().scheduleAtFixedRate(() -> {
|
AntiVPN.getInstance().getExecutor().getThreadExecutor().scheduleAtFixedRate(() -> {
|
||||||
@@ -67,29 +60,25 @@ public class H2VPN implements VPNDatabase {
|
|||||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()|| MySQL.isClosed())
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()|| MySQL.isClosed())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
VPNResponse response = cachedResponses.get(ip, ip2 -> {
|
try(ExecutableStatement statement = Query.prepare("select * from `responses` where `ip` = ? limit 1").append(ip)) {
|
||||||
try(ExecutableStatement statement = Query.prepare("select * from `responses` where `ip` = ? limit 1").append(ip)) {
|
try(ResultSet rs = statement.executeQuery()) {
|
||||||
try(ResultSet rs = statement.executeQuery()) {
|
if (rs != null && rs.next()) {
|
||||||
if (rs != null && rs.next()) {
|
return Optional.of(new VPNResponse(rs.getString("asn"), rs.getString("ip"),
|
||||||
return new VPNResponse(rs.getString("asn"), rs.getString("ip"),
|
rs.getString("countryName"), rs.getString("countryCode"),
|
||||||
rs.getString("countryName"), rs.getString("countryCode"),
|
rs.getString("city"), rs.getString("timeZone"),
|
||||||
rs.getString("city"), rs.getString("timeZone"),
|
rs.getString("method"), rs.getString("isp"), "N/A",
|
||||||
rs.getString("method"), rs.getString("isp"), "N/A",
|
rs.getBoolean("proxy"), rs.getBoolean("cached"), true,
|
||||||
rs.getBoolean("proxy"), rs.getBoolean("cached"), true,
|
rs.getDouble("latitude"), rs.getDouble("longitude"),
|
||||||
rs.getDouble("latitude"), rs.getDouble("longitude"),
|
rs.getTimestamp("inserted").getTime(), -1));
|
||||||
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;
|
} catch (SQLException e) {
|
||||||
});
|
AntiVPN.getInstance().getExecutor().logException("There was a problem getting a response for "
|
||||||
|
+ ip, e);
|
||||||
return Optional.ofNullable(response);
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -106,20 +95,16 @@ public class H2VPN implements VPNDatabase {
|
|||||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(AntiVPN.getInstance().getVpnConfig().cachedResults()) {
|
try(var statement = Query.prepare("insert into `responses` (`ip`,`asn`,`countryName`,`countryCode`,`city`,`timeZone`,"
|
||||||
cachedResponses.put(toCache.getIp(), toCache);
|
+ "`method`,`isp`,`proxy`,`cached`,`inserted`,`latitude`,`longitude`) values (?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
||||||
|
.append(toCache.getIp()).append(toCache.getAsn()).append(toCache.getCountryName())
|
||||||
try(var statement = Query.prepare("insert into `responses` (`ip`,`asn`,`countryName`,`countryCode`,`city`,`timeZone`,"
|
.append(toCache.getCountryCode()).append(toCache.getCity()).append(toCache.getTimeZone())
|
||||||
+ "`method`,`isp`,`proxy`,`cached`,`inserted`,`latitude`,`longitude`) values (?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
.append(toCache.getMethod()).append(toCache.getIsp()).append(toCache.isProxy())
|
||||||
.append(toCache.getIp()).append(toCache.getAsn()).append(toCache.getCountryName())
|
.append(toCache.isCached()).append(new Timestamp(System.currentTimeMillis()))
|
||||||
.append(toCache.getCountryCode()).append(toCache.getCity()).append(toCache.getTimeZone())
|
.append(toCache.getLatitude()).append(toCache.getLongitude())) {
|
||||||
.append(toCache.getMethod()).append(toCache.getIsp()).append(toCache.isProxy())
|
statement.execute();
|
||||||
.append(toCache.isCached()).append(new Timestamp(System.currentTimeMillis()))
|
} catch(SQLException e) {
|
||||||
.append(toCache.getLatitude()).append(toCache.getLongitude())) {
|
AntiVPN.getInstance().getExecutor().logException("Could not cache response for IP: " + toCache.getIp(), e);
|
||||||
statement.execute();
|
|
||||||
} catch(SQLException e) {
|
|
||||||
AntiVPN.getInstance().getExecutor().logException("Could not cache response for IP: " + toCache.getIp(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +124,7 @@ public class H2VPN implements VPNDatabase {
|
|||||||
public boolean isWhitelisted(UUID uuid) {
|
public boolean isWhitelisted(UUID uuid) {
|
||||||
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
if (!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled() || MySQL.isClosed())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
try(var statement = Query.prepare("select uuid from `whitelisted` where `uuid` = ? limit 1")
|
try(var statement = Query.prepare("select uuid from `whitelisted` where `uuid` = ? limit 1")
|
||||||
.append(uuid.toString())) {
|
.append(uuid.toString())) {
|
||||||
try(var set = statement.executeQuery()) {
|
try(var set = statement.executeQuery()) {
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ public class First implements Version<VPNDatabase> {
|
|||||||
.append(versionNumber())).execute();
|
.append(versionNumber())).execute();
|
||||||
|
|
||||||
AntiVPN.getInstance().getExecutor().log("Creating indexes...");
|
AntiVPN.getInstance().getExecutor().log("Creating indexes...");
|
||||||
createIndexIfAbsent("whitelisted", "uuid_1", "`uuid`");
|
createIndexIfAbsent("whitelisted", "whitelisted_uuid_1", "`uuid`");
|
||||||
createIndexIfAbsent("responses", "ip_1", "`ip`");
|
createIndexIfAbsent("responses", "responses_ip_1", "`ip`");
|
||||||
createIndexIfAbsent("responses", "proxy_1", "`proxy`");
|
createIndexIfAbsent("responses", "responses_proxy_1", "`proxy`");
|
||||||
createIndexIfAbsent("responses", "inserted_1", "`inserted`");
|
createIndexIfAbsent("responses", "responses_inserted_1", "`inserted`");
|
||||||
createIndexIfAbsent("whitelisted-ips", "ip_1", "`ip`");
|
createIndexIfAbsent("whitelisted-ips", "whitelisted_ips_ip_1", "`ip`");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DatabaseException("Failed to update database", e);
|
throw new DatabaseException("Failed to update database", e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public class Second extends First implements Version<VPNDatabase> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dropIndexIfPresent("whitelisted-ips", "ip_1");
|
dropIndexIfPresent("whitelisted-ips", "ip_1");
|
||||||
|
dropIndexIfPresent("whitelisted-ips", "whitelisted_ips_ip_1");
|
||||||
closeOnEnd(Query.prepare("DROP TABLE `whitelisted-ips`")).execute();
|
closeOnEnd(Query.prepare("DROP TABLE `whitelisted-ips`")).execute();
|
||||||
closeOnEnd(Query.prepare("INSERT INTO `database_version` (`version`) VALUES (?)").append(versionNumber())).execute();
|
closeOnEnd(Query.prepare("INSERT INTO `database_version` (`version`) VALUES (?)").append(versionNumber())).execute();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@@ -123,7 +124,7 @@ public class Second extends First implements Version<VPNDatabase> {
|
|||||||
statement.execute();
|
statement.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
createIndexIfAbsent("whitelisted-ips", "ip_1", "`ip`");
|
createIndexIfAbsent("whitelisted-ips", "whitelisted_ips_ip_1", "`ip`");
|
||||||
|
|
||||||
try(var statement = Query.prepare("DELETE FROM `whitelisted-ips`")) {
|
try(var statement = Query.prepare("DELETE FROM `whitelisted-ips`")) {
|
||||||
statement.execute();
|
statement.execute();
|
||||||
|
|||||||
@@ -47,11 +47,6 @@ public class MongoVPN implements VPNDatabase {
|
|||||||
private MongoClient client;
|
private MongoClient client;
|
||||||
public MongoDatabase antivpnDatabase;
|
public MongoDatabase antivpnDatabase;
|
||||||
|
|
||||||
private final Cache<String, VPNResponse> cachedResponses = Caffeine.newBuilder()
|
|
||||||
.expireAfterWrite(20, TimeUnit.MINUTES)
|
|
||||||
.maximumSize(4000)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
public MongoVPN() {
|
public MongoVPN() {
|
||||||
AntiVPN.getInstance().getExecutor().getThreadExecutor().scheduleAtFixedRate(() -> {
|
AntiVPN.getInstance().getExecutor().getThreadExecutor().scheduleAtFixedRate(() -> {
|
||||||
if(!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()) return;
|
if(!AntiVPN.getInstance().getVpnConfig().isDatabaseEnabled()) return;
|
||||||
@@ -69,37 +64,32 @@ public class MongoVPN implements VPNDatabase {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Optional<VPNResponse> getStoredResponse(String ip) {
|
public Optional<VPNResponse> getStoredResponse(String ip) {
|
||||||
VPNResponse response = cachedResponses.get(ip, ip2 -> {
|
Document rdoc = cacheDocument.find(Filters.eq("ip", ip)).first();
|
||||||
Document rdoc = cacheDocument.find(Filters.eq("ip", ip)).first();
|
|
||||||
|
|
||||||
if(rdoc != null) {
|
if(rdoc != null) {
|
||||||
long lastUpdate = rdoc.get("lastAccess", 0L);
|
long lastUpdate = rdoc.get("lastAccess", 0L);
|
||||||
|
|
||||||
if(System.currentTimeMillis() - lastUpdate > TimeUnit.HOURS.toMillis(1)) {
|
if(System.currentTimeMillis() - lastUpdate > TimeUnit.HOURS.toMillis(1)) {
|
||||||
AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> deleteResponse(ip));
|
AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> deleteResponse(ip));
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
return VPNResponse.builder().asn(rdoc.getString("asn")).ip(ip)
|
|
||||||
.countryName(rdoc.getString("countryName"))
|
|
||||||
.countryCode(rdoc.getString("countryCode"))
|
|
||||||
.city(rdoc.getString("city"))
|
|
||||||
.isp(rdoc.getString("isp"))
|
|
||||||
.method(rdoc.getString("method"))
|
|
||||||
.timeZone(rdoc.getString("timeZone"))
|
|
||||||
.proxy(rdoc.getBoolean("proxy"))
|
|
||||||
.cached(rdoc.getBoolean("cached"))
|
|
||||||
.success(true)
|
|
||||||
.latitude(rdoc.getDouble("latitude"))
|
|
||||||
.longitude(rdoc.getDouble("longitude"))
|
|
||||||
.lastAccess(rdoc.get("lastAccess", 0L))
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return Optional.of(VPNResponse.builder().asn(rdoc.getString("asn")).ip(ip)
|
||||||
return Optional.ofNullable(response);
|
.countryName(rdoc.getString("countryName"))
|
||||||
|
.countryCode(rdoc.getString("countryCode"))
|
||||||
|
.city(rdoc.getString("city"))
|
||||||
|
.isp(rdoc.getString("isp"))
|
||||||
|
.method(rdoc.getString("method"))
|
||||||
|
.timeZone(rdoc.getString("timeZone"))
|
||||||
|
.proxy(rdoc.getBoolean("proxy"))
|
||||||
|
.cached(rdoc.getBoolean("cached"))
|
||||||
|
.success(true)
|
||||||
|
.latitude(rdoc.getDouble("latitude"))
|
||||||
|
.longitude(rdoc.getDouble("longitude"))
|
||||||
|
.lastAccess(rdoc.get("lastAccess", 0L))
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -121,8 +111,6 @@ public class MongoVPN implements VPNDatabase {
|
|||||||
rdoc.put("longitude", toCache.getLongitude());
|
rdoc.put("longitude", toCache.getLongitude());
|
||||||
rdoc.put("lastAccess", System.currentTimeMillis());
|
rdoc.put("lastAccess", System.currentTimeMillis());
|
||||||
|
|
||||||
cachedResponses.put(toCache.getIp(), toCache);
|
|
||||||
|
|
||||||
AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> {
|
AntiVPN.getInstance().getExecutor().getThreadExecutor().execute(() -> {
|
||||||
Bson update = new Document("$set", rdoc);
|
Bson update = new Document("$set", rdoc);
|
||||||
cacheDocument.updateOne(Filters.eq("ip", toCache.getIp()), update,
|
cacheDocument.updateOne(Filters.eq("ip", toCache.getIp()), update,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.SQLSyntaxErrorException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@@ -48,9 +49,21 @@ public class MySQL {
|
|||||||
}
|
}
|
||||||
conn.setAutoCommit(true);
|
conn.setAutoCommit(true);
|
||||||
Query.use(conn);
|
Query.use(conn);
|
||||||
Query.prepare("CREATE DATABASE IF NOT EXISTS `"
|
String databaseName = AntiVPN.getInstance().getVpnConfig().getDatabaseName();
|
||||||
+ AntiVPN.getInstance().getVpnConfig().getDatabaseName() + "`").execute();
|
|
||||||
Query.prepare("USE `" + AntiVPN.getInstance().getVpnConfig().getDatabaseName() + "`").execute();
|
try {
|
||||||
|
Query.prepare("CREATE DATABASE IF NOT EXISTS `" + databaseName + "`").execute();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
if (!isDatabaseCreationPermissionIssue(ex)) {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
AntiVPN.getInstance().getExecutor().log(
|
||||||
|
"No permission to create MySQL database `" + databaseName
|
||||||
|
+ "`. Attempting to use the existing database instead.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Query.prepare("USE `" + databaseName + "`").execute();
|
||||||
AntiVPN.getInstance().getExecutor().log("Connection to MySQL has been established.");
|
AntiVPN.getInstance().getExecutor().log("Connection to MySQL has been established.");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -59,6 +72,12 @@ public class MySQL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isDatabaseCreationPermissionIssue(SQLException ex) {
|
||||||
|
return ex instanceof SQLSyntaxErrorException
|
||||||
|
&& ex.getMessage() != null
|
||||||
|
&& ex.getMessage().contains("Access denied");
|
||||||
|
}
|
||||||
|
|
||||||
public static void initH2() {
|
public static void initH2() {
|
||||||
initH2(true);
|
initH2(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ import dev.brighten.antivpn.utils.json.JsonReader;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.net.InetAddress;
|
import java.net.*;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -34,6 +33,10 @@ import java.util.regex.Pattern;
|
|||||||
public class MiscUtils {
|
public class MiscUtils {
|
||||||
|
|
||||||
private static final Pattern ipv4 = Pattern.compile("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}");
|
private static final Pattern ipv4 = Pattern.compile("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}");
|
||||||
|
private static final String DEFAULT_FUNKEMUNKY_UUID_ENDPOINT = "https://funkemunky.cc/mojang/uuid?name=";
|
||||||
|
private static final String DEFAULT_MOJANG_UUID_ENDPOINT = "https://api.mojang.com/users/profiles/minecraft/";
|
||||||
|
private static volatile String funkemunkyUuidEndpoint = DEFAULT_FUNKEMUNKY_UUID_ENDPOINT;
|
||||||
|
private static volatile String mojangUuidEndpoint = DEFAULT_MOJANG_UUID_ENDPOINT;
|
||||||
|
|
||||||
public static void close(Closeable... closeables) {
|
public static void close(Closeable... closeables) {
|
||||||
try {
|
try {
|
||||||
@@ -94,7 +97,7 @@ public class MiscUtils {
|
|||||||
int prefixLen = 32 - blockBits; // use 128 for IPv6
|
int prefixLen = 32 - blockBits; // use 128 for IPv6
|
||||||
|
|
||||||
// Build the CIDR string
|
// Build the CIDR string
|
||||||
byte[] addrBytes = toFixedLengthBytes(start, 4); // use 16 for IPv6
|
byte[] addrBytes = toFixedLengthBytes(start); // use 16 for IPv6
|
||||||
String cidr = InetAddress.getByAddress(addrBytes).getHostAddress() + "/" + prefixLen;
|
String cidr = InetAddress.getByAddress(addrBytes).getHostAddress() + "/" + prefixLen;
|
||||||
cidrs.add(new CIDRUtils(cidr));
|
cidrs.add(new CIDRUtils(cidr));
|
||||||
|
|
||||||
@@ -105,24 +108,22 @@ public class MiscUtils {
|
|||||||
return cidrs;
|
return cidrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] toFixedLengthBytes(BigInteger value, int length) {
|
private static byte[] toFixedLengthBytes(BigInteger value) {
|
||||||
byte[] raw = value.toByteArray();
|
byte[] raw = value.toByteArray();
|
||||||
byte[] result = new byte[length];
|
byte[] result = new byte[4];
|
||||||
int srcPos = Math.max(0, raw.length - length);
|
int srcPos = Math.max(0, raw.length - 4);
|
||||||
int destPos = Math.max(0, length - raw.length);
|
int destPos = Math.max(0, 4 - raw.length);
|
||||||
System.arraycopy(raw, srcPos, result, destPos, Math.min(raw.length, length));
|
System.arraycopy(raw, srcPos, result, destPos, Math.min(raw.length, 4));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UUID lookupUUID(String playername) {
|
public static UUID lookupUUID(String playername) {
|
||||||
try {
|
try {
|
||||||
JSONObject object = JsonReader
|
UUID uuid = lookupUuidFromUrl(funkemunkyUuidEndpoint + playername);
|
||||||
.readJsonFromUrl("https://funkemunky.cc/mojang/uuid?name=" + playername);
|
if (uuid != null) {
|
||||||
|
return uuid;
|
||||||
if(object.has("uuid")) {
|
|
||||||
return UUID.fromString(object.getString("uuid"));
|
|
||||||
}
|
}
|
||||||
} catch (IOException | JSONException e) {
|
} catch (IOException | JSONException | URISyntaxException e) {
|
||||||
AntiVPN.getInstance().getExecutor().logException("Error while looking up UUID for " + playername + "! Falling back to Mojang API", e);
|
AntiVPN.getInstance().getExecutor().logException("Error while looking up UUID for " + playername + "! Falling back to Mojang API", e);
|
||||||
return lookupMojangUuid(playername);
|
return lookupMojangUuid(playername);
|
||||||
}
|
}
|
||||||
@@ -130,19 +131,63 @@ public class MiscUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static UUID lookupUuidFromUrl(String url) throws IOException, JSONException, URISyntaxException {
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) new URI(url).toURL().openConnection();
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.setReadTimeout(5000);
|
||||||
|
connection.setInstanceFollowRedirects(true);
|
||||||
|
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
if (responseCode >= 500) {
|
||||||
|
throw new IOException("Server returned HTTP " + responseCode + " for " + url);
|
||||||
|
}
|
||||||
|
if (responseCode != HttpURLConnection.HTTP_OK) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (InputStream inputStream = connection.getInputStream()) {
|
||||||
|
JSONObject object = new JSONObject(JsonReader.readAll(new InputStreamReader(inputStream, java.nio.charset.StandardCharsets.UTF_8)));
|
||||||
|
if (object.has("uuid")) {
|
||||||
|
return parseUuid(object.getString("uuid"));
|
||||||
|
}
|
||||||
|
if (object.has("id")) {
|
||||||
|
return parseUuid(object.getString("id"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static UUID parseUuid(String value) {
|
||||||
|
if (value.length() == 32) {
|
||||||
|
value = value.replaceFirst(
|
||||||
|
"([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{12})",
|
||||||
|
"$1-$2-$3-$4-$5"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return UUID.fromString(value);
|
||||||
|
}
|
||||||
|
|
||||||
private static UUID lookupMojangUuid(String playerName) {
|
private static UUID lookupMojangUuid(String playerName) {
|
||||||
try {
|
try {
|
||||||
JSONObject object = JsonReader.readJsonFromUrl("https://api.mojang.com/users/profiles/minecraft/" + playerName);
|
return lookupUuidFromUrl(mojangUuidEndpoint + playerName);
|
||||||
|
} catch (IOException | JSONException | URISyntaxException e) {
|
||||||
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);
|
AntiVPN.getInstance().getExecutor().logException("Error while looking up UUID for " + playerName + " from Mojang!:", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setLookupEndpointsForTesting(String funkemunkyEndpoint, String mojangEndpoint) {
|
||||||
|
funkemunkyUuidEndpoint = funkemunkyEndpoint;
|
||||||
|
mojangUuidEndpoint = mojangEndpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void resetLookupEndpointsForTesting() {
|
||||||
|
funkemunkyUuidEndpoint = DEFAULT_FUNKEMUNKY_UUID_ENDPOINT;
|
||||||
|
mojangUuidEndpoint = DEFAULT_MOJANG_UUID_ENDPOINT;
|
||||||
|
}
|
||||||
public static boolean isIpv4(String ip)
|
public static boolean isIpv4(String ip)
|
||||||
{
|
{
|
||||||
return ipv4.matcher(ip).matches();
|
return ipv4.matcher(ip).matches();
|
||||||
|
|||||||
+217
@@ -0,0 +1,217 @@
|
|||||||
|
package dev.brighten.antivpn.database;
|
||||||
|
|
||||||
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
import dev.brighten.antivpn.api.VPNConfig;
|
||||||
|
import dev.brighten.antivpn.api.VPNExecutor;
|
||||||
|
import dev.brighten.antivpn.database.sql.utils.MySQL;
|
||||||
|
import dev.brighten.antivpn.utils.CIDRUtils;
|
||||||
|
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.lenient;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
abstract class DatabaseIntegrationTestSupport {
|
||||||
|
|
||||||
|
@TempDir
|
||||||
|
Path pluginFolder;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
protected AntiVPN antiVPN;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
protected VPNConfig vpnConfig;
|
||||||
|
|
||||||
|
protected TestVPNExecutor vpnExecutor;
|
||||||
|
private AutoCloseable mocks;
|
||||||
|
private final AtomicReference<VPNDatabase> activeDatabase = new AtomicReference<>();
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUpBase() throws Exception {
|
||||||
|
mocks = MockitoAnnotations.openMocks(this);
|
||||||
|
vpnExecutor = new TestVPNExecutor();
|
||||||
|
|
||||||
|
when(antiVPN.getVpnConfig()).thenReturn(vpnConfig);
|
||||||
|
when(antiVPN.getExecutor()).thenReturn(vpnExecutor);
|
||||||
|
when(antiVPN.getPluginFolder()).thenReturn(pluginFolder.toFile());
|
||||||
|
when(antiVPN.getDatabase()).thenAnswer(invocation -> activeDatabase.get());
|
||||||
|
|
||||||
|
lenient().when(vpnConfig.isDatabaseEnabled()).thenReturn(true);
|
||||||
|
lenient().when(vpnConfig.cachedResults()).thenReturn(true);
|
||||||
|
lenient().when(vpnConfig.getUsername()).thenReturn("testuser");
|
||||||
|
lenient().when(vpnConfig.getPassword()).thenReturn("testpass");
|
||||||
|
lenient().when(vpnConfig.getDatabaseName()).thenReturn("antivpn");
|
||||||
|
lenient().when(vpnConfig.getIp()).thenReturn("127.0.0.1");
|
||||||
|
lenient().when(vpnConfig.getPort()).thenReturn(-1);
|
||||||
|
lenient().when(vpnConfig.mongoDatabaseURL()).thenReturn("");
|
||||||
|
lenient().when(vpnConfig.useDatabaseCreds()).thenReturn(false);
|
||||||
|
|
||||||
|
setAntiVpnInstance(antiVPN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDownBase() throws Exception {
|
||||||
|
VPNDatabase database = activeDatabase.getAndSet(null);
|
||||||
|
if (database != null) {
|
||||||
|
database.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
MySQL.shutdown();
|
||||||
|
if (vpnExecutor != null) {
|
||||||
|
vpnExecutor.getThreadExecutor().shutdownNow();
|
||||||
|
vpnExecutor.getThreadExecutor().awaitTermination(5, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
setAntiVpnInstance(null);
|
||||||
|
|
||||||
|
if (mocks != null) {
|
||||||
|
mocks.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void registerDatabase(VPNDatabase database) {
|
||||||
|
activeDatabase.set(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void assertDatabaseContract(VPNDatabase database) throws Exception {
|
||||||
|
registerDatabase(database);
|
||||||
|
database.init();
|
||||||
|
|
||||||
|
VPNResponse response = VPNResponse.builder()
|
||||||
|
.ip("1.2.3.4")
|
||||||
|
.asn("AS123")
|
||||||
|
.countryName("United States")
|
||||||
|
.countryCode("US")
|
||||||
|
.city("New York")
|
||||||
|
.proxy(true)
|
||||||
|
.cached(true)
|
||||||
|
.success(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
database.cacheResponse(response);
|
||||||
|
|
||||||
|
Optional<VPNResponse> storedResponse = awaitStoredResponse(database, response.getIp());
|
||||||
|
assertTrue(storedResponse.isPresent(), "Expected cached response to be stored");
|
||||||
|
assertEquals("AS123", storedResponse.get().getAsn());
|
||||||
|
assertTrue(storedResponse.get().isProxy());
|
||||||
|
|
||||||
|
database.deleteResponse(response.getIp());
|
||||||
|
awaitCondition(() -> database.getStoredResponse(response.getIp()).isEmpty(),
|
||||||
|
"Expected cached response to be deleted");
|
||||||
|
|
||||||
|
database.cacheResponse(response);
|
||||||
|
awaitCondition(() -> database.getStoredResponse(response.getIp()).isPresent(),
|
||||||
|
"Expected cached response to be restored");
|
||||||
|
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
assertFalse(database.isWhitelisted(uuid));
|
||||||
|
database.addWhitelist(uuid);
|
||||||
|
awaitCondition(() -> database.isWhitelisted(uuid), "Expected UUID whitelist entry to exist");
|
||||||
|
List<UUID> whitelisted = database.getAllWhitelisted();
|
||||||
|
assertTrue(whitelisted.contains(uuid));
|
||||||
|
database.removeWhitelist(uuid);
|
||||||
|
awaitCondition(() -> !database.isWhitelisted(uuid), "Expected UUID whitelist entry to be removed");
|
||||||
|
|
||||||
|
CIDRUtils cidr = new CIDRUtils("192.168.1.0/24");
|
||||||
|
assertFalse(database.isWhitelisted(cidr));
|
||||||
|
database.addWhitelist(cidr);
|
||||||
|
awaitCondition(() -> database.isWhitelisted(cidr), "Expected CIDR whitelist entry to exist");
|
||||||
|
List<CIDRUtils> whitelistedIps = database.getAllWhitelistedIps();
|
||||||
|
assertTrue(whitelistedIps.stream().anyMatch(entry -> entry.getCidr().equals(cidr.getCidr())));
|
||||||
|
database.removeWhitelist(cidr);
|
||||||
|
awaitCondition(() -> !database.isWhitelisted(cidr), "Expected CIDR whitelist entry to be removed");
|
||||||
|
|
||||||
|
database.updateAlertsState(uuid, true);
|
||||||
|
awaitCondition(() -> awaitAlertsState(database, uuid), "Expected alerts to be enabled");
|
||||||
|
database.updateAlertsState(uuid, false);
|
||||||
|
awaitCondition(() -> !awaitAlertsState(database, uuid), "Expected alerts to be disabled");
|
||||||
|
|
||||||
|
database.clearResponses();
|
||||||
|
awaitCondition(() -> database.getStoredResponse(response.getIp()).isEmpty(),
|
||||||
|
"Expected cached responses to be cleared");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<VPNResponse> awaitStoredResponse(VPNDatabase database, String ip) throws InterruptedException {
|
||||||
|
AtomicReference<Optional<VPNResponse>> result = new AtomicReference<>(Optional.empty());
|
||||||
|
awaitCondition(() -> {
|
||||||
|
Optional<VPNResponse> response = database.getStoredResponse(ip);
|
||||||
|
result.set(response);
|
||||||
|
return response.isPresent();
|
||||||
|
}, "Timed out waiting for cached response");
|
||||||
|
return result.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean awaitAlertsState(VPNDatabase database, UUID uuid) throws InterruptedException {
|
||||||
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
AtomicReference<Boolean> result = new AtomicReference<>(false);
|
||||||
|
database.alertsState(uuid, enabled -> {
|
||||||
|
result.set(enabled);
|
||||||
|
latch.countDown();
|
||||||
|
});
|
||||||
|
assertTrue(latch.await(2, TimeUnit.SECONDS), "Timed out waiting for alerts state callback");
|
||||||
|
return result.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void awaitCondition(CheckedBooleanSupplier condition, String failureMessage) throws InterruptedException {
|
||||||
|
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
|
||||||
|
while (System.nanoTime() < deadline) {
|
||||||
|
try {
|
||||||
|
if (condition.getAsBoolean()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail(e.getMessage(), e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
|
fail(failureMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setAntiVpnInstance(AntiVPN instance) throws Exception {
|
||||||
|
Field instanceField = AntiVPN.class.getDeclaredField("INSTANCE");
|
||||||
|
instanceField.setAccessible(true);
|
||||||
|
instanceField.set(null, instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
protected interface CheckedBooleanSupplier {
|
||||||
|
boolean getAsBoolean() throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final class TestVPNExecutor extends VPNExecutor {
|
||||||
|
@Override
|
||||||
|
public void registerListeners() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(Level level, String log, Object... objects) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(String log, Object... objects) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logException(String message, Throwable ex) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runCommand(String command) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disablePlugin() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package dev.brighten.antivpn.database;
|
||||||
|
|
||||||
|
import dev.brighten.antivpn.database.local.H2VPN;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class H2DatabaseIntegrationTest extends DatabaseIntegrationTestSupport {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void h2DatabaseImplementsTheVpnDatabaseContract() throws Exception {
|
||||||
|
assertDatabaseContract(new H2VPN());
|
||||||
|
}
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package dev.brighten.antivpn.database;
|
||||||
|
|
||||||
|
import com.mongodb.client.MongoClients;
|
||||||
|
import dev.brighten.antivpn.database.mongo.MongoVPN;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.testcontainers.containers.MongoDBContainer;
|
||||||
|
import org.testcontainers.junit.jupiter.Container;
|
||||||
|
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@Testcontainers
|
||||||
|
class MongoDatabaseIntegrationTest extends DatabaseIntegrationTestSupport {
|
||||||
|
|
||||||
|
@Container
|
||||||
|
private static final MongoDBContainer MONGO = new MongoDBContainer("mongo:6.0.14");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mongoDatabaseImplementsTheVpnDatabaseContract() throws Exception {
|
||||||
|
assertTrue(MONGO.isRunning(), "Mongo Testcontainer should be running");
|
||||||
|
|
||||||
|
try (var client = MongoClients.create(MONGO.getConnectionString())) {
|
||||||
|
var response = client.getDatabase("admin").runCommand(new Document("ping", 1));
|
||||||
|
assertEquals(1.0d, response.getDouble("ok"), "Expected Mongo container to respond to ping");
|
||||||
|
}
|
||||||
|
|
||||||
|
when(vpnConfig.getIp()).thenReturn(MONGO.getHost());
|
||||||
|
when(vpnConfig.getPort()).thenReturn(MONGO.getMappedPort(27017));
|
||||||
|
when(vpnConfig.getDatabaseName()).thenReturn("antivpn_" + UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
when(vpnConfig.mongoDatabaseURL()).thenReturn("");
|
||||||
|
when(vpnConfig.useDatabaseCreds()).thenReturn(false);
|
||||||
|
|
||||||
|
assertDatabaseContract(new MongoVPN());
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
package dev.brighten.antivpn.database;
|
||||||
|
|
||||||
|
import dev.brighten.antivpn.database.sql.MySqlVPN;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.testcontainers.containers.MySQLContainer;
|
||||||
|
import org.testcontainers.junit.jupiter.Container;
|
||||||
|
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||||
|
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@Testcontainers
|
||||||
|
class MySqlDatabaseIntegrationTest extends DatabaseIntegrationTestSupport {
|
||||||
|
|
||||||
|
@Container
|
||||||
|
private static final MySQLContainer<?> MYSQL = new MySQLContainer<>("mysql:8.0.36")
|
||||||
|
.withDatabaseName("antivpn")
|
||||||
|
.withUsername("testuser")
|
||||||
|
.withPassword("testpass");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mysqlDatabaseImplementsTheVpnDatabaseContract() throws Exception {
|
||||||
|
assertTrue(MYSQL.isRunning(), "MySQL Testcontainer should be running");
|
||||||
|
|
||||||
|
try (var connection = DriverManager.getConnection(MYSQL.getJdbcUrl(), MYSQL.getUsername(), MYSQL.getPassword());
|
||||||
|
var statement = connection.createStatement();
|
||||||
|
var resultSet = statement.executeQuery("SELECT 1")) {
|
||||||
|
assertTrue(resultSet.next(), "Expected a row from the MySQL container");
|
||||||
|
assertEquals(1, resultSet.getInt(1), "Expected MySQL container to respond to SELECT 1");
|
||||||
|
}
|
||||||
|
|
||||||
|
var pingResult = MYSQL.execInContainer("mysqladmin", "ping", "-h", "127.0.0.1", "-ptestpass");
|
||||||
|
assertEquals(0, pingResult.getExitCode(), "Expected mysqladmin ping to succeed inside the container");
|
||||||
|
|
||||||
|
when(vpnConfig.getIp()).thenReturn(MYSQL.getHost());
|
||||||
|
when(vpnConfig.getPort()).thenReturn(MYSQL.getMappedPort(3306));
|
||||||
|
when(vpnConfig.getDatabaseName()).thenReturn(MYSQL.getDatabaseName());
|
||||||
|
when(vpnConfig.getUsername()).thenReturn(MYSQL.getUsername());
|
||||||
|
when(vpnConfig.getPassword()).thenReturn(MYSQL.getPassword());
|
||||||
|
|
||||||
|
assertDatabaseContract(new MySqlVPN());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
package dev.brighten.antivpn.utils;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
import com.sun.net.httpserver.HttpServer;
|
||||||
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
import dev.brighten.antivpn.api.APIPlayer;
|
||||||
|
import dev.brighten.antivpn.api.VPNConfig;
|
||||||
|
import dev.brighten.antivpn.api.VPNExecutor;
|
||||||
|
import dev.brighten.antivpn.command.CommandExecutor;
|
||||||
|
import dev.brighten.antivpn.command.impl.AllowlistCommand;
|
||||||
|
import dev.brighten.antivpn.database.VPNDatabase;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
class AllowlistCommandTest {
|
||||||
|
|
||||||
|
private static final UUID FUNKEMUNKY_UUID = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AntiVPN antiVPN;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private VPNConfig vpnConfig;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private VPNDatabase database;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private dev.brighten.antivpn.api.PlayerExecutor playerExecutor;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CommandExecutor commandExecutor;
|
||||||
|
|
||||||
|
private TestVPNExecutor vpnExecutor;
|
||||||
|
private AutoCloseable mocks;
|
||||||
|
private AllowlistCommand command;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() throws Exception {
|
||||||
|
mocks = MockitoAnnotations.openMocks(this);
|
||||||
|
vpnExecutor = new TestVPNExecutor();
|
||||||
|
command = new AllowlistCommand();
|
||||||
|
|
||||||
|
when(antiVPN.getVpnConfig()).thenReturn(vpnConfig);
|
||||||
|
when(antiVPN.getExecutor()).thenReturn(vpnExecutor);
|
||||||
|
when(antiVPN.getDatabase()).thenReturn(database);
|
||||||
|
when(antiVPN.getPlayerExecutor()).thenReturn(playerExecutor);
|
||||||
|
|
||||||
|
when(vpnConfig.isDatabaseEnabled()).thenReturn(true);
|
||||||
|
|
||||||
|
setAntiVpnInstance(antiVPN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDown() throws Exception {
|
||||||
|
MiscUtils.resetLookupEndpointsForTesting();
|
||||||
|
setAntiVpnInstance(null);
|
||||||
|
|
||||||
|
if (vpnExecutor != null) {
|
||||||
|
vpnExecutor.getThreadExecutor().shutdownNow();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mocks != null) {
|
||||||
|
mocks.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void onlinePlayerIsWhitelistedWithoutLookup() {
|
||||||
|
APIPlayer onlinePlayer = mock(APIPlayer.class);
|
||||||
|
when(onlinePlayer.getUuid()).thenReturn(FUNKEMUNKY_UUID);
|
||||||
|
when(playerExecutor.getPlayer("funkemunky")).thenReturn(Optional.of(onlinePlayer));
|
||||||
|
|
||||||
|
String result = command.execute(commandExecutor, new String[] {"add", "funkemunky"});
|
||||||
|
|
||||||
|
assertTrue(result.contains(FUNKEMUNKY_UUID.toString()));
|
||||||
|
verify(playerExecutor).getPlayer("funkemunky");
|
||||||
|
verify(database).addWhitelist(FUNKEMUNKY_UUID);
|
||||||
|
verify(database, never()).removeWhitelist(FUNKEMUNKY_UUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void offlinePlayerFallsBackToMojangLookupWhenPrimaryEndpointCannotBeReached() throws Exception {
|
||||||
|
when(playerExecutor.getPlayer("funkemunky")).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
int closedPort;
|
||||||
|
try (ServerSocket socket = new ServerSocket(0)) {
|
||||||
|
closedPort = socket.getLocalPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
AtomicInteger mojangHits = new AtomicInteger();
|
||||||
|
HttpServer mojangServer = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||||
|
mojangServer.createContext("/users/profiles/minecraft/funkemunky", exchange -> {
|
||||||
|
mojangHits.incrementAndGet();
|
||||||
|
respond(exchange);
|
||||||
|
});
|
||||||
|
mojangServer.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
MiscUtils.setLookupEndpointsForTesting(
|
||||||
|
"http://127.0.0.1:" + closedPort + "/mojang/uuid?name=",
|
||||||
|
"http://127.0.0.1:" + mojangServer.getAddress().getPort() + "/users/profiles/minecraft/"
|
||||||
|
);
|
||||||
|
|
||||||
|
String result = command.execute(commandExecutor, new String[] {"add", "funkemunky"});
|
||||||
|
|
||||||
|
assertTrue(result.contains(FUNKEMUNKY_UUID.toString()));
|
||||||
|
verify(playerExecutor).getPlayer("funkemunky");
|
||||||
|
assertEquals(1, mojangHits.get(), "Expected Mojang lookup to be used as the fallback");
|
||||||
|
verify(database).addWhitelist(FUNKEMUNKY_UUID);
|
||||||
|
} finally {
|
||||||
|
mojangServer.stop(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void respond(HttpExchange exchange) throws IOException {
|
||||||
|
byte[] bytes = "{\"id\":\"123e4567e89b12d3a456426614174000\"}".getBytes(StandardCharsets.UTF_8);
|
||||||
|
exchange.getResponseHeaders().add("Content-Type", "application/json");
|
||||||
|
exchange.sendResponseHeaders(200, bytes.length);
|
||||||
|
try (exchange; OutputStream outputStream = exchange.getResponseBody()) {
|
||||||
|
outputStream.write(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setAntiVpnInstance(AntiVPN instance) throws Exception {
|
||||||
|
Field instanceField = AntiVPN.class.getDeclaredField("INSTANCE");
|
||||||
|
instanceField.setAccessible(true);
|
||||||
|
instanceField.set(null, instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final class TestVPNExecutor extends VPNExecutor {
|
||||||
|
@Override
|
||||||
|
public void registerListeners() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(Level level, String log, Object... objects) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(String log, Object... objects) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logException(String message, Throwable ex) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runCommand(String command) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disablePlugin() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
dependencies {
|
||||||
|
// No special dependencies for loader-utils other than lombok from root
|
||||||
|
}
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Common</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>loader-utils</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
<annotationProcessorPaths>
|
|
||||||
<path>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>1.18.44</version>
|
|
||||||
</path>
|
|
||||||
</annotationProcessorPaths>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>AntiVPN</artifactId>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</parent>
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
<modules>
|
|
||||||
<module>loader-utils</module>
|
|
||||||
<module>Source</module>
|
|
||||||
</modules>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>Common</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.gradleup.shadow'
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluationDependsOn(':Sponge:SpongePlugin')
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'org.spongepowered:spongeapi:11.0.0'
|
||||||
|
compileOnly project(':Sponge:SpongePlugin')
|
||||||
|
implementation project(':Common:loader-utils')
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set('')
|
||||||
|
|
||||||
|
// Include the shaded plugin jar as a single resource file
|
||||||
|
from(project(':Sponge:SpongePlugin').tasks.shadowJar) {
|
||||||
|
rename { 'antivpn-sponge.jarinjar' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('shadowJar') {
|
||||||
|
dependsOn(':Sponge:SpongePlugin:shadowJar')
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.build.dependsOn shadowJar
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Sponge</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>SpongeLoader</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>maven-repo</id>
|
|
||||||
<url>https://nexus.funkemunky.cc/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>funkemunky-releases</id>
|
|
||||||
<url>https://nexus.funkemunky.cc/content/repositories/releases/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<minimizeJar>false</minimizeJar>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
|
|
||||||
<resource>antivpn-sponge.jarinjar</resource>
|
|
||||||
<file>${project.parent.basedir}/SpongePlugin/target/SpongePlugin-${project.version}.jar</file>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spongepowered</groupId>
|
|
||||||
<artifactId>spongeapi</artifactId>
|
|
||||||
<version>11.0.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>SpongePlugin</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>loader-utils</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.gradleup.shadow'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'org.spongepowered:spongeapi:11.0.0'
|
||||||
|
testImplementation 'org.spongepowered:spongeapi:11.0.0'
|
||||||
|
compileOnly project(':Common:Source')
|
||||||
|
testImplementation project(':Common:Source')
|
||||||
|
compileOnly project(':Common:loader-utils')
|
||||||
|
testImplementation project(':Common:loader-utils')
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
|
||||||
|
testImplementation 'org.mockito:mockito-core:5.11.0'
|
||||||
|
testImplementation 'org.mockito:mockito-subclass:5.11.0'
|
||||||
|
testImplementation 'org.mockito:mockito-junit-jupiter:5.11.0'
|
||||||
|
testImplementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
|
||||||
|
}
|
||||||
|
tasks.compileJava.dependsOn(':Common:Source:jar')
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
systemProperty 'mockito.mockmaker', 'subclass'
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set('')
|
||||||
|
|
||||||
|
// SpongePlugin pom.xml had some excludes in shade plugin
|
||||||
|
exclude 'com/google/**'
|
||||||
|
exclude 'org/objectweb/**'
|
||||||
|
exclude 'org/checkerframework/**'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.build.dependsOn shadowJar
|
||||||
@@ -1,175 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Sponge</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>SpongePlugin</artifactId>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>maven-repo</id>
|
|
||||||
<url>https://nexus.funkemunky.cc/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>funkemunky-releases</id>
|
|
||||||
<url>https://nexus.funkemunky.cc/content/repositories/releases/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spongepowered</groupId>
|
|
||||||
<artifactId>spongeapi</artifactId>
|
|
||||||
<version>11.0.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>loader-utils</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Source</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>*:*</artifact>
|
|
||||||
<excludes>
|
|
||||||
<exclude>com/google/**</exclude>
|
|
||||||
<exclude>org/objectweb/**</exclude>
|
|
||||||
<exclude>org/checkerframework/**</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
|
|
||||||
</filters>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.yaml.snakeyaml</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.yaml.snakeyaml</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.github.benmanes.caffeine</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.com.github.benmanes.caffeine</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.h2</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.h2</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.bson</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.bson</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.mongodb</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.com.mongodb</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.mysql.cj</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.com.mysql.cj</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.mysql.jdbc</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.com.mysql.jdbc</shadedPattern>
|
|
||||||
<excludes>
|
|
||||||
<!-- Exclude annotation values from relocation -->
|
|
||||||
<exclude>dev.brighten.antivpn.depends.Relocate</exclude>
|
|
||||||
<exclude>dev.brighten.antivpn.depends.MavenLibraries</exclude>
|
|
||||||
</excludes>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
+114
@@ -0,0 +1,114 @@
|
|||||||
|
package dev.brighten.antivpn.sponge;
|
||||||
|
|
||||||
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
import dev.brighten.antivpn.api.PlayerExecutor;
|
||||||
|
import dev.brighten.antivpn.api.VPNConfig;
|
||||||
|
import dev.brighten.antivpn.api.VPNExecutor;
|
||||||
|
import dev.brighten.antivpn.message.MessageHandler;
|
||||||
|
import dev.brighten.antivpn.message.VpnString;
|
||||||
|
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.spongepowered.api.event.network.ServerSideConnectionEvent;
|
||||||
|
import org.spongepowered.api.network.ServerSideConnection;
|
||||||
|
import org.spongepowered.api.profile.GameProfile;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
public class SpongeListenerTest {
|
||||||
|
|
||||||
|
private SpongeListener listener;
|
||||||
|
private VPNExecutor vpnExecutor;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
AntiVPN antiVPN = mock(AntiVPN.class);
|
||||||
|
VPNConfig config = mock(VPNConfig.class);
|
||||||
|
PlayerExecutor playerExecutor = mock(PlayerExecutor.class);
|
||||||
|
vpnExecutor = mock(VPNExecutor.class);
|
||||||
|
MessageHandler messageHandler = mock(MessageHandler.class);
|
||||||
|
|
||||||
|
when(antiVPN.getVpnConfig()).thenReturn(config);
|
||||||
|
when(antiVPN.getPlayerExecutor()).thenReturn(playerExecutor);
|
||||||
|
when(antiVPN.getExecutor()).thenReturn(vpnExecutor);
|
||||||
|
when(antiVPN.getMessageHandler()).thenReturn(messageHandler);
|
||||||
|
|
||||||
|
when(playerExecutor.getPlayer(any(UUID.class))).thenReturn(Optional.empty());
|
||||||
|
when(config.getPrefixWhitelists()).thenReturn(java.util.Collections.emptyList());
|
||||||
|
when(config.getCountryList()).thenReturn(java.util.Collections.emptyList());
|
||||||
|
when(config.isKickPlayers()).thenReturn(true);
|
||||||
|
when(config.getKickMessage()).thenReturn("Blocked!");
|
||||||
|
|
||||||
|
VpnString mockVpnString = mock(VpnString.class);
|
||||||
|
when(mockVpnString.getFormattedMessage(any())).thenReturn("Blocked!");
|
||||||
|
when(messageHandler.getString(anyString())).thenReturn(mockVpnString);
|
||||||
|
|
||||||
|
when(vpnExecutor.checkIp(anyString())).thenReturn(CompletableFuture.completedFuture(
|
||||||
|
VPNResponse.builder().success(true).proxy(false).ip("127.0.0.1")
|
||||||
|
.method("N/A").countryName("N/A").city("N/A").build()
|
||||||
|
));
|
||||||
|
|
||||||
|
// Use reflection to set the private static INSTANCE field
|
||||||
|
Field instanceField = AntiVPN.class.getDeclaredField("INSTANCE");
|
||||||
|
instanceField.setAccessible(true);
|
||||||
|
instanceField.set(null, antiVPN);
|
||||||
|
|
||||||
|
listener = new SpongeListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
// Reset the singleton
|
||||||
|
Field instanceField = AntiVPN.class.getDeclaredField("INSTANCE");
|
||||||
|
instanceField.setAccessible(true);
|
||||||
|
instanceField.set(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoginEventAllowed() {
|
||||||
|
ServerSideConnectionEvent.Login event = mock(ServerSideConnectionEvent.Login.class);
|
||||||
|
GameProfile profile = mock(GameProfile.class);
|
||||||
|
ServerSideConnection connection = mock(ServerSideConnection.class);
|
||||||
|
|
||||||
|
when(event.profile()).thenReturn(profile);
|
||||||
|
when(event.connection()).thenReturn(connection);
|
||||||
|
when(profile.uuid()).thenReturn(UUID.randomUUID());
|
||||||
|
when(profile.name()).thenReturn(Optional.of("TestPlayer"));
|
||||||
|
when(connection.address()).thenReturn(new InetSocketAddress("127.0.0.1", 12345));
|
||||||
|
|
||||||
|
listener.onJoin(event);
|
||||||
|
|
||||||
|
verify(event, never()).setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoginEventBlocked() {
|
||||||
|
ServerSideConnectionEvent.Login event = mock(ServerSideConnectionEvent.Login.class);
|
||||||
|
GameProfile profile = mock(GameProfile.class);
|
||||||
|
ServerSideConnection connection = mock(ServerSideConnection.class);
|
||||||
|
|
||||||
|
when(event.profile()).thenReturn(profile);
|
||||||
|
when(event.connection()).thenReturn(connection);
|
||||||
|
when(profile.uuid()).thenReturn(UUID.randomUUID());
|
||||||
|
when(profile.name()).thenReturn(Optional.of("ProxyPlayer"));
|
||||||
|
when(connection.address()).thenReturn(new InetSocketAddress("1.1.1.1", 12345));
|
||||||
|
|
||||||
|
// Mock proxy response
|
||||||
|
when(vpnExecutor.checkIp("1.1.1.1")).thenReturn(CompletableFuture.completedFuture(
|
||||||
|
VPNResponse.builder().success(true).proxy(true).ip("1.1.1.1")
|
||||||
|
.method("N/A").countryName("N/A").countryCode("N/A").city("N/A").build()
|
||||||
|
));
|
||||||
|
|
||||||
|
listener.onJoin(event);
|
||||||
|
|
||||||
|
verify(event).setCancelled(true);
|
||||||
|
verify(event).setMessage(any());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>AntiVPN</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</parent>
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
<modules>
|
|
||||||
<module>SpongePlugin</module>
|
|
||||||
<module>SpongeLoader</module>
|
|
||||||
</modules>
|
|
||||||
|
|
||||||
<artifactId>Sponge</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>AntiVPN</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>Universal</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn.bukkit</groupId>
|
|
||||||
<artifactId>Loader</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>VelocityLoader</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn.bungee</groupId>
|
|
||||||
<artifactId>BungeeLoader</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<finalName>AntiVPN-${project.version}-universal</finalName>
|
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
|
|
||||||
<resource>antivpn-source.jarinjar</resource>
|
|
||||||
<file>${project.parent.basedir}/Common/Source/target/Source-${project.version}.jar</file>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.yaml.snakeyaml</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.yaml.snakeyaml</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.bstats</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.bstats</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.objectweb</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.objectweb</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<!-- Add other relocations from Common/pom.xml -->
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.gradleup.shadow'
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluationDependsOn(':Velocity:VelocityPlugin')
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'com.velocitypowered:velocity-api:3.4.0-SNAPSHOT'
|
||||||
|
compileOnly project(':Velocity:VelocityPlugin')
|
||||||
|
implementation project(':Common:loader-utils')
|
||||||
|
implementation 'org.bstats:bstats-velocity:2.2.1'
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set('')
|
||||||
|
|
||||||
|
// Include the shaded plugin jar as a single resource file
|
||||||
|
from(project(':Velocity:VelocityPlugin').tasks.shadowJar) {
|
||||||
|
rename { 'antivpn-velocity.jarinjar' }
|
||||||
|
}
|
||||||
|
|
||||||
|
relocate 'org.bstats', 'dev.brighten.antivpn.velocity.org.bstats'
|
||||||
|
relocate 'org.yaml.snakeyaml', 'dev.brighten.antivpn.shaded.org.yaml.snakeyaml'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('shadowJar') {
|
||||||
|
dependsOn(':Velocity:VelocityPlugin:shadowJar')
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.build.dependsOn shadowJar
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Velocity</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>VelocityLoader</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>velocity</id>
|
|
||||||
<url>https://nexus.funkemunky.cc/repository/papermc-public/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.velocitypowered</groupId>
|
|
||||||
<artifactId>velocity-api</artifactId>
|
|
||||||
<version>3.4.0-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bstats</groupId>
|
|
||||||
<artifactId>bstats-velocity</artifactId>
|
|
||||||
<version>2.2.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>loader-utils</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>VelocityPlugin</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<minimizeJar>false</minimizeJar>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
|
|
||||||
<resource>antivpn-velocity.jarinjar</resource>
|
|
||||||
<file>${project.parent.basedir}/VelocityPlugin/target/VelocityPlugin-${project.version}.jar</file>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.bstats</pattern>
|
|
||||||
<!-- Replace this with your package! -->
|
|
||||||
<shadedPattern>dev.brighten.antivpn.velocity.org.bstats</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.yaml.snakeyaml</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.yaml.snakeyaml</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.gradleup.shadow'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'com.velocitypowered:velocity-api:3.4.0-SNAPSHOT'
|
||||||
|
testImplementation 'com.velocitypowered:velocity-api:3.4.0-SNAPSHOT'
|
||||||
|
compileOnly project(':Common:Source')
|
||||||
|
compileOnly project(':Common:loader-utils')
|
||||||
|
implementation 'org.bstats:bstats-velocity:2.2.1'
|
||||||
|
testImplementation 'org.mockito:mockito-core:5.11.0'
|
||||||
|
testImplementation 'org.mockito:mockito-junit-jupiter:5.11.0'
|
||||||
|
testImplementation 'net.java.dev.jna:jna:5.14.0'
|
||||||
|
testImplementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
|
||||||
|
testImplementation project(':Common:Source')
|
||||||
|
testImplementation project(':Common:loader-utils')
|
||||||
|
}
|
||||||
|
tasks.compileJava.dependsOn(':Common:Source:jar')
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
jvmArgs("-XX:+EnableDynamicAgentLoading")
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set('')
|
||||||
|
relocate 'org.bstats', 'dev.brighten.antivpn.velocity.org.bstats'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.build.dependsOn shadowJar
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>AntiVPN</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<relativePath>../../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>VelocityPlugin</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>velocity</id>
|
|
||||||
<url>https://nexus.funkemunky.cc/repository/papermc-public/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.velocitypowered</groupId>
|
|
||||||
<artifactId>velocity-api</artifactId>
|
|
||||||
<version>3.4.0-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>Source</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bstats</groupId>
|
|
||||||
<artifactId>bstats-velocity</artifactId>
|
|
||||||
<version>2.2.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>loader-utils</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.13.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<configuration>
|
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.bstats</pattern>
|
|
||||||
<!-- Replace this with your package! -->
|
|
||||||
<shadedPattern>dev.brighten.antivpn.velocity.org.bstats</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.yaml.snakeyaml</pattern>
|
|
||||||
<shadedPattern>dev.brighten.antivpn.shaded.org.yaml.snakeyaml</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
+30
-28
@@ -41,43 +41,45 @@ public class VelocityListener extends VPNExecutor {
|
|||||||
.unloadPlayer(event.getPlayer().getUniqueId()));
|
.unloadPlayer(event.getPlayer().getUniqueId()));
|
||||||
|
|
||||||
VelocityPlugin.INSTANCE.getServer().getEventManager().register(VelocityPlugin.INSTANCE.getPluginInstance(), LoginEvent.class,
|
VelocityPlugin.INSTANCE.getServer().getEventManager().register(VelocityPlugin.INSTANCE.getPluginInstance(), LoginEvent.class,
|
||||||
event -> {
|
this::onLogin);
|
||||||
APIPlayer player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(event.getPlayer().getUniqueId())
|
}
|
||||||
.orElse(new OfflinePlayer(
|
|
||||||
event.getPlayer().getUniqueId(),
|
|
||||||
event.getPlayer().getUsername(),
|
|
||||||
event.getPlayer().getRemoteAddress().getAddress()
|
|
||||||
));
|
|
||||||
|
|
||||||
player.checkPlayer(result -> {
|
public void onLogin(LoginEvent event) {
|
||||||
if(!result.resultType().isShouldBlock()) return;
|
APIPlayer player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(event.getPlayer().getUniqueId())
|
||||||
|
.orElse(new OfflinePlayer(
|
||||||
|
event.getPlayer().getUniqueId(),
|
||||||
|
event.getPlayer().getUsername(),
|
||||||
|
event.getPlayer().getRemoteAddress().getAddress()
|
||||||
|
));
|
||||||
|
|
||||||
if(!AntiVPN.getInstance().getVpnConfig().isKickPlayers()) {
|
player.checkPlayer(result -> {
|
||||||
return;
|
if(!result.resultType().isShouldBlock()) return;
|
||||||
}
|
|
||||||
|
|
||||||
switch (result.resultType()) {
|
if(!AntiVPN.getInstance().getVpnConfig().isKickPlayers()) {
|
||||||
case DENIED_COUNTRY -> event.setResult(ResultedEvent.ComponentResult.denied(
|
return;
|
||||||
LegacyComponentSerializer.builder()
|
}
|
||||||
.character('&')
|
|
||||||
.build().deserialize(AntiVPN.getInstance().getVpnConfig()
|
switch (result.resultType()) {
|
||||||
.getCountryVanillaKickReason()
|
case DENIED_COUNTRY -> event.setResult(ResultedEvent.ComponentResult.denied(
|
||||||
.replace("%player%", event.getPlayer().getUsername())
|
LegacyComponentSerializer.builder()
|
||||||
.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('&')
|
.character('&')
|
||||||
.build().deserialize(AntiVPN.getInstance().getVpnConfig()
|
.build().deserialize(AntiVPN.getInstance().getVpnConfig()
|
||||||
.getKickMessage()
|
.getCountryVanillaKickReason()
|
||||||
.replace("%player%", event.getPlayer().getUsername())
|
.replace("%player%", event.getPlayer().getUsername())
|
||||||
.replace("%country%", result.response().getCountryName())
|
.replace("%country%", result.response().getCountryName())
|
||||||
.replace("%code%", result.response().getCountryCode()))));
|
.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()
|
||||||
|
.getKickMessage()
|
||||||
|
.replace("%player%", event.getPlayer().getUsername())
|
||||||
|
.replace("%country%", result.response().getCountryName())
|
||||||
|
.replace("%code%", result.response().getCountryCode()))));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+126
@@ -0,0 +1,126 @@
|
|||||||
|
package dev.brighten.antivpn.velocity;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.connection.LoginEvent;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import dev.brighten.antivpn.AntiVPN;
|
||||||
|
import dev.brighten.antivpn.api.PlayerExecutor;
|
||||||
|
import dev.brighten.antivpn.api.VPNConfig;
|
||||||
|
import dev.brighten.antivpn.api.VPNExecutor;
|
||||||
|
import dev.brighten.antivpn.message.MessageHandler;
|
||||||
|
import dev.brighten.antivpn.message.VpnString;
|
||||||
|
import dev.brighten.antivpn.web.objects.VPNResponse;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
public class VelocityListenerTest {
|
||||||
|
|
||||||
|
private VelocityListener listener;
|
||||||
|
private AntiVPN antiVPN;
|
||||||
|
private VPNConfig config;
|
||||||
|
private PlayerExecutor playerExecutor;
|
||||||
|
private VPNExecutor vpnExecutor;
|
||||||
|
private MessageHandler messageHandler;
|
||||||
|
private VelocityPlugin velocityPlugin;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
antiVPN = mock(AntiVPN.class);
|
||||||
|
config = mock(VPNConfig.class);
|
||||||
|
playerExecutor = mock(PlayerExecutor.class);
|
||||||
|
vpnExecutor = mock(VPNExecutor.class);
|
||||||
|
messageHandler = mock(MessageHandler.class);
|
||||||
|
velocityPlugin = mock(VelocityPlugin.class);
|
||||||
|
|
||||||
|
when(antiVPN.getVpnConfig()).thenReturn(config);
|
||||||
|
when(antiVPN.getPlayerExecutor()).thenReturn(playerExecutor);
|
||||||
|
when(antiVPN.getExecutor()).thenReturn(vpnExecutor);
|
||||||
|
when(antiVPN.getMessageHandler()).thenReturn(messageHandler);
|
||||||
|
|
||||||
|
when(velocityPlugin.getLogger()).thenReturn(Logger.getLogger("AntiVPN"));
|
||||||
|
|
||||||
|
when(playerExecutor.getPlayer(any(UUID.class))).thenReturn(Optional.empty());
|
||||||
|
when(config.getPrefixWhitelists()).thenReturn(java.util.Collections.emptyList());
|
||||||
|
when(config.getCountryList()).thenReturn(java.util.Collections.emptyList());
|
||||||
|
when(config.isKickPlayers()).thenReturn(true);
|
||||||
|
when(config.getKickMessage()).thenReturn("Blocked!");
|
||||||
|
|
||||||
|
VpnString mockVpnString = mock(VpnString.class);
|
||||||
|
when(mockVpnString.getFormattedMessage(any())).thenReturn("Blocked!");
|
||||||
|
when(messageHandler.getString(anyString())).thenReturn(mockVpnString);
|
||||||
|
|
||||||
|
when(vpnExecutor.checkIp(anyString())).thenReturn(CompletableFuture.completedFuture(
|
||||||
|
VPNResponse.builder().success(true).proxy(false).ip("127.0.0.1")
|
||||||
|
.method("N/A").countryName("N/A").city("N/A").countryCode("N/A").build()
|
||||||
|
));
|
||||||
|
|
||||||
|
// Use reflection to set the private static INSTANCE field
|
||||||
|
Field instanceField = AntiVPN.class.getDeclaredField("INSTANCE");
|
||||||
|
instanceField.setAccessible(true);
|
||||||
|
instanceField.set(null, antiVPN);
|
||||||
|
|
||||||
|
Field pluginInstanceField = VelocityPlugin.class.getDeclaredField("INSTANCE");
|
||||||
|
pluginInstanceField.setAccessible(true);
|
||||||
|
pluginInstanceField.set(null, velocityPlugin);
|
||||||
|
|
||||||
|
listener = new VelocityListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
// Reset the singletons
|
||||||
|
Field instanceField = AntiVPN.class.getDeclaredField("INSTANCE");
|
||||||
|
instanceField.setAccessible(true);
|
||||||
|
instanceField.set(null, null);
|
||||||
|
|
||||||
|
Field pluginInstanceField = VelocityPlugin.class.getDeclaredField("INSTANCE");
|
||||||
|
pluginInstanceField.setAccessible(true);
|
||||||
|
pluginInstanceField.set(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoginEventAllowed() throws Exception {
|
||||||
|
LoginEvent event = mock(LoginEvent.class);
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
|
when(event.getPlayer()).thenReturn(player);
|
||||||
|
when(player.getUniqueId()).thenReturn(UUID.randomUUID());
|
||||||
|
when(player.getUsername()).thenReturn("TestPlayer");
|
||||||
|
when(player.getRemoteAddress()).thenReturn(new InetSocketAddress("127.0.0.1", 12345));
|
||||||
|
|
||||||
|
listener.onLogin(event);
|
||||||
|
|
||||||
|
verify(event, never()).setResult(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoginEventBlocked() throws Exception {
|
||||||
|
LoginEvent event = mock(LoginEvent.class);
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
|
when(event.getPlayer()).thenReturn(player);
|
||||||
|
when(player.getUniqueId()).thenReturn(UUID.randomUUID());
|
||||||
|
when(player.getUsername()).thenReturn("ProxyPlayer");
|
||||||
|
when(player.getRemoteAddress()).thenReturn(new InetSocketAddress("1.1.1.1", 12345));
|
||||||
|
|
||||||
|
// Mock proxy response
|
||||||
|
when(vpnExecutor.checkIp("1.1.1.1")).thenReturn(CompletableFuture.completedFuture(
|
||||||
|
VPNResponse.builder().success(true).proxy(true).ip("1.1.1.1")
|
||||||
|
.method("N/A").countryName("N/A").city("N/A").countryCode("N/A").build()
|
||||||
|
));
|
||||||
|
|
||||||
|
listener.onLogin(event);
|
||||||
|
|
||||||
|
verify(event).setResult(any());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>AntiVPN</artifactId>
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</parent>
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>Velocity</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'com.gradleup.shadow' version '9.4.1'
|
||||||
|
}
|
||||||
|
|
||||||
|
def aggregateTestProjects = [
|
||||||
|
project(':Common:Source'),
|
||||||
|
project(':Bukkit:Plugin'),
|
||||||
|
project(':Bungee:BungeePlugin'),
|
||||||
|
project(':Sponge:SpongePlugin'),
|
||||||
|
project(':Velocity:VelocityPlugin')
|
||||||
|
]
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
group = 'dev.brighten.antivpn'
|
||||||
|
version = '1.10.1'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url 'https://repo.papermc.io/repository/maven-public/' }
|
||||||
|
maven { url 'https://nexus.funkemunky.cc/repository/papermc-public/' }
|
||||||
|
maven { url 'https://nexus.funkemunky.cc/repository/maven-public/' }
|
||||||
|
maven { url 'https://nexus.funkemunky.cc/repository/maven-central/' }
|
||||||
|
maven { url 'https://nexus.funkemunky.cc/content/repositories/releases/' }
|
||||||
|
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
|
||||||
|
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
|
||||||
|
maven { url 'https://repo.spongepowered.org/repository/maven-public/' }
|
||||||
|
maven { url 'https://jitpack.io' }
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'java'
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(21)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
options.compilerArgs << '-XDignore.symbol.file'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'org.projectlombok:lombok:1.18.44'
|
||||||
|
annotationProcessor 'org.projectlombok:lombok:1.18.44'
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
|
||||||
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
systemProperty 'mockito.mockmaker', 'subclass'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation 'org.junit.platform:junit-platform-suite:1.11.4'
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
test {
|
||||||
|
compileClasspath += files(aggregateTestProjects.collect { it.sourceSets.test.output + it.sourceSets.test.compileClasspath })
|
||||||
|
runtimeClasspath += files(aggregateTestProjects.collect { it.sourceSets.test.output + it.sourceSets.test.runtimeClasspath })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('test') {
|
||||||
|
dependsOn(aggregateTestProjects.collect { it.tasks.named('testClasses') })
|
||||||
|
jvmArgs("-XX:+EnableDynamicAgentLoading")
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluationDependsOn(':Common:Source')
|
||||||
|
evaluationDependsOn(':Bukkit:Loader')
|
||||||
|
evaluationDependsOn(':Velocity:VelocityLoader')
|
||||||
|
evaluationDependsOn(':Bungee:BungeeLoader')
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(':Bukkit:Loader')
|
||||||
|
implementation project(':Velocity:VelocityLoader')
|
||||||
|
implementation project(':Bungee:BungeeLoader')
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveFileName.set("AntiVPN-${project.version}-universal.jar")
|
||||||
|
|
||||||
|
// Include the shaded Common:Source jar as a single resource
|
||||||
|
from(project(':Common:Source').tasks.shadowJar) {
|
||||||
|
rename { 'antivpn-source.jarinjar' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('shadowJar') {
|
||||||
|
dependsOn(':Common:Source:shadowJar')
|
||||||
|
dependsOn(':Bukkit:Loader:shadowJar')
|
||||||
|
dependsOn(':Velocity:VelocityLoader:shadowJar')
|
||||||
|
dependsOn(':Bungee:BungeeLoader:shadowJar')
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.build.dependsOn shadowJar
|
||||||
Vendored
BIN
Binary file not shown.
+7
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015 the original authors.
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
# https://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.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
Vendored
+93
@@ -0,0 +1,93 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<groupId>dev.brighten.antivpn</groupId>
|
|
||||||
<artifactId>AntiVPN</artifactId>
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
|
|
||||||
<modules>
|
|
||||||
<module>Common</module>
|
|
||||||
<module>Bungee</module>
|
|
||||||
<module>Bukkit</module>
|
|
||||||
<module>Velocity</module>
|
|
||||||
<module>Sponge</module>
|
|
||||||
<module>Universal</module>
|
|
||||||
<module>Velocity/VelocityLoader</module>
|
|
||||||
<module>Velocity/VelocityPlugin</module>
|
|
||||||
<module>Bungee/BungeeLoader</module>
|
|
||||||
<module>Bungee/BungeePlugin</module>
|
|
||||||
</modules>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.7.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>17</source>
|
|
||||||
<target>17</target>
|
|
||||||
<compilerArgument>-XDignore.symbol.file</compilerArgument>
|
|
||||||
<useIncrementalCompilation>false</useIncrementalCompilation>
|
|
||||||
<annotationProcessorPaths>
|
|
||||||
<path>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>1.18.44</version>
|
|
||||||
</path>
|
|
||||||
</annotationProcessorPaths>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>funkemunky-releases</id>
|
|
||||||
<url>https://nexus.funkemunky.cc/content/repositories/releases/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>1.18.44</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
rootProject.name = 'AntiVPN'
|
||||||
|
|
||||||
|
include 'Common:Source'
|
||||||
|
include 'Common:loader-utils'
|
||||||
|
|
||||||
|
include 'Bukkit:Plugin'
|
||||||
|
include 'Bukkit:Loader'
|
||||||
|
|
||||||
|
include 'Bungee:BungeePlugin'
|
||||||
|
include 'Bungee:BungeeLoader'
|
||||||
|
|
||||||
|
include 'Sponge:SpongePlugin'
|
||||||
|
include 'Sponge:SpongeLoader'
|
||||||
|
|
||||||
|
include 'Velocity:VelocityPlugin'
|
||||||
|
include 'Velocity:VelocityLoader'
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user