mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 11:07:41 +00:00
Compare commits
28 Commits
v2.0.0
...
v2.0.7+ebc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebcae682aa | ||
|
|
f22e800439 | ||
|
|
f0274ff4d4 | ||
|
|
12f9d669b4 | ||
|
|
c43de8a1c9 | ||
|
|
d8fa2b10c1 | ||
|
|
89311ee6de | ||
|
|
14ffd4eb08 | ||
|
|
50fdbb0c28 | ||
|
|
bb71befe78 | ||
|
|
49f4e249e5 | ||
|
|
5491efa79a | ||
|
|
5e29f7f74a | ||
|
|
ffdbcfa3b4 | ||
|
|
58123dddd7 | ||
|
|
91adbd5526 | ||
|
|
2b1ccd018d | ||
|
|
8f1fd3f1f4 | ||
|
|
50e2a954cd | ||
|
|
a6fb5e379c | ||
|
|
2699ceaeff | ||
|
|
9985223d22 | ||
|
|
b6df47ee2e | ||
|
|
9caec20ef0 | ||
|
|
34226ec549 | ||
|
|
1aa22606b2 | ||
|
|
a483b6ccc5 | ||
|
|
a78fa33de8 |
41
.github/workflows/gradle.yml
vendored
41
.github/workflows/gradle.yml
vendored
@@ -4,6 +4,7 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
paths: [ src/**, build.gradle.kts, settings.gradle.kts ]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -49,21 +50,49 @@ jobs:
|
|||||||
echo "EXISTS=false" >> "$GITHUB_OUTPUT"
|
echo "EXISTS=false" >> "$GITHUB_OUTPUT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
- id: mrck
|
||||||
|
run: |
|
||||||
|
echo "TOKEN=$([ -n "${{ secrets.MODRINTH_TOKEN }}" ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- id: dist
|
||||||
|
run: |
|
||||||
|
echo "TAG_NAME=${{ format('v{0}{1}', steps.vars.outputs.VERS, steps.ghck.outputs.EXISTS == 'true' && format('+{0}', steps.vars.outputs.COMMIT_HASH) || '') }}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "REL_NAME=${{ format('{0}{1}', steps.ghck.outputs.EXISTS == 'true' && 'Snapshot ' || 'v', steps.ghck.outputs.EXISTS == 'true' && steps.vars.outputs.COMMIT_HASH || steps.vars.outputs.VERS) }}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "ART_NAME=${{ format('{0}{1}.jar', steps.vars.outputs.AFCT, steps.ghck.outputs.EXISTS == 'true' && format('+{0}', steps.vars.outputs.COMMIT_HASH) || '') }}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
cp "./build/libs/${{ steps.vars.outputs.AFCT }}" ./dist
|
cp "./build/libs/${{ steps.vars.outputs.AFCT }}.jar" ./dist/${{ steps.dist.outputs.ART_NAME }}
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
path: dist/${{ steps.vars.outputs.AFCT }}
|
path: dist/${{ steps.dist.outputs.ART_NAME }}
|
||||||
name: ${{ steps.vars.outputs.AFCT }}
|
name: ${{ steps.dist.outputs.ART_NAME }}
|
||||||
|
|
||||||
- if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
- if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ format('v{0}{1}', steps.vars.outputs.VERS, steps.ghck.outputs.EXISTS == 'true' && format('+{0}', steps.vars.outputs.COMMIT_HASH) || '') }}
|
tag_name: ${{ steps.dist.outputs.TAG_NAME }}
|
||||||
name: ${{ format('{0}{1}', steps.ghck.outputs.EXISTS == 'true' && 'Snapshot ' || 'v', steps.ghck.outputs.EXISTS == 'true' && steps.vars.outputs.COMMIT_HASH || steps.vars.outputs.VERS) }}
|
name: ${{ steps.dist.outputs.REL_NAME }}
|
||||||
files: dist/${{ steps.vars.outputs.AFCT }}
|
files: dist/${{ steps.dist.outputs.ART_NAME }}
|
||||||
prerelease: ${{ steps.ghck.outputs.EXISTS == 'true' }}
|
prerelease: ${{ steps.ghck.outputs.EXISTS == 'true' }}
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.mrck.outputs.TOKEN == 'true'
|
||||||
|
uses: cloudnode-pro/modrinth-publish@v2
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.MODRINTH_TOKEN }}
|
||||||
|
project: WfBtRGYI
|
||||||
|
version: ${{ steps.dist.outputs.TAG_NAME }}
|
||||||
|
loaders: '["bukkit", "bungeecord", "paper", "purpur", "spigot", "velocity", "waterfall"]'
|
||||||
|
game-versions: '["1.8.x", "1.9.x", "1.10.x", "1.11.x", "1.12.x", "1.13.x", "1.14.x", "1.15.x", "1.16.x", "1.17.x", "1.18.x", "1.19.x", "1.20.x", "1.21.x"]'
|
||||||
|
files: dist/${{ steps.dist.outputs.ART_NAME }}
|
||||||
|
primary-file: ${{ steps.dist.outputs.ART_NAME }}
|
||||||
|
name: ${{ steps.dist.outputs.REL_NAME }}
|
||||||
|
channel: ${{ steps.ghck.outputs.EXISTS == 'true' && 'beta' || 'release' }}
|
||||||
|
dependencies: |-
|
||||||
|
[{
|
||||||
|
"project_id": "Gtsn3SWv",
|
||||||
|
"dependency_type": "required"
|
||||||
|
}]
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,7 +1,10 @@
|
|||||||
/.gradle/
|
/.gradle/
|
||||||
/.vscode/
|
/.vscode/
|
||||||
/gradle/
|
/gradle/**
|
||||||
/build/
|
/build/
|
||||||
|
/bin/
|
||||||
/run/
|
/run/
|
||||||
/gradlew
|
/gradlew
|
||||||
/gradlew.bat
|
/gradlew.bat
|
||||||
|
!/gradle/wrapper/
|
||||||
|
!/gradle/wrapper/*.properties
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -13,12 +13,19 @@
|
|||||||
- [x] Blacklist MOTD customization
|
- [x] Blacklist MOTD customization
|
||||||
- [x] MiniMessage and legacy formattings supported
|
- [x] MiniMessage and legacy formattings supported
|
||||||
- [x] Plugin update checker
|
- [x] Plugin update checker
|
||||||
- [ ] Send blacklist logs to a webhook
|
- [x] Send blacklist logs to a webhook
|
||||||
|
- [x] Ingame blacklist management commands
|
||||||
|
- [x] Blacklist sharing via EaglerXServer routes
|
||||||
|
- [x] Reverse blacklist (whitelist)
|
||||||
- [ ] Subscribe to an auto-updating blacklist
|
- [ ] Subscribe to an auto-updating blacklist
|
||||||
- [ ] Reverse blacklist (whitelist)
|
|
||||||
|
<h2>Changes from v1</h2>
|
||||||
|
|
||||||
|
- [x] Modular multi-platform support
|
||||||
|
- [x] JSON5 based configuration
|
||||||
|
|
||||||
<h2>Download</h2>
|
<h2>Download</h2>
|
||||||
The latest release can be found at <b><a href="https://github.com/WebMCDevelopment/originblacklist/releases/tag/v1.1.3">https://github.com/WebMCDevelopment/originblacklist/releases/tag/v1.1.3</a></b>
|
The latest release can be found at <b><a href="https://github.com/WebMCDevelopment/originblacklist/releases/latest/">https://github.com/WebMCDevelopment/originblacklist/releases/latest/</a></b>
|
||||||
|
|
||||||
<h2>Building</h2>
|
<h2>Building</h2>
|
||||||
|
|
||||||
|
|||||||
166
build.gradle.kts
166
build.gradle.kts
@@ -1,3 +1,6 @@
|
|||||||
|
import groovy.lang.Closure
|
||||||
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
|
import com.palantir.gradle.gitversion.VersionDetails
|
||||||
import org.gradle.api.tasks.compile.JavaCompile
|
import org.gradle.api.tasks.compile.JavaCompile
|
||||||
import org.gradle.language.jvm.tasks.ProcessResources
|
import org.gradle.language.jvm.tasks.ProcessResources
|
||||||
import xyz.jpenilla.runpaper.task.RunServer
|
import xyz.jpenilla.runpaper.task.RunServer
|
||||||
@@ -9,9 +12,9 @@ import xyz.jpenilla.runvelocity.task.RunVelocity
|
|||||||
|
|
||||||
val PLUGIN_NAME = "OriginBlacklist"
|
val PLUGIN_NAME = "OriginBlacklist"
|
||||||
val PLUGIN_IDEN = "originblacklist"
|
val PLUGIN_IDEN = "originblacklist"
|
||||||
val PLUGIN_DOMN = "xyz.webmc"
|
val PLUGIN_DOMN = "xyz.webmc.$PLUGIN_IDEN"
|
||||||
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
||||||
val PLUGIN_VERS = "2.0.0"
|
val PLUGIN_VERS = "2.0.7"
|
||||||
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
||||||
val PLUGIN_DEPA = listOf("EaglercraftXServer")
|
val PLUGIN_DEPA = listOf("EaglercraftXServer")
|
||||||
val PLUGIN_DEPB = listOf("EaglercraftXServer")
|
val PLUGIN_DEPB = listOf("EaglercraftXServer")
|
||||||
@@ -26,23 +29,29 @@ val PLUGIN_CTBR = emptyList<String>()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
val PLUGIN_DEPA_J = getJSONObj(PLUGIN_DEPA)
|
val PLUGIN_DEPA_J = getBukkitBungeeDeps(PLUGIN_DEPA)
|
||||||
val PLUGIN_DEPB_J = getJSONObj(PLUGIN_DEPB)
|
val PLUGIN_DEPB_J = getBukkitBungeeDeps(PLUGIN_DEPB)
|
||||||
val PLUGIN_DEPC_J = getJSONObjMerge(PLUGIN_DEPC, PLUGIN_SDPC)
|
val PLUGIN_DEPC_J = getVelocityDeps(PLUGIN_DEPC, PLUGIN_SDPC)
|
||||||
val PLUGIN_SDPA_J = getJSONObj(PLUGIN_SDPA)
|
val PLUGIN_SDPA_J = getBukkitBungeeDeps(PLUGIN_SDPA)
|
||||||
val PLUGIN_SDPB_J = getJSONObj(PLUGIN_SDPB)
|
val PLUGIN_SDPB_J = getBukkitBungeeDeps(PLUGIN_SDPB)
|
||||||
val PLUGIN_PROV_J = getJSONObj(PLUGIN_PROV)
|
val PLUGIN_PROV_J = getBukkitBungeeDeps(PLUGIN_PROV)
|
||||||
val PLUGIN_ATHR_J = getJSONObj(PLUGIN_ATHR)
|
val PLUGIN_ATHR_J = getBukkitBungeeDeps(PLUGIN_ATHR)
|
||||||
val PLUGIN_CTBR_J = getJSONObj(PLUGIN_CTBR)
|
val PLUGIN_CTBR_J = getBukkitBungeeDeps(PLUGIN_CTBR)
|
||||||
|
|
||||||
|
val EAGXS_VER = "1.0.8"
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("com.gradleup.shadow") version "9.3.0"
|
id("com.gradleup.shadow") version "9.3.1"
|
||||||
|
id("com.palantir.git-version") version "4.2.0"
|
||||||
id("xyz.jpenilla.run-paper") version "3.0.2"
|
id("xyz.jpenilla.run-paper") version "3.0.2"
|
||||||
id("xyz.jpenilla.run-waterfall") version "3.0.2"
|
id("xyz.jpenilla.run-waterfall") version "3.0.2"
|
||||||
id("xyz.jpenilla.run-velocity") version "3.0.2"
|
id("xyz.jpenilla.run-velocity") version "3.0.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val GIT_INFO = (extra["versionDetails"] as Closure<VersionDetails>)()
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven("https://repo.papermc.io/repository/maven-public/")
|
maven("https://repo.papermc.io/repository/maven-public/")
|
||||||
@@ -85,97 +94,116 @@ java {
|
|||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val BUILD_PROPS = mapOf(
|
||||||
|
"plugin_name" to PLUGIN_NAME,
|
||||||
|
"plugin_iden" to PLUGIN_IDEN,
|
||||||
|
"plugin_desc" to PLUGIN_DESC,
|
||||||
|
"plugin_vers" to PLUGIN_VERS,
|
||||||
|
"plugin_site" to PLUGIN_SITE,
|
||||||
|
"plugin_depa" to PLUGIN_DEPA_J,
|
||||||
|
"plugin_depb" to PLUGIN_DEPB_J,
|
||||||
|
"plugin_depc" to PLUGIN_DEPC_J,
|
||||||
|
"plugin_sdpa" to PLUGIN_SDPA_J,
|
||||||
|
"plugin_sdpb" to PLUGIN_SDPB_J,
|
||||||
|
"plugin_prov" to PLUGIN_PROV_J,
|
||||||
|
"plugin_athr" to PLUGIN_ATHR_J,
|
||||||
|
"plugin_ctbr" to PLUGIN_CTBR_J,
|
||||||
|
"git_cm_hash" to GIT_INFO.gitHashFull,
|
||||||
|
)
|
||||||
|
|
||||||
tasks.withType<JavaCompile>().configureEach {
|
tasks.withType<JavaCompile>().configureEach {
|
||||||
options.encoding = "UTF-8"
|
options.encoding = "UTF-8"
|
||||||
options.release.set(17)
|
options.release.set(17)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<ProcessResources>() {
|
tasks.withType<ProcessResources>().configureEach {
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
outputs.upToDateWhen { false }
|
outputs.upToDateWhen { false }
|
||||||
|
|
||||||
doFirst {
|
doFirst {
|
||||||
filesMatching(listOf("plugin.yml", "bungee.yml", "velocity-plugin.json")) {
|
filesMatching(listOf("plugin.yml", "bungee.yml", "velocity-plugin.json")) {
|
||||||
expand(mapOf(
|
expand(BUILD_PROPS)
|
||||||
"plugin_name" to PLUGIN_NAME,
|
|
||||||
"plugin_iden" to PLUGIN_IDEN,
|
|
||||||
"plugin_desc" to PLUGIN_DESC,
|
|
||||||
"plugin_vers" to PLUGIN_VERS,
|
|
||||||
"plugin_site" to PLUGIN_SITE,
|
|
||||||
"plugin_depa" to PLUGIN_DEPA_J,
|
|
||||||
"plugin_depb" to PLUGIN_DEPB_J,
|
|
||||||
"plugin_depc" to PLUGIN_DEPC_J,
|
|
||||||
"plugin_sdpa" to PLUGIN_SDPA_J,
|
|
||||||
"plugin_sdpb" to PLUGIN_SDPB_J,
|
|
||||||
"plugin_prov" to PLUGIN_PROV_J,
|
|
||||||
"plugin_athr" to PLUGIN_ATHR_J,
|
|
||||||
"plugin_ctbr" to PLUGIN_CTBR_J,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
val file = destinationDir.resolve("build.properties")
|
||||||
|
file.parentFile.mkdirs()
|
||||||
|
file.writeText(
|
||||||
|
BUILD_PROPS.entries.joinToString("\n") { (k, v) ->
|
||||||
|
"$k = $v"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
inputs.files(tasks.named<JavaCompile>("compileJava").map { it.outputs.files })
|
inputs.files(tasks.named<JavaCompile>("compileJava").map { it.outputs.files })
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<RunServer>() {
|
tasks.withType<Jar>().configureEach {
|
||||||
minecraftVersion("1.12.2")
|
if (this !is ShadowJar) enabled = false
|
||||||
runDirectory.set(layout.projectDirectory.dir("run/paper"))
|
|
||||||
downloadPlugins {
|
|
||||||
github("lax1dude", "eaglerxserver", "v1.0.8", "EaglerXServer.jar")
|
|
||||||
modrinth("placeholderapi", "2.11.7")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<RunWaterfall>() {
|
tasks.withType<ShadowJar>().configureEach {
|
||||||
waterfallVersion("1.21")
|
doFirst {
|
||||||
runDirectory.set(layout.projectDirectory.dir("run/waterfall"))
|
delete(layout.buildDirectory.dir("libs"))
|
||||||
downloadPlugins {
|
mkdir(layout.buildDirectory.dir("libs"))
|
||||||
github("lax1dude", "eaglerxserver", "v1.0.8", "EaglerXServer.jar")
|
|
||||||
}
|
}
|
||||||
}
|
relocate("inet.ipaddr", "$PLUGIN_DOMN.shaded.ipaddress")
|
||||||
|
relocate("de.marhali.json5", "$PLUGIN_DOMN.shaded.json5")
|
||||||
tasks.withType<RunVelocity>() {
|
relocate("org.bstats", "$PLUGIN_DOMN.shaded.bstats")
|
||||||
velocityVersion("3.4.0-SNAPSHOT")
|
relocate("org.semver4j.semver4j", "$PLUGIN_DOMN.shaded.semver4j")
|
||||||
runDirectory.set(layout.projectDirectory.dir("run/velocity"))
|
// relocate("net.kyori.adventure", "$PLUGIN_DOMN.shaded.adventure")
|
||||||
downloadPlugins {
|
|
||||||
github("lax1dude", "eaglerxserver", "v1.0.8", "EaglerXServer.jar")
|
|
||||||
modrinth("miniplaceholders", "3.1.0")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.jar {
|
|
||||||
archiveFileName.set("$PLUGIN_NAME-$PLUGIN_VERS.jar")
|
archiveFileName.set("$PLUGIN_NAME-$PLUGIN_VERS.jar")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.shadowJar {
|
tasks.named("build") {
|
||||||
relocate("org.bstats", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.bstats")
|
dependsOn(tasks.named("shadowJar"))
|
||||||
relocate("de.marhali.json5", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.json5")
|
|
||||||
relocate("org.semver4j.semver4j", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.semver4j")
|
|
||||||
// relocate("net.kyori.adventure", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.adventure")
|
|
||||||
archiveFileName.set("$PLUGIN_NAME-$PLUGIN_VERS.jar")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register("printVars") {
|
tasks.register("printVars") {
|
||||||
group = "help"
|
group = "help"
|
||||||
doLast {
|
doLast {
|
||||||
println("VERS = " + PLUGIN_VERS)
|
println("VERS = " + PLUGIN_VERS)
|
||||||
println("AFCT = " + tasks.named("shadowJar").get().outputs.files.singleFile.name)
|
println("AFCT = " + tasks.named("shadowJar").get().outputs.files.singleFile.name.removeSuffix(".jar"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getJSONObj(list: List<String>): String {
|
tasks.withType<RunServer>().configureEach {
|
||||||
return if (list.isNotEmpty()) {
|
minecraftVersion("1.12.2")
|
||||||
list.joinToString(
|
runDirectory.set(layout.projectDirectory.dir("run/paper"))
|
||||||
separator = "\", \"",
|
jvmArgs("-Dcom.mojang.eula.agree=true")
|
||||||
prefix = "\"",
|
downloadPlugins {
|
||||||
postfix = "\""
|
github("lax1dude", "eaglerxserver", "v" + EAGXS_VER, "EaglerXServer.jar")
|
||||||
)
|
modrinth("placeholderapi", "2.11.7")
|
||||||
} else {
|
|
||||||
""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getJSONObjMerge(a: List<String>, b: List<String>): String {
|
tasks.withType<RunWaterfall>().configureEach {
|
||||||
|
waterfallVersion("1.21")
|
||||||
|
runDirectory.set(layout.projectDirectory.dir("run/waterfall"))
|
||||||
|
downloadPlugins {
|
||||||
|
github("lax1dude", "eaglerxserver", "v" + EAGXS_VER, "EaglerXServer.jar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<RunVelocity>().configureEach {
|
||||||
|
velocityVersion("3.4.0-SNAPSHOT")
|
||||||
|
runDirectory.set(layout.projectDirectory.dir("run/velocity"))
|
||||||
|
downloadPlugins {
|
||||||
|
github("lax1dude", "eaglerxserver", "v" + EAGXS_VER, "EaglerXServer.jar")
|
||||||
|
modrinth("miniplaceholders", "3.1.0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getBukkitBungeeDeps(list: List<String>): String {
|
||||||
|
return list.joinToString(
|
||||||
|
prefix = "[",
|
||||||
|
postfix = "]"
|
||||||
|
) { "\"$it\"" }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getVelocityDeps(a: List<String>, b: List<String>): String {
|
||||||
val c = a.joinToString(", ") { "{\"id\":\"$it\",\"optional\":false}" }
|
val c = a.joinToString(", ") { "{\"id\":\"$it\",\"optional\":false}" }
|
||||||
val d = b.joinToString(", ") { "{\"id\":\"$it\",\"optional\":true}" }
|
val d = b.joinToString(", ") { "{\"id\":\"$it\",\"optional\":true}" }
|
||||||
return listOf(c, d).filter { it.isNotEmpty() }.joinToString(",")
|
return "[" + listOf(c, d).filter { it.isNotEmpty() }.joinToString(",") + "]"
|
||||||
}
|
}
|
||||||
|
|||||||
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
BIN
img/icon2.png
Normal file
BIN
img/icon2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
@@ -2,49 +2,99 @@ package xyz.webmc.originblacklist.base;
|
|||||||
|
|
||||||
import xyz.webmc.originblacklist.base.config.OriginBlacklistConfig;
|
import xyz.webmc.originblacklist.base.config.OriginBlacklistConfig;
|
||||||
import xyz.webmc.originblacklist.base.enums.EnumBlacklistType;
|
import xyz.webmc.originblacklist.base.enums.EnumBlacklistType;
|
||||||
|
import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
||||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||||
|
import xyz.webmc.originblacklist.base.http.OriginBlacklistRequestHandler;
|
||||||
|
import xyz.webmc.originblacklist.base.util.BuildInfo;
|
||||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||||
import xyz.webmc.originblacklist.base.util.UpdateChecker;
|
import xyz.webmc.originblacklist.base.util.UpdateChecker;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.semver4j.Semver;
|
import de.marhali.json5.Json5;
|
||||||
|
|
||||||
import de.marhali.json5.Json5Array;
|
import de.marhali.json5.Json5Array;
|
||||||
import de.marhali.json5.Json5Element;
|
import de.marhali.json5.Json5Element;
|
||||||
|
import de.marhali.json5.Json5Object;
|
||||||
import inet.ipaddr.AddressStringException;
|
import inet.ipaddr.AddressStringException;
|
||||||
import inet.ipaddr.IPAddressString;
|
import inet.ipaddr.IPAddressString;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
||||||
|
import org.semver4j.Semver;
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes" })
|
||||||
public final class OriginBlacklist {
|
public final class OriginBlacklist {
|
||||||
|
private static final String COMMIT_L = BuildInfo.get("git_cm_hash");
|
||||||
|
private static final String COMMIT_S = COMMIT_L.substring(0, 8);
|
||||||
|
|
||||||
public static final Semver REQUIRED_API_VER = new Semver("1.0.2");
|
public static final Semver REQUIRED_API_VER = new Semver("1.0.2");
|
||||||
public static final String GENERIC_STR = "generic";
|
public static final String GENERIC_STR = "GENERIC";
|
||||||
public static final String UNKNOWN_STR = "unknown";
|
public static final String UNKNOWN_STR = "UNKNOWN";
|
||||||
|
public static final String CENSORED_STR = "CENSORED";
|
||||||
public static final String PLUGIN_REPO = "WebMCDevelopment/originblacklist";
|
public static final String PLUGIN_REPO = "WebMCDevelopment/originblacklist";
|
||||||
public static final int BSTATS_ID = 28776;
|
public static final int BSTATS_ID = 28776;
|
||||||
|
|
||||||
private final IOriginBlacklistPlugin plugin;
|
private final IOriginBlacklistPlugin plugin;
|
||||||
private final OriginBlacklistConfig config;
|
private final OriginBlacklistConfig config;
|
||||||
private boolean updateAvailable;
|
private final Json5 json5;
|
||||||
|
private String updateURL;
|
||||||
|
private Path jarFile;
|
||||||
|
|
||||||
public OriginBlacklist(final IOriginBlacklistPlugin plugin) {
|
public OriginBlacklist(final IOriginBlacklistPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.config = new OriginBlacklistConfig(plugin);
|
this.config = new OriginBlacklistConfig(this);
|
||||||
this.checkForUpdate();
|
this.json5 = Json5.builder(builder -> builder.prettyPrinting().indentFactor(0).build());
|
||||||
plugin.scheduleRepeat(() -> {
|
}
|
||||||
this.checkForUpdate();
|
|
||||||
}, 60, TimeUnit.MINUTES);
|
public final void init() {
|
||||||
|
this.jarFile = this.plugin.getPluginJarPath();
|
||||||
|
this.plugin.scheduleRepeat(() -> {
|
||||||
|
this.checkForUpdates();
|
||||||
|
}, this.config.getInteger("update_checker.check_timer"), TimeUnit.SECONDS);
|
||||||
|
if (this.isBlacklistAPIEnabled()) {
|
||||||
|
OriginBlacklistRequestHandler.register(this);
|
||||||
|
}
|
||||||
|
this.plugin.log(EnumLogLevel.INFO, "Initialized Plugin");
|
||||||
|
this.plugin.log(EnumLogLevel.DEBUG, "Commit " + COMMIT_L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void shutdown() {
|
||||||
|
this.plugin.log(EnumLogLevel.INFO, "Shutting down...");
|
||||||
|
if (this.isBlacklistAPIEnabled()) {
|
||||||
|
OriginBlacklistRequestHandler.unRegister(this);
|
||||||
|
}
|
||||||
|
this.plugin.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void handleReload() {
|
||||||
|
try {
|
||||||
|
if (this.isBlacklistAPIEnabled()) {
|
||||||
|
OriginBlacklistRequestHandler.register(this);
|
||||||
|
} else {
|
||||||
|
OriginBlacklistRequestHandler.unRegister(this);
|
||||||
|
}
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void handleLogin(final OriginBlacklistLoginEvent event) {
|
public final void handleLogin(final OriginBlacklistLoginEvent event) {
|
||||||
@@ -66,9 +116,11 @@ public final class OriginBlacklist {
|
|||||||
this.plugin.kickPlayer(this.getBlacklistedComponent("kick", blacklisted.getArrayString(),
|
this.plugin.kickPlayer(this.getBlacklistedComponent("kick", blacklisted.getArrayString(),
|
||||||
blacklisted.getAltString(), blacklisted.getString(), "not allowed", "not allowed on the server",
|
blacklisted.getAltString(), blacklisted.getString(), "not allowed", "not allowed on the server",
|
||||||
blacklisted_value, blacklisted.getActionString()), event);
|
blacklisted_value, blacklisted.getActionString()), event);
|
||||||
|
this.sendWebhooks(event, blacklisted);
|
||||||
final String name = player.getName();
|
final String name = player.getName();
|
||||||
if (isNonNull(name)) {
|
if (isNonNull(name)) {
|
||||||
this.plugin.log(EnumLogLevel.INFO, "Prevented blacklisted player " + name + " from joining.");
|
this.plugin.log(EnumLogLevel.INFO, "Prevented blacklisted player " + name + " from joining.");
|
||||||
|
this.updateLogFile(event, blacklisted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,11 +144,19 @@ public final class OriginBlacklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isDebugEnabled() {
|
public final boolean isDebugEnabled() {
|
||||||
return this.config.get("debug").getAsBoolean();
|
return this.config.getBoolean("debug");
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isMetricsEnabled() {
|
public final boolean isMetricsEnabled() {
|
||||||
return this.config.get("bStats").getAsBoolean();
|
return this.config.getBoolean("bStats");
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isLogFileEnabled() {
|
||||||
|
return this.config.getBoolean("logFile");
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isBlacklistAPIEnabled() {
|
||||||
|
return this.config.getBoolean("blacklist_http_api");
|
||||||
}
|
}
|
||||||
|
|
||||||
public final OriginBlacklistConfig getConfig() {
|
public final OriginBlacklistConfig getConfig() {
|
||||||
@@ -118,57 +178,176 @@ public final class OriginBlacklist {
|
|||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final EnumBlacklistType testBlacklist(final OPlayer player) {
|
public final void checkForUpdates(final Runnable action1, final Runnable action2) {
|
||||||
|
if (this.config.getBoolean("update_checker.enabled")) {
|
||||||
|
this.plugin.runAsync(() -> {
|
||||||
|
this.updateURL = UpdateChecker.checkForUpdates(PLUGIN_REPO, this.plugin.getPluginVersion(),
|
||||||
|
this.config.getBoolean("update_checker.allow_snapshots"));
|
||||||
|
if (isNonNull((this.updateURL))) {
|
||||||
|
action1.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
action2.run();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
action2.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void updatePlugin(final Runnable action1, final Runnable action2) {
|
||||||
|
try {
|
||||||
|
final URL url = new URL(this.updateURL);
|
||||||
|
final Path jar = this.jarFile;
|
||||||
|
final Path bak = jar.resolveSibling(jar.getFileName().toString() + ".bak");
|
||||||
|
final Path upd = jar
|
||||||
|
.resolveSibling(Paths.get(URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8)).getFileName());
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.copy(jar, bak, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("GET");
|
||||||
|
conn.setConnectTimeout(15000);
|
||||||
|
conn.setReadTimeout(15000);
|
||||||
|
conn.setRequestProperty("User-Agent", OriginBlacklist.getUserAgent());
|
||||||
|
conn.connect();
|
||||||
|
try (final InputStream in = conn.getInputStream()) {
|
||||||
|
Files.copy(in, upd, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} finally {
|
||||||
|
conn.disconnect();
|
||||||
|
}
|
||||||
|
Files.delete(jar);
|
||||||
|
Files.delete(bak);
|
||||||
|
this.jarFile = upd;
|
||||||
|
action1.run();
|
||||||
|
return;
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
Files.move(bak, jar, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
action2.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void updatePlugin() {
|
||||||
|
this.updatePlugin(() -> {
|
||||||
|
}, () -> {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public final EnumBlacklistType testBlacklist(final OPlayer player) {
|
||||||
final String name = player.getName();
|
final String name = player.getName();
|
||||||
final String addr = player.getAddr();
|
final String addr = player.getAddr();
|
||||||
final String origin = player.getOrigin();
|
final String origin = player.getOrigin();
|
||||||
final String brand = player.getBrand();
|
final String brand = player.getBrand();
|
||||||
|
|
||||||
|
final boolean whitelist = this.config.getBoolean("blacklist_to_whitelist");
|
||||||
|
EnumBlacklistType type = EnumBlacklistType.NONE;
|
||||||
|
|
||||||
if (isNonNull(origin)) {
|
if (isNonNull(origin)) {
|
||||||
for (final Json5Element element : this.config.get("blacklist.origins").getAsJson5Array()) {
|
if (whitelist && !type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.ORIGIN;
|
||||||
|
for (final Json5Element element : this.config.getArray("blacklist.origins").getAsJson5Array()) {
|
||||||
if (origin.matches(element.getAsString())) {
|
if (origin.matches(element.getAsString())) {
|
||||||
return EnumBlacklistType.ORIGIN;
|
if (whitelist)
|
||||||
|
type = EnumBlacklistType.NONE;
|
||||||
|
else if (!type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.ORIGIN;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (this.config.getBoolean("block_undefined_origin")) {
|
||||||
|
return whitelist ? EnumBlacklistType.NONE : EnumBlacklistType.ORIGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNonNull(brand)) {
|
if (isNonNull(brand)) {
|
||||||
for (final Json5Element element : this.config.get("blacklist.brands").getAsJson5Array()) {
|
if (whitelist && !type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.BRAND;
|
||||||
|
for (final Json5Element element : this.config.getArray("blacklist.brands")) {
|
||||||
if (brand.matches(element.getAsString())) {
|
if (brand.matches(element.getAsString())) {
|
||||||
return EnumBlacklistType.BRAND;
|
if (whitelist)
|
||||||
|
type = EnumBlacklistType.NONE;
|
||||||
|
else if (!type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.BRAND;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNonNull(name)) {
|
if (isNonNull(name)) {
|
||||||
for (final Json5Element element : this.config.get("blacklist.player_names").getAsJson5Array()) {
|
if (whitelist && !type.isBlacklisted())
|
||||||
this.plugin.log(EnumLogLevel.DEBUG, element.getAsString());
|
type = EnumBlacklistType.NAME;
|
||||||
|
for (final Json5Element element : this.config.getArray("blacklist.player_names")) {
|
||||||
if (name.matches(element.getAsString())) {
|
if (name.matches(element.getAsString())) {
|
||||||
return EnumBlacklistType.NAME;
|
if (whitelist)
|
||||||
|
type = EnumBlacklistType.NONE;
|
||||||
|
else if (!type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.NAME;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNonNull(addr)) {
|
if (isNonNull(addr)) {
|
||||||
for (final Json5Element element : this.config.get("blacklist.ip_addresses").getAsJson5Array()) {
|
if (whitelist && !type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.ADDR;
|
||||||
|
for (final Json5Element element : this.config.getArray("blacklist.ip_addresses")) {
|
||||||
try {
|
try {
|
||||||
if ((new IPAddressString(element.getAsString()).toAddress())
|
if ((new IPAddressString(element.getAsString()).toAddress())
|
||||||
.contains((new IPAddressString(addr)).toAddress())) {
|
.contains((new IPAddressString(addr)).toAddress())) {
|
||||||
return EnumBlacklistType.ADDR;
|
if (whitelist)
|
||||||
|
type = EnumBlacklistType.NONE;
|
||||||
|
else if (!type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.ADDR;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (final AddressStringException exception) {
|
} catch (final AddressStringException exception) {
|
||||||
exception.printStackTrace();
|
if (this.isDebugEnabled())
|
||||||
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EnumBlacklistType.NONE;
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getBlacklistShare() {
|
||||||
|
try {
|
||||||
|
final Json5Object obj = new Json5Object();
|
||||||
|
obj.addProperty("plugin_version", this.plugin.getPluginVersion().getVersion());
|
||||||
|
obj.addProperty("git_commit", COMMIT_L);
|
||||||
|
obj.addProperty("blacklist_to_whitelist", this.config.getBoolean("blacklist_to_whitelist"));
|
||||||
|
obj.addProperty("block_undefined_origin", this.config.getBoolean("block_undefined_origin"));
|
||||||
|
final Json5Object bObj = new Json5Object();
|
||||||
|
final String[] types = new String[] { "origins", "brands", "player_names", "ip_addresses" };
|
||||||
|
for (final String type : types) {
|
||||||
|
bObj.add(type, this.config.getArray("blacklist." + type));
|
||||||
|
}
|
||||||
|
obj.add("blacklist", bObj);
|
||||||
|
return this.json5.serialize(obj);
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getDataDir() {
|
||||||
|
return "plugins/" + plugin.getPluginId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final IEaglerXServerAPI getEaglerAPI() {
|
||||||
|
return this.plugin.getEaglerAPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Component getBlacklistedComponent(final String type, final String id, final String blockType,
|
private final Component getBlacklistedComponent(final String type, final String id, final String blockType,
|
||||||
final String blockTypeAlt, final String notAllowed, final String notAllowedAlt, final String blockValue,
|
final String blockTypeAlt, final String notAllowed, final String notAllowedAlt, final String blockValue,
|
||||||
final String action) {
|
final String action) {
|
||||||
final Json5Array arr = this.config.get("messages." + type).getAsJson5Array();
|
final Json5Array arr = this.config.getArray("messages." + type);
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
@@ -176,7 +355,7 @@ public final class OriginBlacklist {
|
|||||||
sb.append(arr.get(i).getAsString());
|
sb.append(arr.get(i).getAsString());
|
||||||
}
|
}
|
||||||
final String str = sb.toString()
|
final String str = sb.toString()
|
||||||
.replaceAll("%action%", this.config.get("messages.actions." + action).getAsString())
|
.replaceAll("%action%", this.config.getString("messages.actions." + action))
|
||||||
.replaceAll("%block_type%", blockType)
|
.replaceAll("%block_type%", blockType)
|
||||||
.replaceAll("%block_type%", blockType)
|
.replaceAll("%block_type%", blockType)
|
||||||
.replaceAll("%not_allowed%", notAllowed)
|
.replaceAll("%not_allowed%", notAllowed)
|
||||||
@@ -185,14 +364,124 @@ public final class OriginBlacklist {
|
|||||||
return MiniMessage.miniMessage().deserialize(str);
|
return MiniMessage.miniMessage().deserialize(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void checkForUpdate() {
|
private final void sendWebhooks(final OriginBlacklistLoginEvent event, final EnumBlacklistType type) {
|
||||||
(new Thread(() -> {
|
if (this.config.getBoolean("discord.enabled")) {
|
||||||
this.updateAvailable = UpdateChecker.checkForUpdate(PLUGIN_REPO, this.plugin.getPluginVersion(),
|
final OPlayer player = event.getPlayer();
|
||||||
this.config.get("update_checker.allow_snapshots").getAsBoolean());
|
final EnumConnectionType connType = event.getConnectionType();
|
||||||
if (this.updateAvailable) {
|
/* final String userAgent;
|
||||||
this.plugin.log(EnumLogLevel.INFO, "Update Available! Download at https://github.com/" + PLUGIN_REPO + ".git");
|
if (connType == EnumConnectionType.EAGLER) {
|
||||||
|
final IEaglerLoginConnection loginConn = event.getEaglerEvent().getLoginConnection();
|
||||||
|
userAgent = loginConn.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT);
|
||||||
|
} else {
|
||||||
|
userAgent = UNKNOWN_STR;
|
||||||
|
} */
|
||||||
|
final byte[] payload = String.format(
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"content": "Blocked a blacklisted %s from joining",
|
||||||
|
"embeds": [
|
||||||
|
{
|
||||||
|
"title": "-------- Player Information --------",
|
||||||
|
"description": "**→ Name:** %s\\n**→ Origin:** %s\\n**→ Brand:** %s\\n**→ IP Address:** %s\\n**→ Protocol Version:** %s\\n**→ Host:** %s\\n**→ Rewind:** %s\\n**→ Player Type:** %s",
|
||||||
|
"color": 15801922,
|
||||||
|
"fields": [],
|
||||||
|
"footer": {
|
||||||
|
"text": "%s v%s",
|
||||||
|
"icon_url": "https://raw.githubusercontent.com/%s/refs/heads/main/img/icon.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"type": 1,
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"type": 2,
|
||||||
|
"style": 5,
|
||||||
|
"label": "Get the Plugin",
|
||||||
|
"url": "https://github.com/%s",
|
||||||
|
"emoji": {
|
||||||
|
"name": "🌐"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""",
|
||||||
|
type.getAltString(),
|
||||||
|
player.getName().replaceAll("_", "\\_"),
|
||||||
|
player.getOrigin(),
|
||||||
|
player.getBrand(),
|
||||||
|
this.config.getBoolean("discord.send_ips") ? player.getAddr() : CENSORED_STR,
|
||||||
|
player.getPVN(),
|
||||||
|
player.getVHost(),
|
||||||
|
// userAgent,
|
||||||
|
player.isRewind() ? "YES" : "NO",
|
||||||
|
connType.toString(),
|
||||||
|
BuildInfo.get("plugin_name"),
|
||||||
|
this.plugin.getPluginVersion() + " • " + COMMIT_S,
|
||||||
|
PLUGIN_REPO,
|
||||||
|
PLUGIN_REPO).getBytes();
|
||||||
|
final Json5Array arr = this.config.get("discord.webhook_urls").getAsJson5Array();
|
||||||
|
for (final Json5Element element : arr) {
|
||||||
|
this.plugin.runAsync(() -> {
|
||||||
|
try {
|
||||||
|
final URL url = new URL(element.getAsString());
|
||||||
|
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("POST");
|
||||||
|
conn.setRequestProperty("Content-Type", "application/json");
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
conn.setConnectTimeout(5000);
|
||||||
|
conn.setReadTimeout(5000);
|
||||||
|
conn.connect();
|
||||||
|
final OutputStream os = conn.getOutputStream();
|
||||||
|
os.write(payload);
|
||||||
|
os.close();
|
||||||
|
|
||||||
|
final int code = conn.getResponseCode();
|
||||||
|
if (code < 200 || code >= 300) {
|
||||||
|
this.plugin.log(EnumLogLevel.WARN, "Webhook failed (HTTP " + code + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.disconnect();
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})).run();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void checkForUpdates() {
|
||||||
|
this.checkForUpdates(() -> {
|
||||||
|
if (!this.config.getBoolean("update_checker.auto_update")) {
|
||||||
|
this.plugin.log(EnumLogLevel.INFO, "An update is available! Download it at " + this.updateURL);
|
||||||
|
} else {
|
||||||
|
this.updatePlugin();
|
||||||
|
}
|
||||||
|
}, () -> {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void updateLogFile(final OriginBlacklistLoginEvent event, final EnumBlacklistType type) {
|
||||||
|
if (this.isLogFileEnabled()) {
|
||||||
|
final OPlayer player = event.getPlayer();
|
||||||
|
final String txt = Instant.now() + " - [player=" + player.getName() + "," + "blacklist_reason=" + type.toString() + "]";
|
||||||
|
final Path dir = Paths.get(this.getDataDir());
|
||||||
|
try {
|
||||||
|
Files.createDirectories(dir);
|
||||||
|
Files.writeString(
|
||||||
|
dir.resolve("blacklist.log"),
|
||||||
|
txt + "\n",
|
||||||
|
StandardOpenOption.CREATE,
|
||||||
|
StandardOpenOption.WRITE,
|
||||||
|
StandardOpenOption.APPEND
|
||||||
|
);
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String getComponentString(final Component comp) {
|
public static final String getComponentString(final Component comp) {
|
||||||
@@ -207,6 +496,10 @@ public final class OriginBlacklist {
|
|||||||
return "data:image/png;base64," + Base64.getEncoder().encodeToString(bytes);
|
return "data:image/png;base64," + Base64.getEncoder().encodeToString(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String getUserAgent() {
|
||||||
|
return BuildInfo.get("plugin_name") + "/" + BuildInfo.get("plugin_vers") + "+" + BuildInfo.get("git_cm_hash");
|
||||||
|
}
|
||||||
|
|
||||||
public static final boolean isNonNull(final String str) {
|
public static final boolean isNonNull(final String str) {
|
||||||
return str != null && !str.isEmpty() && !str.isBlank() && !str.equals("null");
|
return str != null && !str.isEmpty() && !str.isBlank() && !str.equals("null");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
package xyz.webmc.originblacklist.base.command;
|
package xyz.webmc.originblacklist.base.command;
|
||||||
|
|
||||||
|
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||||
|
|
||||||
public interface CommandContext {
|
public interface CommandContext {
|
||||||
String getPlayerName();
|
public OriginBlacklist getPlugin();
|
||||||
void reply(final String message);
|
|
||||||
boolean hasPermission(final String permission);
|
public String getPlayerName();
|
||||||
String[] getArgs();
|
|
||||||
|
public void reply(final String message);
|
||||||
|
|
||||||
|
public boolean hasPermission(final String permission);
|
||||||
|
|
||||||
|
public String[] getArgs();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package xyz.webmc.originblacklist.base.command;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ICommand {
|
public interface ICommand {
|
||||||
static final String NO_PERMISSION = "<red>You don't have permission to use this command.</red>";
|
public static final String NO_PERMISSION = "<red>You don't have permission to use this command.</red>";
|
||||||
boolean execute(final CommandContext ctx);
|
|
||||||
List<String> suggest(final CommandContext ctx);
|
public boolean execute(final CommandContext ctx);
|
||||||
void usage(final CommandContext ctx);
|
|
||||||
|
public List<String> suggest(final CommandContext ctx);
|
||||||
|
|
||||||
|
public void usage(final CommandContext ctx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package xyz.webmc.originblacklist.base.command;
|
package xyz.webmc.originblacklist.base.command;
|
||||||
|
|
||||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||||
|
import xyz.webmc.originblacklist.base.config.OriginBlacklistConfig;
|
||||||
|
import xyz.webmc.originblacklist.base.enums.EnumBlacklistType;
|
||||||
|
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.marhali.json5.Json5Array;
|
||||||
import de.marhali.json5.Json5Element;
|
import de.marhali.json5.Json5Element;
|
||||||
|
import de.marhali.json5.Json5Primitive;
|
||||||
|
|
||||||
public class OriginBlacklistCommand implements ICommand {
|
public class OriginBlacklistCommand implements ICommand {
|
||||||
private final OriginBlacklist plugin;
|
private final OriginBlacklist plugin;
|
||||||
@@ -18,31 +23,105 @@ public class OriginBlacklistCommand implements ICommand {
|
|||||||
final String[] args = ctx.getArgs();
|
final String[] args = ctx.getArgs();
|
||||||
if (ctx.hasPermission("originblacklist.command")) {
|
if (ctx.hasPermission("originblacklist.command")) {
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
final String command = args[0].toLowerCase();
|
final OriginBlacklistConfig config = this.plugin.getConfig();
|
||||||
if ("reload".equals(command)) {
|
final String command = args[0];
|
||||||
|
final String argA = args.length > 1 ? args[1] : null;
|
||||||
|
;
|
||||||
|
final String argB = args.length > 2 ? args[2] : null;
|
||||||
|
final boolean add = "add".equalsIgnoreCase(command);
|
||||||
|
final boolean remove = "remove".equalsIgnoreCase(command);
|
||||||
|
if ("reload".equalsIgnoreCase(command)) {
|
||||||
if (ctx.hasPermission("originblacklist.command.reload")) {
|
if (ctx.hasPermission("originblacklist.command.reload")) {
|
||||||
this.plugin.getConfig().reloadConfig();
|
config.reloadConfig();
|
||||||
|
this.plugin.handleReload();
|
||||||
ctx.reply("<green>Configuration Reloaded</green>");
|
ctx.reply("<green>Configuration Reloaded</green>");
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(NO_PERMISSION);
|
ctx.reply(NO_PERMISSION);
|
||||||
}
|
}
|
||||||
} else if ("list".equals(command)) {
|
} else if ("update".equalsIgnoreCase(command)) {
|
||||||
if (ctx.hasPermission("originblacklist.command.reload")) {
|
if (ctx.hasPermission("originblacklist.command.update")) {
|
||||||
|
ctx.reply("<aqua>Checking for updates...</aqua>");
|
||||||
|
this.plugin.checkForUpdates(() -> {
|
||||||
|
ctx.reply("<yellow>Updating plugin...</yellow>");
|
||||||
|
this.plugin.updatePlugin(() -> {
|
||||||
|
ctx.reply("<green>Successfully updated plugin.</green>");
|
||||||
|
}, () -> {
|
||||||
|
ctx.reply("<red>Failed to update plugin.</red>");
|
||||||
|
});
|
||||||
|
}, () -> {
|
||||||
|
ctx.reply("<green>Plugin is up to date.</green>");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ctx.reply(NO_PERMISSION);
|
||||||
|
}
|
||||||
|
} else if ((add || remove) && OriginBlacklist.isNonNull(argB)) {
|
||||||
|
if ((add && ctx.hasPermission("originblacklist.command.add"))
|
||||||
|
|| (remove && ctx.hasPermission("originblacklist.command.add"))) {
|
||||||
|
final String arrName;
|
||||||
|
if ("origin".equalsIgnoreCase(argA)) {
|
||||||
|
arrName = "origins";
|
||||||
|
} else if ("brand".equalsIgnoreCase(argA)) {
|
||||||
|
arrName = "brands";
|
||||||
|
} else if ("name".equalsIgnoreCase(argA)) {
|
||||||
|
arrName = "player_names";
|
||||||
|
} else if ("ip".equalsIgnoreCase(argA)) {
|
||||||
|
arrName = "ip_addresses";
|
||||||
|
} else {
|
||||||
|
arrName = null;
|
||||||
|
}
|
||||||
|
if (OriginBlacklist.isNonNull(arrName)) {
|
||||||
|
final String arrPath = "blacklist." + arrName;
|
||||||
|
final Json5Array arr = config.getArray(arrPath);
|
||||||
|
if (add) {
|
||||||
|
if (!arr.contains(Json5Primitive.fromString(argB))) {
|
||||||
|
arr.add(argB);
|
||||||
|
config.set(arrPath, arr);
|
||||||
|
ctx.reply("<green>Added " + argB + " to the " + argA + " blacklist</green>");
|
||||||
|
} else {
|
||||||
|
ctx.reply("<red>" + argB + " is already on the " + argA + " blacklist</red>");
|
||||||
|
}
|
||||||
|
} else if (remove) {
|
||||||
|
if (arr.contains(Json5Primitive.fromString(argB))) {
|
||||||
|
arr.remove(Json5Primitive.fromString(argB));
|
||||||
|
config.set(arrPath, arr);
|
||||||
|
ctx.reply("<green>Removed " + argB + " from the " + argA + " blacklist</green>");
|
||||||
|
} else {
|
||||||
|
ctx.reply("<red>" + argB + " not on the " + argA + " blacklist</red>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.usage(ctx);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.reply(NO_PERMISSION);
|
||||||
|
}
|
||||||
|
} else if ("test".equalsIgnoreCase(command) && OriginBlacklist.isNonNull(argA)) {
|
||||||
|
if (ctx.hasPermission("originblacklist.command.test")) {
|
||||||
|
if (this.isBlacklisted(argA)) {
|
||||||
|
ctx.reply("<green>" + argA + " is on the blacklist.</green>");
|
||||||
|
} else {
|
||||||
|
ctx.reply("<red>" + argA + " is not on the blacklist.</red>");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.reply(NO_PERMISSION);
|
||||||
|
}
|
||||||
|
} else if ("list".equalsIgnoreCase(command)) {
|
||||||
|
if (ctx.hasPermission("originblacklist.command.list")) {
|
||||||
ctx.reply("<aqua>Blacklist:</aqua>");
|
ctx.reply("<aqua>Blacklist:</aqua>");
|
||||||
ctx.reply("<gold> - Origins:</gold>");
|
ctx.reply("<gold> - Origins:</gold>");
|
||||||
for (final Json5Element element : this.plugin.getConfig().get("blacklist.origins").getAsJson5Array()) {
|
for (final Json5Element element : config.getArray("blacklist.origins")) {
|
||||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||||
}
|
}
|
||||||
ctx.reply("<gold> - Brands:</gold>");
|
ctx.reply("<gold> - Brands:</gold>");
|
||||||
for (final Json5Element element : this.plugin.getConfig().get("blacklist.brands").getAsJson5Array()) {
|
for (final Json5Element element : config.getArray("blacklist.brands")) {
|
||||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||||
}
|
}
|
||||||
ctx.reply("<gold> - Players:</gold>");
|
ctx.reply("<gold> - Players:</gold>");
|
||||||
for (final Json5Element element : this.plugin.getConfig().get("blacklist.player_names").getAsJson5Array()) {
|
for (final Json5Element element : config.getArray("blacklist.player_names")) {
|
||||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||||
}
|
}
|
||||||
ctx.reply("<gold> - IPs:</gold>");
|
ctx.reply("<gold> - IPs:</gold>");
|
||||||
for (final Json5Element element : this.plugin.getConfig().get("blacklist.ip_addresses").getAsJson5Array()) {
|
for (final Json5Element element : config.getArray("blacklist.ip_addresses")) {
|
||||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -61,16 +140,23 @@ public class OriginBlacklistCommand implements ICommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggest(final CommandContext ctx) {
|
public final List<String> suggest(final CommandContext ctx) {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void usage(CommandContext ctx) {
|
public final void usage(CommandContext ctx) {
|
||||||
ctx.reply("<aqua>Commands:</aqua>");
|
ctx.reply("<aqua>Commands:</aqua>");
|
||||||
ctx.reply("<gray> - /originblacklist reload</gray>");
|
ctx.reply("<gray> - /originblacklist reload</gray>");
|
||||||
//ctx.reply("<gray> - /originblacklist add <brand/origin/name/ip> <value></gray>");
|
ctx.reply("<gray> - /originblacklist update</gray>");
|
||||||
//ctx.reply("<gray> - /originblacklist remove <brand/origin/name/ip> <value></gray>");
|
ctx.reply("<gray> - /originblacklist add <origin/brand/name/ip> <arg></gray>");
|
||||||
|
ctx.reply("<gray> - /originblacklist remove <origin/brand/name/ip> <arg></gray>");
|
||||||
|
ctx.reply("<gray> - /originblacklist test <arg></gray>");
|
||||||
ctx.reply("<gray> - /originblacklist list</gray>");
|
ctx.reply("<gray> - /originblacklist list</gray>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final boolean isBlacklisted(final String str) {
|
||||||
|
final OPlayer player = new OPlayer(null, str, null, str, str, null, -1);
|
||||||
|
return this.plugin.testBlacklist(player) != EnumBlacklistType.NONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package xyz.webmc.originblacklist.base.config;
|
package xyz.webmc.originblacklist.base.config;
|
||||||
|
|
||||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -12,6 +11,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
@@ -22,6 +22,8 @@ import de.marhali.json5.Json5Object;
|
|||||||
import de.marhali.json5.Json5Primitive;
|
import de.marhali.json5.Json5Primitive;
|
||||||
|
|
||||||
public final class OriginBlacklistConfig {
|
public final class OriginBlacklistConfig {
|
||||||
|
private static final Json5Object DEFAULT_CONFIG = getDefaultConfig();
|
||||||
|
|
||||||
private final Json5 json5;
|
private final Json5 json5;
|
||||||
private final File file;
|
private final File file;
|
||||||
private final Path filePath;
|
private final Path filePath;
|
||||||
@@ -31,7 +33,7 @@ public final class OriginBlacklistConfig {
|
|||||||
private byte[] icon;
|
private byte[] icon;
|
||||||
private String icon64;
|
private String icon64;
|
||||||
|
|
||||||
public OriginBlacklistConfig(IOriginBlacklistPlugin plugin) {
|
public OriginBlacklistConfig(final OriginBlacklist plugin) {
|
||||||
this.json5 = Json5.builder(builder -> builder
|
this.json5 = Json5.builder(builder -> builder
|
||||||
.quoteless()
|
.quoteless()
|
||||||
.quoteSingle()
|
.quoteSingle()
|
||||||
@@ -39,10 +41,10 @@ public final class OriginBlacklistConfig {
|
|||||||
.writeComments()
|
.writeComments()
|
||||||
.prettyPrinting()
|
.prettyPrinting()
|
||||||
.build());
|
.build());
|
||||||
final String dir = "plugins/" + plugin.getPluginId();
|
|
||||||
this.file = new File(dir + "/config.json5");
|
this.file = new File(plugin.getDataDir() + "/config.json5");
|
||||||
this.filePath = file.toPath();
|
this.filePath = file.toPath();
|
||||||
this.iconFile = new File(dir + "/blacklisted.png");
|
this.iconFile = new File(plugin.getDataDir() + "/blacklisted.png");
|
||||||
this.iconPath = iconFile.toPath();
|
this.iconPath = iconFile.toPath();
|
||||||
this.loadConfig();
|
this.loadConfig();
|
||||||
}
|
}
|
||||||
@@ -50,19 +52,19 @@ public final class OriginBlacklistConfig {
|
|||||||
private final void loadConfig() {
|
private final void loadConfig() {
|
||||||
try {
|
try {
|
||||||
this.reloadConfigUnsafe();
|
this.reloadConfigUnsafe();
|
||||||
|
this.reloadIconImage();
|
||||||
} catch (final IOException exception) {
|
} catch (final IOException exception) {
|
||||||
throw new RuntimeException("Failed to load config.", exception);
|
throw new RuntimeException("Failed to load config.", exception);
|
||||||
}
|
}
|
||||||
this.reloadIconImage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void reloadConfig() {
|
public final void reloadConfig() {
|
||||||
try {
|
try {
|
||||||
this.reloadConfigUnsafe();
|
this.reloadConfigUnsafe();
|
||||||
|
this.reloadIconImage();
|
||||||
} catch (final IOException exception) {
|
} catch (final IOException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
this.reloadIconImage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void reloadConfigUnsafe() throws IOException {
|
private final void reloadConfigUnsafe() throws IOException {
|
||||||
@@ -71,16 +73,14 @@ public final class OriginBlacklistConfig {
|
|||||||
Json5Element parsed = this.json5.parse(text);
|
Json5Element parsed = this.json5.parse(text);
|
||||||
if (parsed instanceof Json5Object) {
|
if (parsed instanceof Json5Object) {
|
||||||
this.config = (Json5Object) parsed;
|
this.config = (Json5Object) parsed;
|
||||||
if (merge(this.config, getDefaultConfig())) {
|
merge(this.config, DEFAULT_CONFIG);
|
||||||
this.saveConfig();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Config must be an object!");
|
throw new IOException("Config must be an object!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.config = getDefaultConfig();
|
this.config = DEFAULT_CONFIG;
|
||||||
this.saveConfig();
|
|
||||||
}
|
}
|
||||||
|
this.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void reloadIconImage() {
|
private final void reloadIconImage() {
|
||||||
@@ -95,10 +95,10 @@ public final class OriginBlacklistConfig {
|
|||||||
final BufferedImage img = ImageIO.read(iconFile);
|
final BufferedImage img = ImageIO.read(iconFile);
|
||||||
|
|
||||||
if (img.getWidth() == 64 && img.getHeight() == 64) {
|
if (img.getWidth() == 64 && img.getHeight() == 64) {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ImageIO.write(img, "png", baos);
|
ImageIO.write(img, "png", baos);
|
||||||
this.icon64 = OriginBlacklist.getPNGBase64FromBytes(baos.toByteArray());
|
this.icon64 = OriginBlacklist.getPNGBase64FromBytes(baos.toByteArray());
|
||||||
byte[] bytes = new byte[64 * 64 * 4];
|
final byte[] bytes = new byte[64 * 64 * 4];
|
||||||
for (int y = 0; y < 64; y++) {
|
for (int y = 0; y < 64; y++) {
|
||||||
for (int x = 0; x < 64; x++) {
|
for (int x = 0; x < 64; x++) {
|
||||||
int pixel = img.getRGB(x, y);
|
int pixel = img.getRGB(x, y);
|
||||||
@@ -132,7 +132,7 @@ public final class OriginBlacklistConfig {
|
|||||||
|
|
||||||
if (this.config != null && OriginBlacklist.isNonNull(key)) {
|
if (this.config != null && OriginBlacklist.isNonNull(key)) {
|
||||||
element = this.config;
|
element = this.config;
|
||||||
final String[] parts = key.split("\\.");
|
final String[] parts = splitPath(key);
|
||||||
|
|
||||||
for (final String part : parts) {
|
for (final String part : parts) {
|
||||||
if (element instanceof Json5Object) {
|
if (element instanceof Json5Object) {
|
||||||
@@ -155,6 +155,94 @@ public final class OriginBlacklistConfig {
|
|||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean set(final String key, final Json5Element value) {
|
||||||
|
boolean ret = false;
|
||||||
|
|
||||||
|
if (this.config != null && value != null) {
|
||||||
|
final String[] parts = splitPath(key);
|
||||||
|
|
||||||
|
if (parts.length > 0) {
|
||||||
|
Json5Object obj = this.config;
|
||||||
|
|
||||||
|
for (int i = 0; i < parts.length - 1; i++) {
|
||||||
|
final String part = parts[i];
|
||||||
|
final Json5Element cur = obj.has(part) ? obj.get(part) : null;
|
||||||
|
|
||||||
|
if (cur instanceof Json5Object next) {
|
||||||
|
obj = next;
|
||||||
|
} else {
|
||||||
|
final Json5Object next = new Json5Object();
|
||||||
|
obj.add(part, next);
|
||||||
|
obj = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.add(parts[parts.length - 1], value.deepCopy());
|
||||||
|
this.saveConfig();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean remove(final String key) {
|
||||||
|
boolean ret = false;
|
||||||
|
|
||||||
|
if (this.config != null) {
|
||||||
|
final String[] parts = splitPath(key);
|
||||||
|
|
||||||
|
if (parts.length > 0) {
|
||||||
|
Json5Object obj = this.config;
|
||||||
|
Json5Element element = obj;
|
||||||
|
|
||||||
|
for (int i = 0; i < parts.length - 1; i++) {
|
||||||
|
if (element instanceof Json5Object cur && cur.has(parts[i])) {
|
||||||
|
element = cur.get(parts[i]);
|
||||||
|
if (element instanceof Json5Object) {
|
||||||
|
obj = (Json5Object) element;
|
||||||
|
} else {
|
||||||
|
element = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
element = null;
|
||||||
|
}
|
||||||
|
if (element == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element != null && obj.has(parts[parts.length - 1])) {
|
||||||
|
obj.remove(parts[parts.length - 1]);
|
||||||
|
this.saveConfig();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getString(final String key) {
|
||||||
|
return this.get(key).getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean getBoolean(final String key) {
|
||||||
|
return this.get(key).getAsBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int getInteger(final String key) {
|
||||||
|
return this.get(key).getAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Json5Array getArray(final String key) {
|
||||||
|
return this.get(key).getAsJson5Array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Json5Object getObject(final String key) {
|
||||||
|
return this.get(key).getAsJson5Object();
|
||||||
|
}
|
||||||
|
|
||||||
public final byte[] getIconBytes() {
|
public final byte[] getIconBytes() {
|
||||||
return this.icon;
|
return this.icon;
|
||||||
}
|
}
|
||||||
@@ -166,7 +254,7 @@ public final class OriginBlacklistConfig {
|
|||||||
private static final Json5Object getDefaultConfig() {
|
private static final Json5Object getDefaultConfig() {
|
||||||
final Json5Object obj = new Json5Object();
|
final Json5Object obj = new Json5Object();
|
||||||
addJSONObj(obj, "debug", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(obj, "debug", Json5Primitive.fromBoolean(false), null);
|
||||||
final Json5Object mobj = new Json5Object();
|
final Json5Object mObj = new Json5Object();
|
||||||
final Json5Array kick = new Json5Array();
|
final Json5Array kick = new Json5Array();
|
||||||
kick.add("<red>This %block_type% is %not_allowed_alt%!</red>");
|
kick.add("<red>This %block_type% is %not_allowed_alt%!</red>");
|
||||||
kick.add("<dark_gray>»</dark_gray> <gray>%blocked_value%</gray> <dark_gray>«</dark_gray>");
|
kick.add("<dark_gray>»</dark_gray> <gray>%blocked_value%</gray> <dark_gray>«</dark_gray>");
|
||||||
@@ -175,18 +263,18 @@ public final class OriginBlacklistConfig {
|
|||||||
kick.add("");
|
kick.add("");
|
||||||
kick.add("<aqua>Think this is a mistake? Join our discord:</aqua>");
|
kick.add("<aqua>Think this is a mistake? Join our discord:</aqua>");
|
||||||
kick.add("<blue>discord.gg/changethisintheconfig</blue>");
|
kick.add("<blue>discord.gg/changethisintheconfig</blue>");
|
||||||
addJSONObj(mobj, "kick", kick, null);
|
addJSONObj(mObj, "kick", kick, null);
|
||||||
final Json5Array motd = new Json5Array();
|
final Json5Array motd = new Json5Array();
|
||||||
motd.add("<red>This %block_type% is %not_allowed%!</red>");
|
motd.add("<red>This %block_type% is %not_allowed%!</red>");
|
||||||
motd.add("<dark_gray>»</dark_gray> <gray>%blocked_value%</gray>");
|
motd.add("<dark_gray>»</dark_gray> <gray>%blocked_value%</gray>");
|
||||||
addJSONObj(mobj, "motd", motd, null);
|
addJSONObj(mObj, "motd", motd, null);
|
||||||
final Json5Object actions = new Json5Object();
|
final Json5Object actions = new Json5Object();
|
||||||
actions.add("generic", Json5Primitive.fromString("<gold>Please switch to a different %block_type%.</gold>"));
|
actions.add("generic", Json5Primitive.fromString("<gold>Please switch to a different %block_type%.</gold>"));
|
||||||
actions.add("player_name", Json5Primitive.fromString("<gold>Please change your %block_type%.</gold>"));
|
actions.add("player_name", Json5Primitive.fromString("<gold>Please change your %block_type%.</gold>"));
|
||||||
actions.add("ip_address", Json5Primitive.fromString("<gold>Please contact staff for assistance.</gold>"));
|
actions.add("ip_address", Json5Primitive.fromString("<gold>Please contact staff for assistance.</gold>"));
|
||||||
addJSONObj(mobj, "actions", actions, null);
|
addJSONObj(mObj, "actions", actions, null);
|
||||||
addJSONObj(obj, "messages", mobj, null);
|
addJSONObj(obj, "messages", mObj, null);
|
||||||
final Json5Object bobj = new Json5Object();
|
final Json5Object bObj = new Json5Object();
|
||||||
final Json5Array origins = new Json5Array();
|
final Json5Array origins = new Json5Array();
|
||||||
origins.add(".*eaglerhackedclients\\.vercel\\.app.*");
|
origins.add(".*eaglerhackedclients\\.vercel\\.app.*");
|
||||||
origins.add(".*eaglerhacks\\.github\\.io.*");
|
origins.add(".*eaglerhacks\\.github\\.io.*");
|
||||||
@@ -198,52 +286,192 @@ public final class OriginBlacklistConfig {
|
|||||||
origins.add(".*uec\\.vercel\\.app.*");
|
origins.add(".*uec\\.vercel\\.app.*");
|
||||||
origins.add(".*valux-game\\.github\\.io.*");
|
origins.add(".*valux-game\\.github\\.io.*");
|
||||||
origins.add(".*project516\\.dev.*");
|
origins.add(".*project516\\.dev.*");
|
||||||
addJSONObj(bobj, "origins", origins, null);
|
addJSONObj(bObj, "origins", origins, null);
|
||||||
final Json5Array brands = new Json5Array();
|
final Json5Array brands = new Json5Array();
|
||||||
brands.add(".*dragonx.*");
|
brands.add(".*dragonx.*");
|
||||||
brands.add(".*piclient.*");
|
brands.add(".*piclient.*");
|
||||||
brands.add(".*justin.*");
|
brands.add(".*justin.*");
|
||||||
brands.add(".*wurstx.*");
|
brands.add(".*wurstx.*");
|
||||||
brands.add(".*moonlight.*");
|
brands.add(".*moonlight.*");
|
||||||
addJSONObj(bobj, "brands", brands, null);
|
addJSONObj(bObj, "brands", brands, null);
|
||||||
final Json5Array players = new Json5Array();
|
final Json5Array players = new Json5Array();
|
||||||
players.add("Admin");
|
players.add("Admin");
|
||||||
addJSONObj(bobj, "player_names", players, null);
|
addJSONObj(bObj, "player_names", players, null);
|
||||||
final Json5Array ips = new Json5Array();
|
final Json5Array ips = new Json5Array();
|
||||||
ips.add("192.0.2.0/24");
|
ips.add("192.0.2.0/24");
|
||||||
addJSONObj(bobj, "ip_addresses", ips, null);
|
addJSONObj(bObj, "ip_addresses", ips, null);
|
||||||
addJSONObj(obj, "blacklist", bobj, null);
|
addJSONObj(obj, "blacklist", bObj, null);
|
||||||
final Json5Object dobj = new Json5Object();
|
final Json5Object dObj = new Json5Object();
|
||||||
addJSONObj(dobj, "enabled", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(dObj, "enabled", Json5Primitive.fromBoolean(false), null);
|
||||||
addJSONObj(dobj, "webhook_urls", new Json5Array(), null);
|
addJSONObj(dObj, "webhook_urls", new Json5Array(), null);
|
||||||
addJSONObj(obj, "discord", dobj, null);
|
addJSONObj(dObj, "send_ips", Json5Primitive.fromBoolean(true), null);
|
||||||
final Json5Object uobj = new Json5Object();
|
addJSONObj(obj, "discord", dObj, null);
|
||||||
addJSONObj(uobj, "enabled", Json5Primitive.fromBoolean(true), null);
|
final Json5Object uObj = new Json5Object();
|
||||||
addJSONObj(uobj, "allow_snapshots", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(uObj, "enabled", Json5Primitive.fromBoolean(true), null);
|
||||||
addJSONObj(uobj, "auto_update", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(uObj, "allow_snapshots", Json5Primitive.fromBoolean(false), null);
|
||||||
addJSONObj(obj, "update_checker", uobj, null);
|
addJSONObj(uObj, "check_timer", Json5Primitive.fromNumber(3600), null);
|
||||||
|
addJSONObj(uObj, "auto_update", Json5Primitive.fromBoolean(true), null);
|
||||||
|
addJSONObj(obj, "update_checker", uObj, null);
|
||||||
|
addJSONObj(obj, "blacklist_http_api", Json5Primitive.fromBoolean(false), null);
|
||||||
|
addJSONObj(obj, "blacklist_to_whitelist", Json5Primitive.fromBoolean(false), null);
|
||||||
|
addJSONObj(obj, "block_undefined_origin", Json5Primitive.fromBoolean(false), null);
|
||||||
addJSONObj(obj, "bStats", Json5Primitive.fromBoolean(true), null);
|
addJSONObj(obj, "bStats", Json5Primitive.fromBoolean(true), null);
|
||||||
|
addJSONObj(obj, "logFile", Json5Primitive.fromBoolean(true), null);
|
||||||
|
addJSONObj(obj, "config_version", Json5Primitive.fromNumber(1), "DO NOT CHANGE");
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final boolean merge(final Json5Object a, final Json5Object b) {
|
private static final boolean merge(final Json5Object aObj, final Json5Object bObj) {
|
||||||
|
final Json5Object ret = new Json5Object();
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
for (final String key : bObj.keySet()) {
|
||||||
for (String key : b.keySet()) {
|
final Json5Element dv = bObj.get(key);
|
||||||
Json5Element element = b.get(key);
|
if (aObj.has(key)) {
|
||||||
if (!a.has(key)) {
|
final Json5Element v = aObj.get(key);
|
||||||
a.add(key, element.deepCopy());
|
if (dv instanceof Json5Object) {
|
||||||
changed = true;
|
if (v instanceof Json5Object) {
|
||||||
} else {
|
final boolean c = merge((Json5Object) v, (Json5Object) dv);
|
||||||
final Json5Element _element = a.get(key);
|
ret.add(key, (Json5Object) v);
|
||||||
if (_element instanceof Json5Object objA && element instanceof Json5Object objB) {
|
if (c) {
|
||||||
if (merge(objA, objB)) {
|
changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
} else if (dv instanceof Json5Array) {
|
||||||
|
if (v instanceof Json5Array) {
|
||||||
|
final Json5Array vArr = (Json5Array) v;
|
||||||
|
final Json5Array dArr = (Json5Array) dv;
|
||||||
|
if (dArr.size() == 0) {
|
||||||
|
ret.add(key, vArr.deepCopy());
|
||||||
|
} else {
|
||||||
|
final Json5Element d0 = dArr.get(0);
|
||||||
|
if (d0 instanceof Json5Primitive && ((Json5Primitive) d0).isString()) {
|
||||||
|
final Json5Array out = new Json5Array();
|
||||||
|
for (final Json5Element e : vArr) {
|
||||||
|
if (e instanceof Json5Primitive && ((Json5Primitive) e).isString()) {
|
||||||
|
out.add(e.deepCopy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (out.size() > 0) {
|
||||||
|
if (out.size() != vArr.size()) {
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
ret.add(key, out);
|
||||||
|
} else {
|
||||||
|
ret.add(key, dArr.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
boolean a = true;
|
||||||
|
for (final Json5Element e : vArr) {
|
||||||
|
if (e == null) {
|
||||||
|
a = false;
|
||||||
|
} else if (d0 instanceof Json5Object) {
|
||||||
|
if (!(e instanceof Json5Object)) {
|
||||||
|
a = false;
|
||||||
|
}
|
||||||
|
} else if (d0 instanceof Json5Array) {
|
||||||
|
if (!(e instanceof Json5Array)) {
|
||||||
|
a = false;
|
||||||
|
}
|
||||||
|
} else if (d0 instanceof Json5Primitive && e instanceof Json5Primitive) {
|
||||||
|
final Json5Primitive bp = (Json5Primitive) d0;
|
||||||
|
final Json5Primitive ap = (Json5Primitive) e;
|
||||||
|
if (bp.isBoolean()) {
|
||||||
|
if (!ap.isBoolean()) {
|
||||||
|
a = false;
|
||||||
|
}
|
||||||
|
} else if (bp.isNumber()) {
|
||||||
|
if (!ap.isNumber()) {
|
||||||
|
a = false;
|
||||||
|
}
|
||||||
|
} else if (bp.isString()) {
|
||||||
|
if (!ap.isString()) {
|
||||||
|
a = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
a = false;
|
||||||
|
}
|
||||||
|
if (!a) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (a) {
|
||||||
|
ret.add(key, vArr.deepCopy());
|
||||||
|
} else {
|
||||||
|
ret.add(key, dArr.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else if (dv instanceof Json5Primitive) {
|
||||||
|
if (v instanceof Json5Primitive) {
|
||||||
|
final Json5Primitive dp = (Json5Primitive) dv;
|
||||||
|
final Json5Primitive vp = (Json5Primitive) v;
|
||||||
|
if (dp.isBoolean()) {
|
||||||
|
if (vp.isBoolean()) {
|
||||||
|
ret.add(key, vp.deepCopy());
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else if (dp.isNumber()) {
|
||||||
|
if (vp.isNumber()) {
|
||||||
|
ret.add(key, vp.deepCopy());
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else if (dp.isString()) {
|
||||||
|
if (vp.isString()) {
|
||||||
|
ret.add(key, vp.deepCopy());
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (final String key : aObj.keySet()) {
|
||||||
|
if (!bObj.has(key)) {
|
||||||
|
ret.add(key, aObj.get(key).deepCopy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (final String key : aObj.keySet()) {
|
||||||
|
if (!bObj.has(key)) {
|
||||||
|
ret.add(key, aObj.get(key).deepCopy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (final String k : new ArrayList<>(aObj.keySet())) {
|
||||||
|
aObj.remove(k);
|
||||||
|
}
|
||||||
|
for (final String k : ret.keySet()) {
|
||||||
|
aObj.add(k, ret.get(k));
|
||||||
|
}
|
||||||
|
for (final String key : ret.keySet()) {
|
||||||
|
aObj.add(key, ret.get(key));
|
||||||
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,4 +482,16 @@ public final class OriginBlacklistConfig {
|
|||||||
}
|
}
|
||||||
obj.add(key, value);
|
obj.add(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String[] splitPath(final String key) {
|
||||||
|
final String[] ret;
|
||||||
|
|
||||||
|
if (OriginBlacklist.isNonNull(key)) {
|
||||||
|
ret = key.split("\\.");
|
||||||
|
} else {
|
||||||
|
ret = new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public enum EnumBlacklistType {
|
|||||||
this.str = str;
|
this.str = str;
|
||||||
this.alt = alt;
|
this.alt = alt;
|
||||||
this.arr = arr;
|
this.arr = arr;
|
||||||
this.act = OriginBlacklist.isNonNull(act) ? act : OriginBlacklist.GENERIC_STR;
|
this.act = OriginBlacklist.isNonNull(act) ? act : OriginBlacklist.GENERIC_STR.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getString() {
|
public final String getString() {
|
||||||
@@ -36,4 +36,8 @@ public enum EnumBlacklistType {
|
|||||||
public final String getActionString() {
|
public final String getActionString() {
|
||||||
return this.act;
|
return this.act;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean isBlacklisted() {
|
||||||
|
return this != NONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import xyz.webmc.originblacklist.base.util.OPlayer;
|
|||||||
|
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.event.IBaseServerEvent;
|
import net.lax1dude.eaglercraft.backend.server.api.event.IBaseServerEvent;
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes" })
|
||||||
public abstract class OriginBlacklistEvent {
|
public abstract class OriginBlacklistEvent {
|
||||||
private final EnumConnectionType connectionType;
|
private final EnumConnectionType connectionType;
|
||||||
private final IBaseServerEvent eaglerEvent;
|
private final IBaseServerEvent eaglerEvent;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import xyz.webmc.originblacklist.base.util.OPlayer;
|
|||||||
|
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftLoginEvent;
|
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftLoginEvent;
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes" })
|
||||||
public final class OriginBlacklistLoginEvent extends OriginBlacklistEvent {
|
public final class OriginBlacklistLoginEvent extends OriginBlacklistEvent {
|
||||||
public OriginBlacklistLoginEvent(final IEaglercraftLoginEvent eaglerEvent, final Object javaEvent,
|
public OriginBlacklistLoginEvent(final IEaglercraftLoginEvent eaglerEvent, final Object javaEvent,
|
||||||
final EnumConnectionType connectionType, final OPlayer player) {
|
final EnumConnectionType connectionType, final OPlayer player) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import xyz.webmc.originblacklist.base.util.OPlayer;
|
|||||||
|
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftMOTDEvent;
|
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftMOTDEvent;
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes" })
|
||||||
public final class OriginBlacklistMOTDEvent extends OriginBlacklistEvent {
|
public final class OriginBlacklistMOTDEvent extends OriginBlacklistEvent {
|
||||||
public OriginBlacklistMOTDEvent(final IEaglercraftMOTDEvent eaglerEvent, final Object javaEvent,
|
public OriginBlacklistMOTDEvent(final IEaglercraftMOTDEvent eaglerEvent, final Object javaEvent,
|
||||||
final EnumConnectionType connectionType, final OPlayer player) {
|
final EnumConnectionType connectionType, final OPlayer player) {
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package xyz.webmc.originblacklist.base.http;
|
||||||
|
|
||||||
|
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.webserver.IRequestContext;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.webserver.IRequestHandler;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.webserver.RouteDesc;
|
||||||
|
|
||||||
|
public class OriginBlacklistRequestHandler implements IRequestHandler {
|
||||||
|
private static final RouteDesc route = RouteDesc.create("/originblacklist/v2/");
|
||||||
|
private final OriginBlacklist plugin;
|
||||||
|
|
||||||
|
public OriginBlacklistRequestHandler(final OriginBlacklist plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void handleRequest(final IRequestContext ctx) {
|
||||||
|
final String path = ctx.getPath();
|
||||||
|
if (route.getPattern().equals(path)) {
|
||||||
|
final byte[] bytes = this.plugin.getBlacklistShare().getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
ctx.addResponseHeader("Content-Type", "application/json; charset=utf-8");
|
||||||
|
ctx.setResponseCode(200);
|
||||||
|
ctx.setResponseBody(bytes);
|
||||||
|
} else {
|
||||||
|
ctx.getServer().get404Handler().handleRequest(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void register(final OriginBlacklist plugin) {
|
||||||
|
plugin.getEaglerAPI().getWebServer().registerRoute(plugin, route, new OriginBlacklistRequestHandler(plugin));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void unRegister(final OriginBlacklist plugin) {
|
||||||
|
plugin.getEaglerAPI().getWebServer().unregisterRoute(plugin, route);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package xyz.webmc.originblacklist.base.util;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public final class BuildInfo {
|
||||||
|
private static final Properties properties;
|
||||||
|
|
||||||
|
public static final String get(final String key) {
|
||||||
|
return properties.getProperty(key).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
properties = new Properties();
|
||||||
|
try (final InputStream in = BuildInfo.class.getClassLoader().getResourceAsStream("build.properties")) {
|
||||||
|
properties.load(in);
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package xyz.webmc.originblacklist.base.util;
|
||||||
|
|
||||||
|
public final class EventPriority {
|
||||||
|
public static final int EAGLER_MOTD_EVENT = 100;
|
||||||
|
}
|
||||||
@@ -4,19 +4,34 @@ import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
|||||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||||
import org.semver4j.Semver;
|
import org.semver4j.Semver;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
@SuppressWarnings({ "rawtypes" })
|
||||||
|
|
||||||
public interface IOriginBlacklistPlugin {
|
public interface IOriginBlacklistPlugin {
|
||||||
public String getPluginId();
|
public String getPluginId();
|
||||||
|
|
||||||
public Semver getPluginVersion();
|
public Semver getPluginVersion();
|
||||||
|
|
||||||
|
public Path getPluginJarPath();
|
||||||
|
|
||||||
|
public IEaglerXServerAPI getEaglerAPI();
|
||||||
|
|
||||||
public void log(final EnumLogLevel level, final String txt);
|
public void log(final EnumLogLevel level, final String txt);
|
||||||
|
|
||||||
public void kickPlayer(final Component txt, final OriginBlacklistLoginEvent event);
|
public void kickPlayer(final Component txt, final OriginBlacklistLoginEvent event);
|
||||||
|
|
||||||
public void setMOTD(final Component txt, final OriginBlacklistMOTDEvent event);
|
public void setMOTD(final Component txt, final OriginBlacklistMOTDEvent event);
|
||||||
|
|
||||||
public String parsePlaceholders(final OPlayer player, final String str);
|
public String parsePlaceholders(final OPlayer player, final String str);
|
||||||
|
|
||||||
public void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit);
|
public void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit);
|
||||||
|
|
||||||
|
public void runAsync(final Runnable task);
|
||||||
|
|
||||||
public void shutdown();
|
public void shutdown();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,28 +16,40 @@ public final class OPlayer {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
private final String brand;
|
private final String brand;
|
||||||
|
private final String vhost;
|
||||||
|
private final boolean rewind;
|
||||||
|
private final int pvn;
|
||||||
|
|
||||||
public OPlayer(final IEaglerConnection conn, final String name, final UUID uuid, final String addr,
|
public OPlayer(final IEaglerConnection conn, final String name, final UUID uuid, final String addr,
|
||||||
final String brand) {
|
final String brand, final String vhost, final int pvn) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
this.origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
this.origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||||
this.addr = formatSocketAddress(conn.getSocketAddress());
|
this.addr = formatSocketAddress(conn.getSocketAddress());
|
||||||
|
this.vhost = conn.isWebSocketSecure() ? "wss://" : "ws://" + conn.getWebSocketHost();
|
||||||
if (conn instanceof IEaglerLoginConnection) {
|
if (conn instanceof IEaglerLoginConnection) {
|
||||||
this.brand = ((IEaglerLoginConnection) conn).getEaglerBrandString();
|
final IEaglerLoginConnection loginConn = (IEaglerLoginConnection) conn;
|
||||||
|
this.brand = loginConn.getEaglerBrandString();
|
||||||
|
this.rewind = loginConn.isEaglerXRewindPlayer();
|
||||||
|
this.pvn = this.rewind ? loginConn.getRewindProtocolVersion() : loginConn.getMinecraftProtocol();
|
||||||
} else {
|
} else {
|
||||||
this.brand = OriginBlacklist.UNKNOWN_STR;
|
this.brand = OriginBlacklist.UNKNOWN_STR;
|
||||||
|
this.rewind = false;
|
||||||
|
this.pvn = pvn;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.origin = OriginBlacklist.UNKNOWN_STR;
|
this.origin = OriginBlacklist.UNKNOWN_STR;
|
||||||
this.addr = formatIPAddress(addr);
|
this.addr = formatIPAddress(addr);
|
||||||
this.brand = brand;
|
this.brand = brand;
|
||||||
|
this.vhost = vhost;
|
||||||
|
this.rewind = false;
|
||||||
|
this.pvn = pvn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public OPlayer(final IEaglerConnection conn, final String name, final UUID uuid) {
|
public OPlayer(final IEaglerConnection conn, final String name, final UUID uuid) {
|
||||||
this(conn, name, uuid, null, null);
|
this(conn, name, uuid, null, null, null, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getOrigin() {
|
public final String getOrigin() {
|
||||||
@@ -60,26 +72,73 @@ public final class OPlayer {
|
|||||||
return this.brand;
|
return this.brand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final String getVHost() {
|
||||||
|
return this.vhost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isRewind() {
|
||||||
|
return this.rewind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int getPVN() {
|
||||||
|
return this.pvn;
|
||||||
|
}
|
||||||
|
|
||||||
private static final String formatIPAddress(String addr) {
|
private static final String formatIPAddress(String addr) {
|
||||||
if (addr.startsWith("/")) {
|
if (OriginBlacklist.isNonNull(addr)) {
|
||||||
addr = addr.substring(1);
|
if (addr.startsWith("/")) {
|
||||||
}
|
addr = addr.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
int i = addr.lastIndexOf('/');
|
int i = addr.lastIndexOf('/');
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
addr = addr.substring(i + 1);
|
addr = addr.substring(i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addr.startsWith("[")) {
|
if (addr.startsWith("[")) {
|
||||||
i = addr.indexOf(']');
|
i = addr.indexOf(']');
|
||||||
if (i != -1)
|
if (i != -1) {
|
||||||
return addr.substring(1, i);
|
addr = addr.substring(1, i);
|
||||||
return addr.substring(1);
|
} else {
|
||||||
}
|
addr = addr.substring(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
i = addr.lastIndexOf(':');
|
||||||
|
if (i != -1) {
|
||||||
|
String a = addr.substring(0, i);
|
||||||
|
String p = addr.substring(i + 1);
|
||||||
|
|
||||||
i = addr.lastIndexOf(':');
|
boolean port = !p.isEmpty();
|
||||||
if (i != -1) {
|
for (int j = 0; j < p.length() && port; j++) {
|
||||||
addr = addr.substring(0, i);
|
char c = p.charAt(j);
|
||||||
|
port = (c >= '0' && c <= '9');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (port) {
|
||||||
|
if (a.indexOf('.') != -1) {
|
||||||
|
addr = a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int c = 0;
|
||||||
|
boolean hex = true;
|
||||||
|
for (int j = 0; j < addr.length(); j++) {
|
||||||
|
char ch = addr.charAt(j);
|
||||||
|
if (ch == ':') {
|
||||||
|
c++;
|
||||||
|
} else if (!((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'))) {
|
||||||
|
hex = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hex && c == 6 && addr.indexOf("::") == -1) {
|
||||||
|
addr = addr + "::";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addr = OriginBlacklist.UNKNOWN_STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return addr;
|
return addr;
|
||||||
|
|||||||
@@ -1,47 +1,101 @@
|
|||||||
package xyz.webmc.originblacklist.base.util;
|
package xyz.webmc.originblacklist.base.util;
|
||||||
|
|
||||||
|
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.semver4j.Semver;
|
|
||||||
|
|
||||||
import de.marhali.json5.Json5;
|
import de.marhali.json5.Json5;
|
||||||
import de.marhali.json5.Json5Array;
|
import de.marhali.json5.Json5Array;
|
||||||
import de.marhali.json5.Json5Element;
|
import de.marhali.json5.Json5Element;
|
||||||
import de.marhali.json5.Json5Object;
|
import de.marhali.json5.Json5Object;
|
||||||
|
import org.semver4j.Semver;
|
||||||
|
import org.semver4j.Semver.VersionDiff;
|
||||||
|
|
||||||
public class UpdateChecker {
|
public final class UpdateChecker {
|
||||||
private static final Json5 json5 = Json5.builder(builder -> builder.build());
|
private static final Json5 json5 = Json5.builder(builder -> builder.build());
|
||||||
|
|
||||||
public static final boolean checkForUpdate(final String repo, final Semver currentVersion, final boolean allowPreRelease) {
|
public static final String checkForUpdates(final String repo, final Semver currentVersion,
|
||||||
|
final boolean allowSnapshots) {
|
||||||
try {
|
try {
|
||||||
final URL url = new URL("https://api.github.com/repos/" + repo + "/releases");
|
final URL url = new URL("https://api.github.com/repos/" + repo + "/releases");
|
||||||
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
conn.setRequestMethod("GET");
|
conn.setRequestMethod("GET");
|
||||||
conn.setConnectTimeout(5000);
|
conn.setConnectTimeout(5000);
|
||||||
conn.setReadTimeout(5000);
|
conn.setReadTimeout(5000);
|
||||||
|
conn.setRequestProperty("User-Agent", OriginBlacklist.getUserAgent());
|
||||||
|
conn.setRequestProperty("Accept", "application/vnd.github+json");
|
||||||
|
conn.connect();
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
Json5Element element = json5.parse(reader);
|
String ret = null;
|
||||||
|
Json5Element element = json5.parse(reader);
|
||||||
|
reader.close();
|
||||||
|
|
||||||
|
Json5Object rel = null;
|
||||||
|
Json5Object snap = null;
|
||||||
|
|
||||||
if (element instanceof Json5Array) {
|
if (element instanceof Json5Array) {
|
||||||
final Json5Array arr = element.getAsJson5Array();
|
final Json5Array arr = element.getAsJson5Array();
|
||||||
if (arr.size() > 0) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
element = arr.get(0);
|
element = arr.get(i);
|
||||||
if (element instanceof Json5Object) {
|
if (element instanceof Json5Object) {
|
||||||
final Json5Object obj = element.getAsJson5Object();
|
final Json5Object obj = element.getAsJson5Object();
|
||||||
final String tag = obj.get("tag_name").getAsString();
|
if (!obj.has("published_at")) {
|
||||||
final Semver ver = new Semver(tag.substring(1));
|
continue;
|
||||||
if (ver.isGreaterThan(currentVersion)) {
|
}
|
||||||
return true;
|
final boolean pre = obj.get("prerelease").getAsBoolean();
|
||||||
|
if (!pre) {
|
||||||
|
if (rel == null
|
||||||
|
|| obj.get("published_at").getAsString().compareTo(rel.get("published_at").getAsString()) > 0) {
|
||||||
|
rel = obj;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (snap == null
|
||||||
|
|| obj.get("published_at").getAsString().compareTo(snap.get("published_at").getAsString()) > 0) {
|
||||||
|
snap = obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
final Json5Object obj = i == 0 ? rel : snap;
|
||||||
|
if (obj == null || (i == 1 && !allowSnapshots)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final String tag = obj.get("tag_name").getAsString();
|
||||||
|
final Semver ver = new Semver(tag.startsWith("v") ? tag.substring(1) : tag);
|
||||||
|
String comm;
|
||||||
|
try {
|
||||||
|
comm = ver.getBuild().get(0).trim();
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
comm = "";
|
||||||
|
}
|
||||||
|
if (ver.isGreaterThan(currentVersion) || (allowSnapshots && currentVersion.diff(ver) == VersionDiff.BUILD
|
||||||
|
&& OriginBlacklist.isNonNull(comm) && !BuildInfo.get("git_cm_hash").startsWith(comm))) {
|
||||||
|
element = obj.get("assets");
|
||||||
|
if (element instanceof Json5Array) {
|
||||||
|
final Json5Array aArr = element.getAsJson5Array();
|
||||||
|
if (aArr.size() > 0) {
|
||||||
|
element = aArr.get(0);
|
||||||
|
if (element instanceof Json5Object) {
|
||||||
|
ret = element.getAsJson5Object().get("browser_download_url").getAsString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
conn.disconnect();
|
||||||
|
return ret;
|
||||||
} catch (final Throwable t) {
|
} catch (final Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,20 +5,26 @@ import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
|||||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
|
||||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||||
|
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||||
import xyz.webmc.originblacklist.bukkit.command.OriginBlacklistCommandBukkit;
|
import xyz.webmc.originblacklist.bukkit.command.OriginBlacklistCommandBukkit;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.semver4j.Semver;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.bukkit.EaglerXServerAPI;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftLoginEvent;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftMOTDEvent;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bstats.charts.AdvancedPie;
|
import org.bstats.charts.AdvancedPie;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -32,18 +38,13 @@ import org.bukkit.event.server.ServerListPingEvent;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.CachedServerIcon;
|
import org.bukkit.util.CachedServerIcon;
|
||||||
|
import org.semver4j.Semver;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
@SuppressWarnings({ "rawtypes" })
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.bukkit.EaglerXServerAPI;
|
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftLoginEvent;
|
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftMOTDEvent;
|
|
||||||
|
|
||||||
public final class OriginBlacklistBukkit extends JavaPlugin implements Listener, IOriginBlacklistPlugin {
|
public final class OriginBlacklistBukkit extends JavaPlugin implements Listener, IOriginBlacklistPlugin {
|
||||||
private boolean papiPlaceholdersEnabled;
|
private boolean papiPlaceholdersEnabled;
|
||||||
private Object papi;
|
private Object papi;
|
||||||
private OriginBlacklist blacklist;
|
private OriginBlacklist blacklist;
|
||||||
private IEaglerXServerAPI eaglerAPI;
|
|
||||||
private Metrics metrics;
|
private Metrics metrics;
|
||||||
|
|
||||||
private CachedServerIcon iconCache;
|
private CachedServerIcon iconCache;
|
||||||
@@ -71,17 +72,16 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
this.papi = null;
|
this.papi = null;
|
||||||
}
|
}
|
||||||
this.blacklist = new OriginBlacklist(this);
|
this.blacklist = new OriginBlacklist(this);
|
||||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
|
||||||
this.getCommand("originblacklist").setExecutor(new OriginBlacklistCommandBukkit(this.blacklist));
|
this.getCommand("originblacklist").setExecutor(new OriginBlacklistCommandBukkit(this.blacklist));
|
||||||
this.getServer().getPluginManager().registerEvents(this, this);
|
this.getServer().getPluginManager().registerEvents(this, this);
|
||||||
this.log(EnumLogLevel.INFO, "Initialized Plugin");
|
this.blacklist.init();
|
||||||
if (this.blacklist.isMetricsEnabled()) {
|
if (this.blacklist.isMetricsEnabled()) {
|
||||||
this.metrics = new Metrics(this, OriginBlacklist.BSTATS_ID);
|
this.metrics = new Metrics(this, OriginBlacklist.BSTATS_ID);
|
||||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||||
final Map<String, Integer> playerMap = new HashMap<>();
|
final Map<String, Integer> playerMap = new HashMap<>();
|
||||||
|
|
||||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||||
final boolean eagler = eaglerAPI.isEaglerPlayerByUUID(player.getUniqueId());
|
final boolean eagler = this.getEaglerAPI().isEaglerPlayerByUUID(player.getUniqueId());
|
||||||
final String key = eagler ? "Eagler" : "Java";
|
final String key = eagler ? "Eagler" : "Java";
|
||||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||||
}
|
}
|
||||||
@@ -91,6 +91,11 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
this.blacklist.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
||||||
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
||||||
@@ -105,15 +110,14 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public final void onJavaLogin(final AsyncPlayerPreLoginEvent event) {
|
public final void onJavaLogin(final AsyncPlayerPreLoginEvent event) {
|
||||||
final OPlayer player = new OPlayer(null, event.getName(), event.getUniqueId(),
|
final OPlayer player = new OPlayer(null, event.getName(), event.getUniqueId(), event.getAddress().toString(),
|
||||||
event.getAddress() != null ? event.getAddress().toString() : null, null);
|
OriginBlacklist.UNKNOWN_STR, OriginBlacklist.UNKNOWN_STR, -1);
|
||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public final void onJavaMOTD(final ServerListPingEvent event) {
|
public final void onJavaMOTD(final ServerListPingEvent event) {
|
||||||
final OPlayer player = new OPlayer(null, null, null,
|
final OPlayer player = new OPlayer(null, null, null, event.getAddress().toString(), null, null, -1);
|
||||||
event.getAddress() != null ? event.getAddress().toString() : null, null);
|
|
||||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +131,16 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
return new Semver(this.getDescription().getVersion());
|
return new Semver(this.getDescription().getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final Path getPluginJarPath() {
|
||||||
|
return Paths.get(this.getFile().getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final IEaglerXServerAPI getEaglerAPI() {
|
||||||
|
return EaglerXServerAPI.instance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void log(final EnumLogLevel level, final String txt) {
|
public final void log(final EnumLogLevel level, final String txt) {
|
||||||
if (level == EnumLogLevel.WARN) {
|
if (level == EnumLogLevel.WARN) {
|
||||||
@@ -224,7 +238,12 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
||||||
long ms = unit.toMillis((long) period);
|
long ms = unit.toMillis((long) period);
|
||||||
long ticks = Math.max(1L, ms / 50L);
|
long ticks = Math.max(1L, ms / 50L);
|
||||||
Bukkit.getScheduler().runTaskTimer(this, task, ticks, ticks);
|
Bukkit.getScheduler().runTaskTimer(this, task, 0, ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void runAsync(final Runnable task) {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(this, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,32 +5,39 @@ import xyz.webmc.originblacklist.base.command.CommandContext;
|
|||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class BKTCommandContext implements CommandContext {
|
public final class BKTCommandContext implements CommandContext {
|
||||||
|
private final OriginBlacklist plugin;
|
||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
private final String[] args;
|
private final String[] args;
|
||||||
|
|
||||||
public BKTCommandContext(final CommandSender sender, final String[] args) {
|
public BKTCommandContext(final OriginBlacklist plugin, final CommandSender sender, final String[] args) {
|
||||||
|
this.plugin = plugin;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerName() {
|
public final OriginBlacklist getPlugin() {
|
||||||
|
return this.plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getPlayerName() {
|
||||||
return this.sender.getName();
|
return this.sender.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reply(final String message) {
|
public final void reply(final String message) {
|
||||||
this.sender.sendMessage(OriginBlacklist.getLegacyFromMiniMessage(message));
|
this.sender.sendMessage(OriginBlacklist.getLegacyFromMiniMessage(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(final String permission) {
|
public final boolean hasPermission(final String permission) {
|
||||||
return this.sender.hasPermission(permission);
|
return this.sender.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getArgs() {
|
public final String[] getArgs() {
|
||||||
return this.args;
|
return this.args;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,18 +9,22 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
|
|
||||||
public class OriginBlacklistCommandBukkit extends OriginBlacklistCommand implements TabExecutor {
|
public final class OriginBlacklistCommandBukkit extends OriginBlacklistCommand implements TabExecutor {
|
||||||
|
private final OriginBlacklist plugin;
|
||||||
|
|
||||||
public OriginBlacklistCommandBukkit(OriginBlacklist plugin) {
|
public OriginBlacklistCommandBukkit(OriginBlacklist plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
return super.execute(new BKTCommandContext(sender, args));
|
return super.execute(new BKTCommandContext(this.plugin, sender, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label,
|
||||||
return super.suggest(new BKTCommandContext(sender, args));
|
final String[] args) {
|
||||||
|
return super.suggest(new BKTCommandContext(this.plugin, sender, args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,13 @@ import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
|||||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||||
import xyz.webmc.originblacklist.bungee.command.OriginBlacklistCommandBungee;
|
import xyz.webmc.originblacklist.bungee.command.OriginBlacklistCommandBungee;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.bstats.bungeecord.Metrics;
|
|
||||||
import org.bstats.charts.AdvancedPie;
|
|
||||||
import org.semver4j.Semver;
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.bungee.EaglerXServerAPI;
|
import net.lax1dude.eaglercraft.backend.server.api.bungee.EaglerXServerAPI;
|
||||||
@@ -25,22 +24,25 @@ import net.lax1dude.eaglercraft.backend.server.api.bungee.event.EaglercraftLogin
|
|||||||
import net.lax1dude.eaglercraft.backend.server.api.bungee.event.EaglercraftMOTDEvent;
|
import net.lax1dude.eaglercraft.backend.server.api.bungee.event.EaglercraftMOTDEvent;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.ServerPing;
|
import net.md_5.bungee.api.ServerPing;
|
||||||
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||||
import net.md_5.bungee.api.event.PreLoginEvent;
|
import net.md_5.bungee.api.event.PreLoginEvent;
|
||||||
|
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
import net.md_5.bungee.event.EventPriority;
|
import net.md_5.bungee.event.EventPriority;
|
||||||
|
import org.bstats.bungeecord.Metrics;
|
||||||
|
import org.bstats.charts.AdvancedPie;
|
||||||
|
import org.semver4j.Semver;
|
||||||
|
|
||||||
@SuppressWarnings({ "deprecation" })
|
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||||
public final class OriginBlacklistBungee extends Plugin implements Listener, IOriginBlacklistPlugin {
|
public final class OriginBlacklistBungee extends Plugin implements Listener, IOriginBlacklistPlugin {
|
||||||
private ProxyServer proxy;
|
private ProxyServer proxy;
|
||||||
private boolean papiPlaceholdersEnabled;
|
private boolean papiPlaceholdersEnabled;
|
||||||
private Object papi;
|
private Object papi;
|
||||||
private OriginBlacklist blacklist;
|
private OriginBlacklist blacklist;
|
||||||
private IEaglerXServerAPI eaglerAPI;
|
|
||||||
private Metrics metrics;
|
private Metrics metrics;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -68,17 +70,17 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
this.papi = null;
|
this.papi = null;
|
||||||
}
|
}
|
||||||
this.blacklist = new OriginBlacklist(this);
|
this.blacklist = new OriginBlacklist(this);
|
||||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
this.getProxy().getPluginManager().registerCommand(this,
|
||||||
this.getProxy().getPluginManager().registerCommand(this, new OriginBlacklistCommandBungee(this, this.blacklist, "originblacklist"));
|
new OriginBlacklistCommandBungee(this, this.blacklist, "originblacklist"));
|
||||||
this.getProxy().getPluginManager().registerListener(this, this);
|
this.getProxy().getPluginManager().registerListener(this, this);
|
||||||
this.log(EnumLogLevel.INFO, "Initialized Plugin");
|
this.blacklist.init();
|
||||||
if (this.blacklist.isMetricsEnabled()) {
|
if (this.blacklist.isMetricsEnabled()) {
|
||||||
this.metrics = new Metrics(this, OriginBlacklist.BSTATS_ID);
|
this.metrics = new Metrics(this, OriginBlacklist.BSTATS_ID);
|
||||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||||
final Map<String, Integer> playerMap = new HashMap<>();
|
final Map<String, Integer> playerMap = new HashMap<>();
|
||||||
|
|
||||||
for (final ProxiedPlayer player : this.proxy.getPlayers()) {
|
for (final ProxiedPlayer player : this.proxy.getPlayers()) {
|
||||||
final boolean eagler = eaglerAPI.isEaglerPlayerByUUID(player.getUniqueId());
|
final boolean eagler = this.getEaglerAPI().isEaglerPlayerByUUID(player.getUniqueId());
|
||||||
final String key = eagler ? "Eagler" : "Java";
|
final String key = eagler ? "Eagler" : "Java";
|
||||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||||
}
|
}
|
||||||
@@ -88,13 +90,18 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
this.blacklist.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
||||||
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = xyz.webmc.originblacklist.base.util.EventPriority.EAGLER_MOTD_EVENT)
|
||||||
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
||||||
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
||||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||||
@@ -102,21 +109,30 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public final void onJavaLogin(final PostLoginEvent event) {
|
public final void onJavaLogin(final PostLoginEvent event) {
|
||||||
|
final PendingConnection conn = event.getPlayer().getPendingConnection();
|
||||||
|
final InetSocketAddress vhost = conn.getVirtualHost();
|
||||||
final ProxiedPlayer aPlayer = event.getPlayer();
|
final ProxiedPlayer aPlayer = event.getPlayer();
|
||||||
final OPlayer bPlayer = new OPlayer(null, aPlayer.getName(), aPlayer.getUniqueId(),
|
final OPlayer bPlayer = new OPlayer(null, aPlayer.getName(), aPlayer.getUniqueId(),
|
||||||
aPlayer.getAddress().toString(), aPlayer.getClientBrand());
|
aPlayer.getAddress().toString(), aPlayer.getClientBrand(), vhost.getHostString() + vhost.getPort(),
|
||||||
|
conn.getVersion());
|
||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public final void onJavaHandshake(final PreLoginEvent event) {
|
public final void onJavaHandshake(final PreLoginEvent event) {
|
||||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getAddress().toString(), null);
|
final PendingConnection conn = event.getConnection();
|
||||||
|
final InetSocketAddress vhost = conn.getVirtualHost();
|
||||||
|
final OPlayer player = new OPlayer(null, null, null, conn.getAddress().toString(), OriginBlacklist.UNKNOWN_STR,
|
||||||
|
vhost.getHostString() + vhost.getPort(), conn.getVersion());
|
||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getAddress().toString(), null);
|
final PendingConnection conn = event.getConnection();
|
||||||
|
final InetSocketAddress vhost = conn.getVirtualHost();
|
||||||
|
final OPlayer player = new OPlayer(null, null, null, conn.getAddress().toString(), null,
|
||||||
|
vhost.getHostString() + vhost.getPort(), -1);
|
||||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +146,16 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
return new Semver(this.getDescription().getVersion());
|
return new Semver(this.getDescription().getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final Path getPluginJarPath() {
|
||||||
|
return Paths.get(this.getFile().getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final IEaglerXServerAPI getEaglerAPI() {
|
||||||
|
return EaglerXServerAPI.instance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void log(final EnumLogLevel level, final String txt) {
|
public final void log(final EnumLogLevel level, final String txt) {
|
||||||
if (level == EnumLogLevel.WARN) {
|
if (level == EnumLogLevel.WARN) {
|
||||||
@@ -189,7 +215,12 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
||||||
this.proxy.getScheduler().schedule(this, task, period, period, unit);
|
this.proxy.getScheduler().schedule(this, task, 0, period, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void runAsync(final Runnable task) {
|
||||||
|
this.proxy.getScheduler().runAsync(this, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,32 +6,39 @@ import xyz.webmc.originblacklist.base.command.CommandContext;
|
|||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
|
||||||
public class BNGCommandContext implements CommandContext {
|
public final class BNGCommandContext implements CommandContext {
|
||||||
|
private final OriginBlacklist plugin;
|
||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
private final String[] args;
|
private final String[] args;
|
||||||
|
|
||||||
public BNGCommandContext(final CommandSender sender, final String[] args) {
|
public BNGCommandContext(final OriginBlacklist plugin, final CommandSender sender, final String[] args) {
|
||||||
|
this.plugin = plugin;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerName() {
|
public final OriginBlacklist getPlugin() {
|
||||||
|
return this.plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getPlayerName() {
|
||||||
return this.sender.getName();
|
return this.sender.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reply(final String message) {
|
public final void reply(final String message) {
|
||||||
this.sender.sendMessage(TextComponent.fromLegacy(OriginBlacklist.getLegacyFromMiniMessage(message)));
|
this.sender.sendMessage(TextComponent.fromLegacy(OriginBlacklist.getLegacyFromMiniMessage(message)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(final String permission) {
|
public final boolean hasPermission(final String permission) {
|
||||||
return this.sender.hasPermission(permission);
|
return this.sender.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getArgs() {
|
public final String[] getArgs() {
|
||||||
return this.args;
|
return this.args;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,21 +10,24 @@ import net.md_5.bungee.api.CommandSender;
|
|||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||||
|
|
||||||
public class OriginBlacklistCommandBungee extends Command implements TabExecutor {
|
public final class OriginBlacklistCommandBungee extends Command implements TabExecutor {
|
||||||
private final OriginBlacklistCommand cmd;
|
private final OriginBlacklistCommand cmd;
|
||||||
|
private final OriginBlacklist blacklist;
|
||||||
|
|
||||||
public OriginBlacklistCommandBungee(final OriginBlacklistBungee plugin, final OriginBlacklist blacklist, final String command) {
|
public OriginBlacklistCommandBungee(final OriginBlacklistBungee plugin, final OriginBlacklist blacklist,
|
||||||
|
final String command) {
|
||||||
super(command);
|
super(command);
|
||||||
this.cmd = new OriginBlacklistCommand(blacklist);
|
this.cmd = new OriginBlacklistCommand(blacklist);
|
||||||
|
this.blacklist = blacklist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final String[] args) {
|
public final void execute(final CommandSender sender, final String[] args) {
|
||||||
this.cmd.execute(new BNGCommandContext(sender, args));
|
this.cmd.execute(new BNGCommandContext(this.blacklist, sender, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(final CommandSender sender, final String[] args) {
|
public final List<String> onTabComplete(final CommandSender sender, final String[] args) {
|
||||||
return this.cmd.suggest(new BNGCommandContext(sender, args));
|
return this.cmd.suggest(new BNGCommandContext(this.blacklist, sender, args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,22 +5,20 @@ import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
|||||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||||
|
import xyz.webmc.originblacklist.base.util.EventPriority;
|
||||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||||
import xyz.webmc.originblacklist.velocity.command.OriginBlacklistCommandVelocity;
|
import xyz.webmc.originblacklist.velocity.command.OriginBlacklistCommandVelocity;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.bstats.charts.AdvancedPie;
|
|
||||||
import org.bstats.velocity.Metrics;
|
|
||||||
import org.bstats.velocity.Metrics.Factory;
|
|
||||||
import org.semver4j.Semver;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
@@ -28,20 +26,26 @@ import com.velocitypowered.api.event.connection.PreLoginEvent;
|
|||||||
import com.velocitypowered.api.event.player.PlayerClientBrandEvent;
|
import com.velocitypowered.api.event.player.PlayerClientBrandEvent;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||||
import com.velocitypowered.api.plugin.PluginContainer;
|
import com.velocitypowered.api.plugin.PluginContainer;
|
||||||
|
import com.velocitypowered.api.proxy.InboundConnection;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||||
import com.velocitypowered.api.util.Favicon;
|
import com.velocitypowered.api.util.Favicon;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftMOTDEvent;
|
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.EaglerXServerAPI;
|
import net.lax1dude.eaglercraft.backend.server.api.velocity.EaglerXServerAPI;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftLoginEvent;
|
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftLoginEvent;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftMOTDEvent;
|
||||||
|
import org.bstats.charts.AdvancedPie;
|
||||||
|
import org.bstats.velocity.Metrics;
|
||||||
|
import org.bstats.velocity.Metrics.Factory;
|
||||||
|
import org.semver4j.Semver;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
@SuppressWarnings({ "deprecation", "unchecked", "rawtypes" })
|
||||||
public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||||
private final PluginContainer plugin;
|
private final PluginContainer plugin;
|
||||||
private final Factory metricsFactory;
|
private final Factory metricsFactory;
|
||||||
@@ -51,7 +55,6 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
private boolean papiPlaceholdersEnabled;
|
private boolean papiPlaceholdersEnabled;
|
||||||
private Object papi;
|
private Object papi;
|
||||||
private OriginBlacklist blacklist;
|
private OriginBlacklist blacklist;
|
||||||
private IEaglerXServerAPI eaglerAPI;
|
|
||||||
private Metrics metrics;
|
private Metrics metrics;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -64,7 +67,7 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public final void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
this.proxy.getPluginManager().getPlugin("eaglerxserver").ifPresentOrElse(plugin -> {
|
this.proxy.getPluginManager().getPlugin("eaglerxserver").ifPresentOrElse(plugin -> {
|
||||||
final Semver version = new Semver(plugin.getDescription().getVersion().orElse("1.0.0"));
|
final Semver version = new Semver(plugin.getDescription().getVersion().orElse("1.0.0"));
|
||||||
if (version.isLowerThan(OriginBlacklist.REQUIRED_API_VER)) {
|
if (version.isLowerThan(OriginBlacklist.REQUIRED_API_VER)) {
|
||||||
@@ -86,16 +89,15 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
this.papi = null;
|
this.papi = null;
|
||||||
}
|
}
|
||||||
this.blacklist = new OriginBlacklist(this);
|
this.blacklist = new OriginBlacklist(this);
|
||||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
|
||||||
this.proxy.getCommandManager().register("originblacklist", new OriginBlacklistCommandVelocity(this.blacklist));
|
this.proxy.getCommandManager().register("originblacklist", new OriginBlacklistCommandVelocity(this.blacklist));
|
||||||
this.log(EnumLogLevel.INFO, "Initialized Plugin");
|
this.blacklist.init();
|
||||||
if (this.blacklist.isMetricsEnabled()) {
|
if (this.blacklist.isMetricsEnabled()) {
|
||||||
this.metrics = this.metricsFactory.make(this, OriginBlacklist.BSTATS_ID);
|
this.metrics = this.metricsFactory.make(this, OriginBlacklist.BSTATS_ID);
|
||||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||||
final Map<String, Integer> playerMap = new HashMap<>();
|
final Map<String, Integer> playerMap = new HashMap<>();
|
||||||
|
|
||||||
for (final Player player : this.proxy.getAllPlayers()) {
|
for (final Player player : this.proxy.getAllPlayers()) {
|
||||||
final boolean eagler = eaglerAPI.isEaglerPlayerByUUID(player.getUniqueId());
|
final boolean eagler = this.getEaglerAPI().isEaglerPlayerByUUID(player.getUniqueId());
|
||||||
final String key = eagler ? "Eagler" : "Java";
|
final String key = eagler ? "Eagler" : "Java";
|
||||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||||
}
|
}
|
||||||
@@ -105,13 +107,18 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public final void onProxyShutdown(final ProxyShutdownEvent e) {
|
||||||
|
this.blacklist.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.FIRST)
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
||||||
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LAST)
|
@Subscribe(priority = EventPriority.EAGLER_MOTD_EVENT, order = PostOrder.LAST)
|
||||||
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
||||||
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
||||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||||
@@ -119,23 +126,31 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
|
|
||||||
@Subscribe(order = PostOrder.FIRST)
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
public final void onJavaLogin(final PreLoginEvent event) {
|
public final void onJavaLogin(final PreLoginEvent event) {
|
||||||
|
final InboundConnection conn = event.getConnection();
|
||||||
|
final InetSocketAddress vhost = conn.getVirtualHost().orElseThrow();
|
||||||
final OPlayer player = new OPlayer(null, event.getUsername(), event.getUniqueId(),
|
final OPlayer player = new OPlayer(null, event.getUsername(), event.getUniqueId(),
|
||||||
event.getConnection().getRemoteAddress().toString(), null);
|
conn.getRemoteAddress().toString(), OriginBlacklist.UNKNOWN_STR, vhost.getHostString() + vhost.getPort(),
|
||||||
|
conn.getProtocolVersion().getProtocol());
|
||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.FIRST)
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
public final void onJavaHandshake(final PlayerClientBrandEvent event) {
|
public final void onJavaHandshake(final PlayerClientBrandEvent event) {
|
||||||
final Player aPlayer = (Player) event.getPlayer();
|
final InetSocketAddress vhost = event.getPlayer().getVirtualHost().orElseThrow();
|
||||||
|
final Player aPlayer = event.getPlayer();
|
||||||
final OPlayer bPlayer = new OPlayer(null, aPlayer.getUsername(), aPlayer.getUniqueId(),
|
final OPlayer bPlayer = new OPlayer(null, aPlayer.getUsername(), aPlayer.getUniqueId(),
|
||||||
aPlayer.getRemoteAddress().getAddress().toString(), event.getBrand());
|
aPlayer.getRemoteAddress().getAddress().toString(), event.getBrand(), vhost.getHostString() + vhost.getPort(),
|
||||||
|
event.getPlayer().getProtocolVersion().getProtocol());
|
||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LAST)
|
@Subscribe(order = PostOrder.LAST)
|
||||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getRemoteAddress().getHostString(),
|
final InboundConnection conn = event.getConnection();
|
||||||
null);
|
final InetSocketAddress vhost = conn.getVirtualHost().orElseThrow();
|
||||||
|
final OPlayer player = new OPlayer(null, null, null, conn.getRemoteAddress().getHostString(),
|
||||||
|
vhost.getHostString() + vhost.getPort(),
|
||||||
|
null, -1);
|
||||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +164,20 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
return new Semver(this.plugin.getDescription().getVersion().get());
|
return new Semver(this.plugin.getDescription().getVersion().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final Path getPluginJarPath() {
|
||||||
|
try {
|
||||||
|
return Paths.get(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).toAbsolutePath();
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
throw new RuntimeException("Unable to determine plugin JAR path");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final IEaglerXServerAPI getEaglerAPI() {
|
||||||
|
return EaglerXServerAPI.instance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void log(final EnumLogLevel level, final String txt) {
|
public final void log(final EnumLogLevel level, final String txt) {
|
||||||
if (level == EnumLogLevel.WARN) {
|
if (level == EnumLogLevel.WARN) {
|
||||||
@@ -157,7 +186,7 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
this.logger.error(txt);
|
this.logger.error(txt);
|
||||||
} else if (level == EnumLogLevel.DEBUG) {
|
} else if (level == EnumLogLevel.DEBUG) {
|
||||||
if (this.blacklist.isDebugEnabled()) {
|
if (this.blacklist.isDebugEnabled()) {
|
||||||
this.logger.debug(txt);
|
this.logger.info(txt);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.logger.info(txt);
|
this.logger.info(txt);
|
||||||
@@ -216,6 +245,13 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
.schedule();
|
.schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void runAsync(final Runnable task) {
|
||||||
|
this.proxy.getScheduler()
|
||||||
|
.buildTask(this, task)
|
||||||
|
.schedule();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void shutdown() {
|
public final void shutdown() {
|
||||||
this.metrics.shutdown();
|
this.metrics.shutdown();
|
||||||
|
|||||||
@@ -7,18 +7,21 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.velocitypowered.api.command.SimpleCommand;
|
import com.velocitypowered.api.command.SimpleCommand;
|
||||||
|
|
||||||
public class OriginBlacklistCommandVelocity extends OriginBlacklistCommand implements SimpleCommand {
|
public final class OriginBlacklistCommandVelocity extends OriginBlacklistCommand implements SimpleCommand {
|
||||||
|
private final OriginBlacklist plugin;
|
||||||
|
|
||||||
public OriginBlacklistCommandVelocity(OriginBlacklist plugin) {
|
public OriginBlacklistCommandVelocity(OriginBlacklist plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final Invocation invocation) {
|
public final void execute(final Invocation invocation) {
|
||||||
super.execute(new VCommandContext(invocation));
|
super.execute(new VCommandContext(this.plugin, invocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggest(final Invocation invocation) {
|
public final List<String> suggest(final Invocation invocation) {
|
||||||
return super.suggest(new VCommandContext(invocation));
|
return super.suggest(new VCommandContext(this.plugin, invocation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,42 @@
|
|||||||
package xyz.webmc.originblacklist.velocity.command;
|
package xyz.webmc.originblacklist.velocity.command;
|
||||||
|
|
||||||
|
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||||
import xyz.webmc.originblacklist.base.command.CommandContext;
|
import xyz.webmc.originblacklist.base.command.CommandContext;
|
||||||
|
|
||||||
import com.velocitypowered.api.command.SimpleCommand.Invocation;
|
import com.velocitypowered.api.command.SimpleCommand.Invocation;
|
||||||
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
public class VCommandContext implements CommandContext {
|
public final class VCommandContext implements CommandContext {
|
||||||
|
private final OriginBlacklist plugin;
|
||||||
private final Invocation invocation;
|
private final Invocation invocation;
|
||||||
|
|
||||||
public VCommandContext(final Invocation invocation) {
|
public VCommandContext(final OriginBlacklist plugin, final Invocation invocation) {
|
||||||
|
this.plugin = plugin;
|
||||||
this.invocation = invocation;
|
this.invocation = invocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerName() {
|
public final OriginBlacklist getPlugin() {
|
||||||
|
return this.plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getPlayerName() {
|
||||||
return this.invocation.source().toString();
|
return this.invocation.source().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reply(final String message) {
|
public final void reply(final String message) {
|
||||||
this.invocation.source().sendMessage(MiniMessage.miniMessage().deserialize(message));
|
this.invocation.source().sendMessage(MiniMessage.miniMessage().deserialize(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(final String permission) {
|
public final boolean hasPermission(final String permission) {
|
||||||
return this.invocation.source().hasPermission(permission);
|
return this.invocation.source().hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getArgs() {
|
public final String[] getArgs() {
|
||||||
return this.invocation.arguments();
|
return this.invocation.arguments();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ version: ${plugin_vers}
|
|||||||
main: xyz.webmc.${plugin_iden}.bungee.${plugin_name}Bungee
|
main: xyz.webmc.${plugin_iden}.bungee.${plugin_name}Bungee
|
||||||
description: ${plugin_desc}
|
description: ${plugin_desc}
|
||||||
website: ${plugin_site}
|
website: ${plugin_site}
|
||||||
author: [${plugin_athr}]
|
author: ${plugin_athr}
|
||||||
contributors: [${plugin_ctbr}]
|
contributors: ${plugin_ctbr}
|
||||||
depends: [${plugin_depb}]
|
depends: ${plugin_depb}
|
||||||
provides: [${plugin_prov}]
|
provides: ${plugin_prov}
|
||||||
softdepend: [${plugin_sdpb}]
|
softdepend: ${plugin_sdpb}
|
||||||
@@ -3,10 +3,10 @@ version: ${plugin_vers}
|
|||||||
main: xyz.webmc.${plugin_iden}.bukkit.${plugin_name}Bukkit
|
main: xyz.webmc.${plugin_iden}.bukkit.${plugin_name}Bukkit
|
||||||
description: ${plugin_desc}
|
description: ${plugin_desc}
|
||||||
website: ${plugin_site}
|
website: ${plugin_site}
|
||||||
authors: [${plugin_athr}]
|
authors: ${plugin_athr}
|
||||||
contributors: [${plugin_ctbr}]
|
contributors: ${plugin_ctbr}
|
||||||
depend: [${plugin_depa}]
|
depend: ${plugin_depa}
|
||||||
provides: [${plugin_prov}]
|
provides: ${plugin_prov}
|
||||||
softdepend: [${plugin_sdpa}]
|
softdepend: ${plugin_sdpa}
|
||||||
commands:
|
commands:
|
||||||
originblacklist:
|
${plugin_iden}:
|
||||||
@@ -5,6 +5,6 @@
|
|||||||
"description": "${plugin_desc}",
|
"description": "${plugin_desc}",
|
||||||
"website": "${plugin_site}",
|
"website": "${plugin_site}",
|
||||||
"main": "xyz.webmc.${plugin_iden}.velocity.${plugin_name}Velocity",
|
"main": "xyz.webmc.${plugin_iden}.velocity.${plugin_name}Velocity",
|
||||||
"authors": [${plugin_athr}],
|
"authors": ${plugin_athr},
|
||||||
"dependencies": [${plugin_depc}]
|
"dependencies": ${plugin_depc}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user