mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 19:17:40 +00:00
Compare commits
5 Commits
5e29f7f74a
...
v2.0.5+14f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14ffd4eb08 | ||
|
|
50fdbb0c28 | ||
|
|
bb71befe78 | ||
|
|
49f4e249e5 | ||
|
|
5491efa79a |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,8 +1,10 @@
|
|||||||
/.gradle/
|
/.gradle/
|
||||||
/.vscode/
|
/.vscode/
|
||||||
/gradle/
|
/gradle/**
|
||||||
/build/
|
/build/
|
||||||
/bin/
|
/bin/
|
||||||
/run/
|
/run/
|
||||||
/gradlew
|
/gradlew
|
||||||
/gradlew.bat
|
/gradlew.bat
|
||||||
|
!/gradle/wrapper/
|
||||||
|
!/gradle/wrapper/*.properties
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
- [x] MiniMessage and legacy formattings supported
|
- [x] MiniMessage and legacy formattings supported
|
||||||
- [x] Plugin update checker
|
- [x] Plugin update checker
|
||||||
- [x] Send blacklist logs to a webhook
|
- [x] Send blacklist logs to a webhook
|
||||||
|
- [x] Ingame blacklist management commands
|
||||||
- [x] Reverse blacklist (whitelist)
|
- [x] Reverse blacklist (whitelist)
|
||||||
- [ ] Ingame blacklist management command
|
|
||||||
- [ ] Subscribe to an auto-updating blacklist
|
- [ ] Subscribe to an auto-updating blacklist
|
||||||
|
|
||||||
<h2>Changes from v1</h2>
|
<h2>Changes from v1</h2>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import groovy.lang.Closure
|
import groovy.lang.Closure
|
||||||
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
import com.palantir.gradle.gitversion.VersionDetails
|
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
|
||||||
@@ -13,7 +14,7 @@ val PLUGIN_NAME = "OriginBlacklist"
|
|||||||
val PLUGIN_IDEN = "originblacklist"
|
val PLUGIN_IDEN = "originblacklist"
|
||||||
val PLUGIN_DOMN = "xyz.webmc"
|
val PLUGIN_DOMN = "xyz.webmc"
|
||||||
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
||||||
val PLUGIN_VERS = "2.0.4"
|
val PLUGIN_VERS = "2.0.5"
|
||||||
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")
|
||||||
@@ -37,9 +38,11 @@ val PLUGIN_PROV_J = getBukkitBungeeDeps(PLUGIN_PROV)
|
|||||||
val PLUGIN_ATHR_J = getBukkitBungeeDeps(PLUGIN_ATHR)
|
val PLUGIN_ATHR_J = getBukkitBungeeDeps(PLUGIN_ATHR)
|
||||||
val PLUGIN_CTBR_J = getBukkitBungeeDeps(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("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"
|
||||||
@@ -113,7 +116,7 @@ tasks.withType<JavaCompile>().configureEach {
|
|||||||
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 }
|
||||||
|
|
||||||
@@ -126,7 +129,6 @@ tasks.withType<ProcessResources>() {
|
|||||||
doLast {
|
doLast {
|
||||||
val file = destinationDir.resolve("build.properties")
|
val file = destinationDir.resolve("build.properties")
|
||||||
file.parentFile.mkdirs()
|
file.parentFile.mkdirs()
|
||||||
|
|
||||||
file.writeText(
|
file.writeText(
|
||||||
BUILD_PROPS.entries.joinToString("\n") { (k, v) ->
|
BUILD_PROPS.entries.joinToString("\n") { (k, v) ->
|
||||||
"$k = $v"
|
"$k = $v"
|
||||||
@@ -137,44 +139,27 @@ tasks.withType<ProcessResources>() {
|
|||||||
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")
|
tasks.withType<ShadowJar>().configureEach {
|
||||||
modrinth("placeholderapi", "2.11.7")
|
doFirst {
|
||||||
|
delete(layout.buildDirectory.dir("libs"))
|
||||||
|
mkdir(layout.buildDirectory.dir("libs"))
|
||||||
}
|
}
|
||||||
}
|
relocate("inet.ipaddr", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.ipaddress")
|
||||||
|
|
||||||
tasks.withType<RunWaterfall>() {
|
|
||||||
waterfallVersion("1.21")
|
|
||||||
runDirectory.set(layout.projectDirectory.dir("run/waterfall"))
|
|
||||||
downloadPlugins {
|
|
||||||
github("lax1dude", "eaglerxserver", "v1.0.8", "EaglerXServer.jar")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<RunVelocity>() {
|
|
||||||
velocityVersion("3.4.0-SNAPSHOT")
|
|
||||||
runDirectory.set(layout.projectDirectory.dir("run/velocity"))
|
|
||||||
downloadPlugins {
|
|
||||||
github("lax1dude", "eaglerxserver", "v1.0.8", "EaglerXServer.jar")
|
|
||||||
modrinth("miniplaceholders", "3.1.0")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.jar {
|
|
||||||
archiveFileName.set("$PLUGIN_NAME-$PLUGIN_VERS.jar")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.shadowJar {
|
|
||||||
relocate("org.bstats", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.bstats")
|
|
||||||
relocate("de.marhali.json5", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.json5")
|
relocate("de.marhali.json5", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.json5")
|
||||||
|
relocate("org.bstats", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.bstats")
|
||||||
relocate("org.semver4j.semver4j", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.semver4j")
|
relocate("org.semver4j.semver4j", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.semver4j")
|
||||||
// relocate("net.kyori.adventure", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.adventure")
|
// relocate("net.kyori.adventure", "$PLUGIN_DOMN.$PLUGIN_IDEN.shaded.adventure")
|
||||||
archiveFileName.set("$PLUGIN_NAME-$PLUGIN_VERS.jar")
|
archiveFileName.set("$PLUGIN_NAME-$PLUGIN_VERS.jar")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.named("build") {
|
||||||
|
dependsOn(tasks.named("shadowJar"))
|
||||||
|
}
|
||||||
|
|
||||||
tasks.register("printVars") {
|
tasks.register("printVars") {
|
||||||
group = "help"
|
group = "help"
|
||||||
doLast {
|
doLast {
|
||||||
@@ -183,6 +168,32 @@ tasks.register("printVars") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType<RunServer>().configureEach {
|
||||||
|
minecraftVersion("1.12.2")
|
||||||
|
runDirectory.set(layout.projectDirectory.dir("run/paper"))
|
||||||
|
downloadPlugins {
|
||||||
|
github("lax1dude", "eaglerxserver", "v" + EAGXS_VER, "EaglerXServer.jar")
|
||||||
|
modrinth("placeholderapi", "2.11.7")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
fun getBukkitBungeeDeps(list: List<String>): String {
|
||||||
return list.joinToString(
|
return list.joinToString(
|
||||||
prefix = "[",
|
prefix = "[",
|
||||||
|
|||||||
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
|
||||||
@@ -6,6 +6,7 @@ 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.OriginBlacklistHTTPServer;
|
||||||
import xyz.webmc.originblacklist.base.util.BuildInfo;
|
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;
|
||||||
@@ -26,8 +27,10 @@ import java.util.Base64;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -47,11 +50,15 @@ public final class OriginBlacklist {
|
|||||||
|
|
||||||
private final IOriginBlacklistPlugin plugin;
|
private final IOriginBlacklistPlugin plugin;
|
||||||
private final OriginBlacklistConfig config;
|
private final OriginBlacklistConfig config;
|
||||||
|
private final OriginBlacklistHTTPServer http;
|
||||||
|
private final Json5 json5;
|
||||||
private String updateURL;
|
private String updateURL;
|
||||||
|
|
||||||
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(plugin);
|
||||||
|
this.http = new OriginBlacklistHTTPServer(this);
|
||||||
|
this.json5 = Json5.builder(builder -> builder.prettyPrinting().indentFactor(0).build());
|
||||||
plugin.scheduleRepeat(() -> {
|
plugin.scheduleRepeat(() -> {
|
||||||
this.checkForUpdates();
|
this.checkForUpdates();
|
||||||
}, this.config.getInteger("update_checker.check_timer"), TimeUnit.SECONDS);
|
}, this.config.getInteger("update_checker.check_timer"), TimeUnit.SECONDS);
|
||||||
@@ -60,6 +67,22 @@ public final class OriginBlacklist {
|
|||||||
public final void init() {
|
public final void init() {
|
||||||
this.plugin.log(EnumLogLevel.INFO, "Initialized Plugin");
|
this.plugin.log(EnumLogLevel.INFO, "Initialized Plugin");
|
||||||
this.plugin.log(EnumLogLevel.DEBUG, "Commit " + BuildInfo.get("git_cm_hash"));
|
this.plugin.log(EnumLogLevel.DEBUG, "Commit " + BuildInfo.get("git_cm_hash"));
|
||||||
|
if (this.isHTTPServerEnabled()) {
|
||||||
|
this.http.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void shutdown() {
|
||||||
|
this.plugin.log(EnumLogLevel.INFO, "Shutting down...");
|
||||||
|
this.http.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void handleReload() {
|
||||||
|
if (this.isHTTPServerEnabled()) {
|
||||||
|
this.http.start();
|
||||||
|
} else {
|
||||||
|
this.http.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void handleLogin(final OriginBlacklistLoginEvent event) {
|
public final void handleLogin(final OriginBlacklistLoginEvent event) {
|
||||||
@@ -115,6 +138,10 @@ public final class OriginBlacklist {
|
|||||||
return this.config.getBoolean("bStats");
|
return this.config.getBoolean("bStats");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean isHTTPServerEnabled() {
|
||||||
|
return this.config.getBoolean("blacklist_http_share.enabled");
|
||||||
|
}
|
||||||
|
|
||||||
public final OriginBlacklistConfig getConfig() {
|
public final OriginBlacklistConfig getConfig() {
|
||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
@@ -134,7 +161,7 @@ public final class OriginBlacklist {
|
|||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void checkForUpdates(Runnable action1, Runnable action2) {
|
public final void checkForUpdates(final Runnable action1, final Runnable action2) {
|
||||||
if (this.config.getBoolean("update_checker.enabled")) {
|
if (this.config.getBoolean("update_checker.enabled")) {
|
||||||
this.plugin.runAsync(() -> {
|
this.plugin.runAsync(() -> {
|
||||||
this.updateURL = UpdateChecker.checkForUpdates(PLUGIN_REPO, this.plugin.getPluginVersion(),
|
this.updateURL = UpdateChecker.checkForUpdates(PLUGIN_REPO, this.plugin.getPluginVersion(),
|
||||||
@@ -150,12 +177,13 @@ public final class OriginBlacklist {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void updatePlugin(Runnable action1, Runnable action2) {
|
public final void updatePlugin(final Runnable action1, final Runnable action2) {
|
||||||
try {
|
try {
|
||||||
final URL url = new URL(this.updateURL);
|
final URL url = new URL(this.updateURL);
|
||||||
final Path jar = this.plugin.getPluginJarPath();
|
final Path jar = this.plugin.getPluginJarPath();
|
||||||
final Path bak = jar.resolveSibling(jar.getFileName().toString() + ".bak");
|
final Path bak = jar.resolveSibling(jar.getFileName().toString() + ".bak");
|
||||||
final Path upd = jar.resolveSibling(Paths.get(URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8)).getFileName());
|
final Path upd = jar
|
||||||
|
.resolveSibling(Paths.get(URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8)).getFileName());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.copy(jar, bak, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(jar, bak, StandardCopyOption.REPLACE_EXISTING);
|
||||||
@@ -190,10 +218,12 @@ public final class OriginBlacklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void updatePlugin() {
|
public final void updatePlugin() {
|
||||||
this.updatePlugin(() -> {}, () -> {});
|
this.updatePlugin(() -> {
|
||||||
|
}, () -> {
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private final EnumBlacklistType testBlacklist(final OPlayer player) {
|
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();
|
||||||
@@ -203,11 +233,14 @@ public final class OriginBlacklist {
|
|||||||
EnumBlacklistType type = EnumBlacklistType.NONE;
|
EnumBlacklistType type = EnumBlacklistType.NONE;
|
||||||
|
|
||||||
if (isNonNull(origin)) {
|
if (isNonNull(origin)) {
|
||||||
if (whitelist && !type.isBlacklisted()) type = EnumBlacklistType.ORIGIN;
|
if (whitelist && !type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.ORIGIN;
|
||||||
for (final Json5Element element : this.config.getArray("blacklist.origins").getAsJson5Array()) {
|
for (final Json5Element element : this.config.getArray("blacklist.origins").getAsJson5Array()) {
|
||||||
if (origin.matches(element.getAsString())) {
|
if (origin.matches(element.getAsString())) {
|
||||||
if (whitelist) type = EnumBlacklistType.NONE;
|
if (whitelist)
|
||||||
else if (!type.isBlacklisted()) type = EnumBlacklistType.ORIGIN;
|
type = EnumBlacklistType.NONE;
|
||||||
|
else if (!type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.ORIGIN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,40 +249,49 @@ public final class OriginBlacklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isNonNull(brand)) {
|
if (isNonNull(brand)) {
|
||||||
if (whitelist && !type.isBlacklisted()) type = EnumBlacklistType.BRAND;
|
if (whitelist && !type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.BRAND;
|
||||||
for (final Json5Element element : this.config.getArray("blacklist.brands")) {
|
for (final Json5Element element : this.config.getArray("blacklist.brands")) {
|
||||||
if (brand.matches(element.getAsString())) {
|
if (brand.matches(element.getAsString())) {
|
||||||
if (whitelist) type = EnumBlacklistType.NONE;
|
if (whitelist)
|
||||||
else if (!type.isBlacklisted()) type = EnumBlacklistType.BRAND;
|
type = EnumBlacklistType.NONE;
|
||||||
|
else if (!type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.BRAND;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNonNull(name)) {
|
if (isNonNull(name)) {
|
||||||
if (whitelist && !type.isBlacklisted()) type = EnumBlacklistType.NAME;
|
if (whitelist && !type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.NAME;
|
||||||
for (final Json5Element element : this.config.getArray("blacklist.player_names")) {
|
for (final Json5Element element : this.config.getArray("blacklist.player_names")) {
|
||||||
this.plugin.log(EnumLogLevel.DEBUG, element.getAsString());
|
|
||||||
if (name.matches(element.getAsString())) {
|
if (name.matches(element.getAsString())) {
|
||||||
if (whitelist) type = EnumBlacklistType.NONE;
|
if (whitelist)
|
||||||
else if (!type.isBlacklisted()) type = EnumBlacklistType.NAME;
|
type = EnumBlacklistType.NONE;
|
||||||
|
else if (!type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.NAME;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNonNull(addr)) {
|
if (isNonNull(addr)) {
|
||||||
if (whitelist && !type.isBlacklisted()) type = EnumBlacklistType.ADDR;
|
if (whitelist && !type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.ADDR;
|
||||||
for (final Json5Element element : this.config.getArray("blacklist.ip_addresses")) {
|
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())) {
|
||||||
if (whitelist) type = EnumBlacklistType.NONE;
|
if (whitelist)
|
||||||
else if (!type.isBlacklisted()) type = EnumBlacklistType.ADDR;
|
type = EnumBlacklistType.NONE;
|
||||||
|
else if (!type.isBlacklisted())
|
||||||
|
type = EnumBlacklistType.ADDR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (final AddressStringException exception) {
|
} catch (final AddressStringException exception) {
|
||||||
if (this.isDebugEnabled()) exception.printStackTrace();
|
if (this.isDebugEnabled())
|
||||||
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,6 +299,24 @@ public final class OriginBlacklist {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final String getBlacklistShare() {
|
||||||
|
try {
|
||||||
|
final Json5Object obj = new Json5Object();
|
||||||
|
obj.addProperty("plugin_version", this.plugin.getPluginVersion().getVersion());
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@@ -289,80 +349,77 @@ public final class OriginBlacklist {
|
|||||||
userAgent = UNKNOWN_STR;
|
userAgent = UNKNOWN_STR;
|
||||||
}
|
}
|
||||||
final byte[] payload = String.format(
|
final byte[] payload = String.format(
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
"content": "Blocked a blacklisted %s from joining",
|
"content": "Blocked a blacklisted %s from joining",
|
||||||
"embeds": [
|
"embeds": [
|
||||||
{
|
{
|
||||||
"title": "-------- Player Information --------",
|
"title": "-------- Player Information --------",
|
||||||
"description": "**→ Name:** %s\\n**→ Origin:** %s\\n**→ Brand:** %s\\n**→ IP Address:** %s\\n**→ Protocol Version:** %s\\n**→ User Agent:** %s\\n**→ Rewind:** %s\\n**→ Player Type:** %s",
|
"description": "**→ Name:** %s\\n**→ Origin:** %s\\n**→ Brand:** %s\\n**→ IP Address:** %s\\n**→ Protocol Version:** %s\\n**→ User Agent:** %s\\n**→ Rewind:** %s\\n**→ Player Type:** %s",
|
||||||
"color": 15801922,
|
"color": 15801922,
|
||||||
"fields": [],
|
"fields": [],
|
||||||
"footer": {
|
"footer": {
|
||||||
"text": "OriginBlacklist v%s",
|
"text": "OriginBlacklist v%s",
|
||||||
"icon_url": "https://raw.githubusercontent.com/%s/refs/heads/main/img/icon.png"
|
"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": "🌐"
|
|
||||||
}
|
}
|
||||||
}
|
],
|
||||||
]
|
"components": [
|
||||||
}
|
{
|
||||||
]
|
"type": 1,
|
||||||
}
|
"components": [
|
||||||
""",
|
{
|
||||||
type.getAltString(),
|
"type": 2,
|
||||||
player.getName().replaceAll("_", "\\_"),
|
"style": 5,
|
||||||
player.getOrigin(),
|
"label": "Get the Plugin",
|
||||||
player.getBrand(),
|
"url": "https://github.com/%s",
|
||||||
this.config.getBoolean("discord.send_ips") ? player.getAddr() : "*\\*CENSORED\\**",
|
"emoji": {
|
||||||
player.getPVN(),
|
"name": "🌐"
|
||||||
userAgent,
|
}
|
||||||
player.isRewind() ? "YES" : "NO",
|
}
|
||||||
connType.toString(),
|
]
|
||||||
this.plugin.getPluginVersion(),
|
}
|
||||||
PLUGIN_REPO,
|
]
|
||||||
PLUGIN_REPO
|
}
|
||||||
).getBytes();
|
""",
|
||||||
final Json5Element element = this.config.get("discord.webhook_urls");
|
type.getAltString(),
|
||||||
if (element instanceof Json5Array) {
|
player.getName().replaceAll("_", "\\_"),
|
||||||
for (final Json5Element _element : element.getAsJson5Array()) {
|
player.getOrigin(),
|
||||||
this.plugin.runAsync(() -> {
|
player.getBrand(),
|
||||||
try {
|
this.config.getBoolean("discord.send_ips") ? player.getAddr() : "*\\*CENSORED\\**",
|
||||||
final URL url = new URL(_element.getAsString());
|
player.getPVN(),
|
||||||
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
userAgent,
|
||||||
conn.setRequestMethod("POST");
|
player.isRewind() ? "YES" : "NO",
|
||||||
conn.setRequestProperty("Content-Type", "application/json");
|
connType.toString(),
|
||||||
conn.setDoOutput(true);
|
this.plugin.getPluginVersion(),
|
||||||
conn.setConnectTimeout(5000);
|
PLUGIN_REPO,
|
||||||
conn.setReadTimeout(5000);
|
PLUGIN_REPO).getBytes();
|
||||||
conn.connect();
|
final Json5Array arr = this.config.get("discord.webhook_urls").getAsJson5Array();
|
||||||
final OutputStream os = conn.getOutputStream();
|
for (final Json5Element element : arr) {
|
||||||
os.write(payload);
|
this.plugin.runAsync(() -> {
|
||||||
os.close();
|
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();
|
final int code = conn.getResponseCode();
|
||||||
if (code < 200 || code >= 300) {
|
if (code < 200 || code >= 300) {
|
||||||
this.plugin.log(EnumLogLevel.WARN, "Webhook failed (HTTP " + code + ")");
|
this.plugin.log(EnumLogLevel.WARN, "Webhook failed (HTTP " + code + ")");
|
||||||
}
|
|
||||||
|
|
||||||
conn.disconnect();
|
|
||||||
} catch (final Throwable t) {
|
|
||||||
t.printStackTrace();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
conn.disconnect();
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,7 +431,8 @@ public final class OriginBlacklist {
|
|||||||
} else {
|
} else {
|
||||||
this.updatePlugin();
|
this.updatePlugin();
|
||||||
}
|
}
|
||||||
}, () -> {});
|
}, () -> {
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String getComponentString(final Component comp) {
|
public static final String getComponentString(final Component comp) {
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ import xyz.webmc.originblacklist.base.OriginBlacklist;
|
|||||||
|
|
||||||
public interface CommandContext {
|
public interface CommandContext {
|
||||||
public OriginBlacklist getPlugin();
|
public OriginBlacklist getPlugin();
|
||||||
|
|
||||||
public String getPlayerName();
|
public String getPlayerName();
|
||||||
|
|
||||||
public void reply(final String message);
|
public void reply(final String message);
|
||||||
|
|
||||||
public boolean hasPermission(final String permission);
|
public boolean hasPermission(final String permission);
|
||||||
|
|
||||||
public String[] getArgs();
|
public String[] getArgs();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface ICommand {
|
public interface ICommand {
|
||||||
public 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>";
|
||||||
|
|
||||||
public boolean execute(final CommandContext ctx);
|
public boolean execute(final CommandContext ctx);
|
||||||
|
|
||||||
public List<String> suggest(final CommandContext ctx);
|
public List<String> suggest(final CommandContext ctx);
|
||||||
|
|
||||||
public void usage(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,43 +23,27 @@ 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")) {
|
|
||||||
ctx.reply("<aqua>Blacklist:</aqua>");
|
|
||||||
ctx.reply("<gold> - Origins:</gold>");
|
|
||||||
for (final Json5Element element : this.plugin.getConfig().getArray("blacklist.origins")) {
|
|
||||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
|
||||||
}
|
|
||||||
ctx.reply("<gold> - Brands:</gold>");
|
|
||||||
for (final Json5Element element : this.plugin.getConfig().getArray("blacklist.brands")) {
|
|
||||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
|
||||||
}
|
|
||||||
ctx.reply("<gold> - Players:</gold>");
|
|
||||||
for (final Json5Element element : this.plugin.getConfig().getArray("blacklist.player_names")) {
|
|
||||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
|
||||||
}
|
|
||||||
ctx.reply("<gold> - IPs:</gold>");
|
|
||||||
for (final Json5Element element : this.plugin.getConfig().getArray("blacklist.ip_addresses")) {
|
|
||||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ctx.reply(NO_PERMISSION);
|
|
||||||
}
|
|
||||||
} else if ("update".equals(command)) {
|
|
||||||
if (ctx.hasPermission("originblacklist.command.update")) {
|
if (ctx.hasPermission("originblacklist.command.update")) {
|
||||||
ctx.reply("<aqua>Checking for updates...</aqua>");
|
ctx.reply("<aqua>Checking for updates...</aqua>");
|
||||||
final OriginBlacklist plugin = ctx.getPlugin();
|
this.plugin.checkForUpdates(() -> {
|
||||||
plugin.checkForUpdates(() -> {
|
|
||||||
ctx.reply("<yellow>Updating plugin...</yellow>");
|
ctx.reply("<yellow>Updating plugin...</yellow>");
|
||||||
plugin.updatePlugin(() -> {
|
this.plugin.updatePlugin(() -> {
|
||||||
ctx.reply("<green>Successfully updated plugin.</green>");
|
ctx.reply("<green>Successfully updated plugin.</green>");
|
||||||
}, () -> {
|
}, () -> {
|
||||||
ctx.reply("<red>Failed to update plugin.</red>");
|
ctx.reply("<red>Failed to update plugin.</red>");
|
||||||
@@ -65,6 +54,79 @@ public class OriginBlacklistCommand implements ICommand {
|
|||||||
} else {
|
} else {
|
||||||
ctx.reply(NO_PERMISSION);
|
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("<gold> - Origins:</gold>");
|
||||||
|
for (final Json5Element element : config.getArray("blacklist.origins")) {
|
||||||
|
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||||
|
}
|
||||||
|
ctx.reply("<gold> - Brands:</gold>");
|
||||||
|
for (final Json5Element element : config.getArray("blacklist.brands")) {
|
||||||
|
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||||
|
}
|
||||||
|
ctx.reply("<gold> - Players:</gold>");
|
||||||
|
for (final Json5Element element : config.getArray("blacklist.player_names")) {
|
||||||
|
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||||
|
}
|
||||||
|
ctx.reply("<gold> - IPs:</gold>");
|
||||||
|
for (final Json5Element element : config.getArray("blacklist.ip_addresses")) {
|
||||||
|
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.reply(NO_PERMISSION);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.usage(ctx);
|
this.usage(ctx);
|
||||||
}
|
}
|
||||||
@@ -78,17 +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 update</gray>");
|
ctx.reply("<gray> - /originblacklist update</gray>");
|
||||||
// ctx.reply("<gray> - /originblacklist add <brand/origin/name/ip> <value></gray>");
|
ctx.reply("<gray> - /originblacklist add <origin/brand/name/ip> <arg></gray>");
|
||||||
// ctx.reply("<gray> - /originblacklist remove <brand/origin/name/ip> <value></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, -1);
|
||||||
|
return this.plugin.testBlacklist(player) != EnumBlacklistType.NONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,19 +50,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 {
|
||||||
@@ -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,75 @@ 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) {
|
public final String getString(final String key) {
|
||||||
return this.get(key).getAsString();
|
return this.get(key).getAsString();
|
||||||
}
|
}
|
||||||
@@ -186,7 +255,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>");
|
||||||
@@ -195,18 +264,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.*");
|
||||||
@@ -218,32 +287,37 @@ 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(dobj, "send_ips", Json5Primitive.fromBoolean(true), null);
|
addJSONObj(dObj, "send_ips", Json5Primitive.fromBoolean(true), null);
|
||||||
addJSONObj(obj, "discord", dobj, null);
|
addJSONObj(obj, "discord", dObj, null);
|
||||||
final Json5Object uobj = new Json5Object();
|
final Json5Object uObj = new Json5Object();
|
||||||
addJSONObj(uobj, "enabled", Json5Primitive.fromBoolean(true), null);
|
addJSONObj(uObj, "enabled", Json5Primitive.fromBoolean(true), null);
|
||||||
addJSONObj(uobj, "allow_snapshots", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(uObj, "allow_snapshots", Json5Primitive.fromBoolean(false), null);
|
||||||
addJSONObj(uobj, "check_timer", Json5Primitive.fromNumber(3600), null);
|
addJSONObj(uObj, "check_timer", Json5Primitive.fromNumber(3600), null);
|
||||||
addJSONObj(uobj, "auto_update", Json5Primitive.fromBoolean(true), null);
|
addJSONObj(uObj, "auto_update", Json5Primitive.fromBoolean(true), null);
|
||||||
addJSONObj(obj, "update_checker", uobj, null);
|
addJSONObj(obj, "update_checker", uObj, null);
|
||||||
|
final Json5Object hObj = new Json5Object();
|
||||||
|
addJSONObj(hObj, "enabled", Json5Primitive.fromBoolean(false), null);
|
||||||
|
addJSONObj(hObj, "http_port", Json5Primitive.fromNumber(8080), null);
|
||||||
|
addJSONObj(hObj, "listen_addr", Json5Primitive.fromString("0.0.0.0"), null);
|
||||||
|
addJSONObj(obj, "blacklist_http_share", hObj, null);
|
||||||
addJSONObj(obj, "blacklist_to_whitelist", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(obj, "blacklist_to_whitelist", Json5Primitive.fromBoolean(false), null);
|
||||||
addJSONObj(obj, "block_undefined_origin", 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);
|
||||||
@@ -279,4 +353,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package xyz.webmc.originblacklist.base.http;
|
||||||
|
|
||||||
|
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
import com.sun.net.httpserver.HttpHandler;
|
||||||
|
|
||||||
|
public class OriginBlacklistHTTPHandler implements HttpHandler {
|
||||||
|
private final OriginBlacklist plugin;
|
||||||
|
|
||||||
|
public OriginBlacklistHTTPHandler(final OriginBlacklist plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void handle(final HttpExchange exchange) throws IOException {
|
||||||
|
try {
|
||||||
|
final String path = exchange.getRequestURI().getPath();
|
||||||
|
if ("/".equals(path)) {
|
||||||
|
final byte[] bytes = this.plugin.getBlacklistShare().getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
exchange.getResponseHeaders().set("Content-Type", "application/json; charset=utf-8");
|
||||||
|
exchange.sendResponseHeaders(200, bytes.length);
|
||||||
|
|
||||||
|
try (final OutputStream os = exchange.getResponseBody()) {
|
||||||
|
os.write(bytes);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
exchange.sendResponseHeaders(404, -1);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
exchange.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package xyz.webmc.originblacklist.base.http;
|
||||||
|
|
||||||
|
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||||
|
import xyz.webmc.originblacklist.base.config.OriginBlacklistConfig;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpServer;
|
||||||
|
|
||||||
|
public class OriginBlacklistHTTPServer {
|
||||||
|
private final OriginBlacklist plugin;
|
||||||
|
private final ExecutorService executor;
|
||||||
|
private HttpServer server;
|
||||||
|
private boolean running;
|
||||||
|
|
||||||
|
public OriginBlacklistHTTPServer(final OriginBlacklist plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.executor = Executors.newFixedThreadPool(4);
|
||||||
|
this.running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void start() {
|
||||||
|
if (!this.running) {
|
||||||
|
try {
|
||||||
|
this.server = this.createServer();
|
||||||
|
this.server.start();
|
||||||
|
this.running = true;
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void stop() {
|
||||||
|
if (this.running && this.server != null) {
|
||||||
|
this.server.stop(0);
|
||||||
|
this.running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void shutdown() {
|
||||||
|
this.stop();
|
||||||
|
this.executor.shutdownNow();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final HttpServer createServer() throws Throwable {
|
||||||
|
final OriginBlacklistConfig config = this.plugin.getConfig();
|
||||||
|
final HttpServer server = HttpServer
|
||||||
|
.create(new InetSocketAddress(config.getString("blacklist_http_share.listen_addr"),
|
||||||
|
config.getInteger("blacklist_http_share.http_port")), 0);
|
||||||
|
server.createContext("/", new OriginBlacklistHTTPHandler(this.plugin));
|
||||||
|
server.setExecutor(executor);
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ package xyz.webmc.originblacklist.base.util;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class BuildInfo {
|
public final class BuildInfo {
|
||||||
private static final Properties properties;
|
private static final Properties properties;
|
||||||
|
|
||||||
public static final String get(final String key) {
|
public static final String get(final String key) {
|
||||||
@@ -14,6 +14,7 @@ public class BuildInfo {
|
|||||||
properties = new Properties();
|
properties = new Properties();
|
||||||
try (final InputStream in = BuildInfo.class.getClassLoader().getResourceAsStream("build.properties")) {
|
try (final InputStream in = BuildInfo.class.getClassLoader().getResourceAsStream("build.properties")) {
|
||||||
properties.load(in);
|
properties.load(in);
|
||||||
} catch (final Throwable t) {}
|
} catch (final Throwable t) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,22 @@ import org.semver4j.Semver;
|
|||||||
|
|
||||||
public interface IOriginBlacklistPlugin {
|
public interface IOriginBlacklistPlugin {
|
||||||
public String getPluginId();
|
public String getPluginId();
|
||||||
|
|
||||||
public Semver getPluginVersion();
|
public Semver getPluginVersion();
|
||||||
|
|
||||||
public Path getPluginJarPath();
|
public Path getPluginJarPath();
|
||||||
|
|
||||||
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 runAsync(final Runnable task);
|
||||||
|
|
||||||
public void shutdown();
|
public void shutdown();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,9 +78,7 @@ public final class OPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final String formatIPAddress(String addr) {
|
private static final String formatIPAddress(String addr) {
|
||||||
if (addr == null) {
|
if (OriginBlacklist.isNonNull(addr)) {
|
||||||
addr = OriginBlacklist.UNKNOWN_STR;
|
|
||||||
} else {
|
|
||||||
if (addr.startsWith("/")) {
|
if (addr.startsWith("/")) {
|
||||||
addr = addr.substring(1);
|
addr = addr.substring(1);
|
||||||
}
|
}
|
||||||
@@ -132,6 +130,8 @@ public final class OPlayer {
|
|||||||
if (hex && c == 6 && addr.indexOf("::") == -1) {
|
if (hex && c == 6 && addr.indexOf("::") == -1) {
|
||||||
addr = addr + "::";
|
addr = addr + "::";
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
addr = OriginBlacklist.UNKNOWN_STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return addr;
|
return addr;
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ import de.marhali.json5.Json5Object;
|
|||||||
import org.semver4j.Semver;
|
import org.semver4j.Semver;
|
||||||
import org.semver4j.Semver.VersionDiff;
|
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 String checkForUpdates(final String repo, final Semver currentVersion, final boolean allowSnapshots) {
|
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();
|
||||||
@@ -46,11 +47,13 @@ public class UpdateChecker {
|
|||||||
}
|
}
|
||||||
final boolean pre = obj.get("prerelease").getAsBoolean();
|
final boolean pre = obj.get("prerelease").getAsBoolean();
|
||||||
if (!pre) {
|
if (!pre) {
|
||||||
if (rel == null || obj.get("published_at").getAsString().compareTo(rel.get("published_at").getAsString()) > 0) {
|
if (rel == null
|
||||||
|
|| obj.get("published_at").getAsString().compareTo(rel.get("published_at").getAsString()) > 0) {
|
||||||
rel = obj;
|
rel = obj;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (snap == null || obj.get("published_at").getAsString().compareTo(snap.get("published_at").getAsString()) > 0) {
|
if (snap == null
|
||||||
|
|| obj.get("published_at").getAsString().compareTo(snap.get("published_at").getAsString()) > 0) {
|
||||||
snap = obj;
|
snap = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,10 +71,11 @@ public class UpdateChecker {
|
|||||||
String comm;
|
String comm;
|
||||||
try {
|
try {
|
||||||
comm = ver.getBuild().get(0).trim();
|
comm = ver.getBuild().get(0).trim();
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
comm = "";
|
comm = "";
|
||||||
}
|
}
|
||||||
if (ver.isGreaterThan(currentVersion) || (allowSnapshots && currentVersion.diff(ver) == VersionDiff.BUILD && OriginBlacklist.isNonNull(comm) && !BuildInfo.get("git_cm_hash").startsWith(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");
|
element = obj.get("assets");
|
||||||
if (element instanceof Json5Array) {
|
if (element instanceof Json5Array) {
|
||||||
final Json5Array aArr = element.getAsJson5Array();
|
final Json5Array aArr = element.getAsJson5Array();
|
||||||
|
|||||||
@@ -93,6 +93,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());
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ 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 OriginBlacklist plugin;
|
||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
private final String[] args;
|
private final String[] args;
|
||||||
@@ -17,27 +17,27 @@ public class BKTCommandContext implements CommandContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OriginBlacklist getPlugin() {
|
public final OriginBlacklist getPlugin() {
|
||||||
return this.plugin;
|
return this.plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerName() {
|
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,7 +9,7 @@ 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;
|
private final OriginBlacklist plugin;
|
||||||
|
|
||||||
public OriginBlacklistCommandBukkit(OriginBlacklist plugin) {
|
public OriginBlacklistCommandBukkit(OriginBlacklist plugin) {
|
||||||
@@ -23,7 +23,8 @@ public class OriginBlacklistCommandBukkit extends OriginBlacklistCommand impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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,
|
||||||
|
final String[] args) {
|
||||||
return super.suggest(new BKTCommandContext(this.plugin, sender, args));
|
return super.suggest(new BKTCommandContext(this.plugin, sender, args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,11 @@ 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());
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ 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 OriginBlacklist plugin;
|
||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
private final String[] args;
|
private final String[] args;
|
||||||
@@ -18,27 +18,27 @@ public class BNGCommandContext implements CommandContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OriginBlacklist getPlugin() {
|
public final OriginBlacklist getPlugin() {
|
||||||
return this.plugin;
|
return this.plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerName() {
|
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,23 +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;
|
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;
|
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(this.blacklist, 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(this.blacklist, sender, args));
|
return this.cmd.suggest(new BNGCommandContext(this.blacklist, sender, args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ 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.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
@@ -64,7 +65,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)) {
|
||||||
@@ -105,6 +106,11 @@ 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());
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ 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;
|
private final OriginBlacklist plugin;
|
||||||
|
|
||||||
public OriginBlacklistCommandVelocity(OriginBlacklist plugin) {
|
public OriginBlacklistCommandVelocity(OriginBlacklist plugin) {
|
||||||
@@ -16,12 +16,12 @@ public class OriginBlacklistCommandVelocity extends OriginBlacklistCommand imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final Invocation invocation) {
|
public final void execute(final Invocation invocation) {
|
||||||
super.execute(new VCommandContext(this.plugin, 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(this.plugin, invocation));
|
return super.suggest(new VCommandContext(this.plugin, invocation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ 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 OriginBlacklist plugin;
|
||||||
private final Invocation invocation;
|
private final Invocation invocation;
|
||||||
|
|
||||||
@@ -16,27 +16,27 @@ public class VCommandContext implements CommandContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OriginBlacklist getPlugin() {
|
public final OriginBlacklist getPlugin() {
|
||||||
return this.plugin;
|
return this.plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerName() {
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user