mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 11:07:41 +00:00
Compare commits
11 Commits
v2.0.5
...
00b1c99dc4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00b1c99dc4 | ||
|
|
1cd60a4dba | ||
|
|
ebcae682aa | ||
|
|
f22e800439 | ||
|
|
f0274ff4d4 | ||
|
|
12f9d669b4 | ||
|
|
c43de8a1c9 | ||
|
|
d8fa2b10c1 | ||
|
|
89311ee6de | ||
|
|
14ffd4eb08 | ||
|
|
50fdbb0c28 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,8 +1,10 @@
|
||||
/.gradle/
|
||||
/.vscode/
|
||||
/gradle/
|
||||
/gradle/**
|
||||
/build/
|
||||
/bin/
|
||||
/run/
|
||||
/gradlew
|
||||
/gradlew.bat
|
||||
/gradlew.bat
|
||||
!/gradle/wrapper/
|
||||
!/gradle/wrapper/*.properties
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
- [x] Plugin update checker
|
||||
- [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
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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.language.jvm.tasks.ProcessResources
|
||||
@@ -11,9 +12,9 @@ import xyz.jpenilla.runvelocity.task.RunVelocity
|
||||
|
||||
val PLUGIN_NAME = "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_VERS = "2.0.5"
|
||||
val PLUGIN_VERS = "2.0.8"
|
||||
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
||||
val PLUGIN_DEPA = 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_CTBR_J = getBukkitBungeeDeps(PLUGIN_CTBR)
|
||||
|
||||
val EAGXS_VER = "1.0.8"
|
||||
|
||||
plugins {
|
||||
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-waterfall") version "3.0.2"
|
||||
@@ -113,7 +116,7 @@ tasks.withType<JavaCompile>().configureEach {
|
||||
options.release.set(17)
|
||||
}
|
||||
|
||||
tasks.withType<ProcessResources>() {
|
||||
tasks.withType<ProcessResources>().configureEach {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
outputs.upToDateWhen { false }
|
||||
|
||||
@@ -126,7 +129,6 @@ tasks.withType<ProcessResources>() {
|
||||
doLast {
|
||||
val file = destinationDir.resolve("build.properties")
|
||||
file.parentFile.mkdirs()
|
||||
|
||||
file.writeText(
|
||||
BUILD_PROPS.entries.joinToString("\n") { (k, v) ->
|
||||
"$k = $v"
|
||||
@@ -137,42 +139,25 @@ tasks.withType<ProcessResources>() {
|
||||
inputs.files(tasks.named<JavaCompile>("compileJava").map { it.outputs.files })
|
||||
}
|
||||
|
||||
tasks.withType<RunServer>() {
|
||||
minecraftVersion("1.12.2")
|
||||
runDirectory.set(layout.projectDirectory.dir("run/paper"))
|
||||
downloadPlugins {
|
||||
github("lax1dude", "eaglerxserver", "v1.0.8", "EaglerXServer.jar")
|
||||
modrinth("placeholderapi", "2.11.7")
|
||||
}
|
||||
tasks.withType<Jar>().configureEach {
|
||||
if (this !is ShadowJar) enabled = false
|
||||
}
|
||||
|
||||
tasks.withType<RunWaterfall>() {
|
||||
waterfallVersion("1.21")
|
||||
runDirectory.set(layout.projectDirectory.dir("run/waterfall"))
|
||||
downloadPlugins {
|
||||
github("lax1dude", "eaglerxserver", "v1.0.8", "EaglerXServer.jar")
|
||||
tasks.withType<ShadowJar>().configureEach {
|
||||
doFirst {
|
||||
delete(layout.buildDirectory.dir("libs"))
|
||||
mkdir(layout.buildDirectory.dir("libs"))
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
relocate("inet.ipaddr", "$PLUGIN_DOMN.shaded.ipaddress")
|
||||
relocate("de.marhali.json5", "$PLUGIN_DOMN.shaded.json5")
|
||||
relocate("org.bstats", "$PLUGIN_DOMN.shaded.bstats")
|
||||
relocate("org.semver4j.semver4j", "$PLUGIN_DOMN.shaded.semver4j")
|
||||
// relocate("net.kyori.adventure", "$PLUGIN_DOMN.shaded.adventure")
|
||||
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("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.named("build") {
|
||||
dependsOn(tasks.named("shadowJar"))
|
||||
}
|
||||
|
||||
tasks.register("printVars") {
|
||||
@@ -183,6 +168,33 @@ tasks.register("printVars") {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<RunServer>().configureEach {
|
||||
minecraftVersion("1.12.2")
|
||||
runDirectory.set(layout.projectDirectory.dir("run/paper"))
|
||||
jvmArgs("-Dcom.mojang.eula.agree=true")
|
||||
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 {
|
||||
return list.joinToString(
|
||||
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.events.OriginBlacklistLoginEvent;
|
||||
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.OPlayer;
|
||||
@@ -21,45 +22,78 @@ 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.Base64;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import de.marhali.json5.Json5;
|
||||
import de.marhali.json5.Json5Array;
|
||||
import de.marhali.json5.Json5Element;
|
||||
import de.marhali.json5.Json5Object;
|
||||
import inet.ipaddr.AddressStringException;
|
||||
import inet.ipaddr.IPAddressString;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.EnumWebSocketHeader;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerLoginConnection;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
||||
import org.semver4j.Semver;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
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 String GENERIC_STR = "GENERIC";
|
||||
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 int BSTATS_ID = 28776;
|
||||
|
||||
private final IOriginBlacklistPlugin plugin;
|
||||
private final OriginBlacklistConfig config;
|
||||
private final Json5 json5;
|
||||
private String updateURL;
|
||||
private Path jarFile;
|
||||
|
||||
public OriginBlacklist(final IOriginBlacklistPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.config = new OriginBlacklistConfig(plugin);
|
||||
plugin.scheduleRepeat(() -> {
|
||||
this.checkForUpdates();
|
||||
}, this.config.getInteger("update_checker.check_timer"), TimeUnit.SECONDS);
|
||||
this.config = new OriginBlacklistConfig(this);
|
||||
this.json5 = Json5.builder(builder -> builder.prettyPrinting().indentFactor(0).build());
|
||||
}
|
||||
|
||||
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 " + BuildInfo.get("git_cm_hash"));
|
||||
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) {
|
||||
@@ -80,11 +114,12 @@ public final class OriginBlacklist {
|
||||
}
|
||||
this.plugin.kickPlayer(this.getBlacklistedComponent("kick", blacklisted.getArrayString(),
|
||||
blacklisted.getAltString(), blacklisted.getString(), "not allowed", "not allowed on the server",
|
||||
blacklisted_value, blacklisted.getActionString()), event);
|
||||
blacklisted_value, blacklisted.getActionString(), false), event);
|
||||
this.sendWebhooks(event, blacklisted);
|
||||
final String name = player.getName();
|
||||
if (isNonNull(name)) {
|
||||
this.plugin.log(EnumLogLevel.INFO, "Prevented blacklisted player " + name + " from joining.");
|
||||
this.updateLogFile(event, blacklisted);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,9 +136,12 @@ public final class OriginBlacklist {
|
||||
} else {
|
||||
blacklisted_value = UNKNOWN_STR;
|
||||
}
|
||||
this.plugin.setMOTD(this.getBlacklistedComponent("motd", blacklisted.getArrayString(), blacklisted.getAltString(),
|
||||
blacklisted.getString(), "blacklisted", "blacklisted from the server", blacklisted_value,
|
||||
blacklisted.getActionString()), event);
|
||||
if (this.isMOTDEnabled()) {
|
||||
this.plugin
|
||||
.setMOTD(this.getBlacklistedComponent("motd", blacklisted.getArrayString(), blacklisted.getAltString(),
|
||||
blacklisted.getString(), "blacklisted", "blacklisted from the server", blacklisted_value,
|
||||
blacklisted.getActionString(), true), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +153,22 @@ public final class OriginBlacklist {
|
||||
return this.config.getBoolean("bStats");
|
||||
}
|
||||
|
||||
public final boolean isMOTDEnabled() {
|
||||
return this.config.getBoolean("motd.enabled");
|
||||
}
|
||||
|
||||
public final boolean isWebhooksEnabled() {
|
||||
return this.config.getBoolean("discord.webhook.enabled");
|
||||
}
|
||||
|
||||
public final boolean isLogFileEnabled() {
|
||||
return this.config.getBoolean("logFile");
|
||||
}
|
||||
|
||||
public final boolean isBlacklistAPIEnabled() {
|
||||
return this.config.getBoolean("blacklist_http_api");
|
||||
}
|
||||
|
||||
public final OriginBlacklistConfig getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
@@ -122,19 +176,23 @@ public final class OriginBlacklist {
|
||||
public final void setEaglerMOTD(final Component comp, final OriginBlacklistMOTDEvent event) {
|
||||
final IMOTDConnection conn = event.getEaglerEvent().getMOTDConnection();
|
||||
final List<String> lst = new ArrayList<>();
|
||||
for (String ln : getComponentString(comp).split("\n")) {
|
||||
for (final String ln : getComponentString(comp).split("\n")) {
|
||||
lst.add(ln);
|
||||
}
|
||||
final List<String> pLst = new ArrayList<>();
|
||||
for (final Json5Element ln : this.config.getArray("motd.players.hover").getAsJson5Array()) {
|
||||
pLst.add(getLegacyFromMiniMessage(ln.getAsString().replaceAll("%discord_invite%", this.config.getString("discord.invite"))));
|
||||
}
|
||||
conn.setServerMOTD(lst);
|
||||
conn.setPlayerTotal(0);
|
||||
conn.setPlayerUnlimited();
|
||||
conn.setPlayerList(List.of());
|
||||
conn.setPlayerTotal(this.config.getInteger("motd.players.online"));
|
||||
conn.setPlayerMax(this.config.getInteger("motd.players.max"));
|
||||
conn.setPlayerList(pLst);
|
||||
conn.setServerIcon(this.config.getIconBytes());
|
||||
conn.sendToUser();
|
||||
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")) {
|
||||
this.plugin.runAsync(() -> {
|
||||
this.updateURL = UpdateChecker.checkForUpdates(PLUGIN_REPO, this.plugin.getPluginVersion(),
|
||||
@@ -150,19 +208,20 @@ public final class OriginBlacklist {
|
||||
}
|
||||
}
|
||||
|
||||
public final void updatePlugin(Runnable action1, Runnable action2) {
|
||||
public final void updatePlugin(final Runnable action1, final Runnable action2) {
|
||||
try {
|
||||
final URL url = new URL(this.updateURL);
|
||||
final Path jar = this.plugin.getPluginJarPath();
|
||||
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());
|
||||
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");
|
||||
@@ -177,6 +236,7 @@ public final class OriginBlacklist {
|
||||
}
|
||||
Files.delete(jar);
|
||||
Files.delete(bak);
|
||||
this.jarFile = upd;
|
||||
action1.run();
|
||||
return;
|
||||
} catch (final Throwable t) {
|
||||
@@ -190,7 +250,9 @@ public final class OriginBlacklist {
|
||||
}
|
||||
|
||||
public final void updatePlugin() {
|
||||
this.updatePlugin(() -> {}, () -> {});
|
||||
this.updatePlugin(() -> {
|
||||
}, () -> {
|
||||
});
|
||||
}
|
||||
|
||||
public final EnumBlacklistType testBlacklist(final OPlayer player) {
|
||||
@@ -203,11 +265,14 @@ public final class OriginBlacklist {
|
||||
EnumBlacklistType type = EnumBlacklistType.NONE;
|
||||
|
||||
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()) {
|
||||
if (origin.matches(element.getAsString())) {
|
||||
if (whitelist) type = EnumBlacklistType.NONE;
|
||||
else if (!type.isBlacklisted()) type = EnumBlacklistType.ORIGIN;
|
||||
if (whitelist)
|
||||
type = EnumBlacklistType.NONE;
|
||||
else if (!type.isBlacklisted())
|
||||
type = EnumBlacklistType.ORIGIN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -216,39 +281,49 @@ public final class OriginBlacklist {
|
||||
}
|
||||
|
||||
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")) {
|
||||
if (brand.matches(element.getAsString())) {
|
||||
if (whitelist) type = EnumBlacklistType.NONE;
|
||||
else if (!type.isBlacklisted()) type = EnumBlacklistType.BRAND;
|
||||
if (whitelist)
|
||||
type = EnumBlacklistType.NONE;
|
||||
else if (!type.isBlacklisted())
|
||||
type = EnumBlacklistType.BRAND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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")) {
|
||||
if (name.matches(element.getAsString())) {
|
||||
if (whitelist) type = EnumBlacklistType.NONE;
|
||||
else if (!type.isBlacklisted()) type = EnumBlacklistType.NAME;
|
||||
if (whitelist)
|
||||
type = EnumBlacklistType.NONE;
|
||||
else if (!type.isBlacklisted())
|
||||
type = EnumBlacklistType.NAME;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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")) {
|
||||
try {
|
||||
if ((new IPAddressString(element.getAsString()).toAddress())
|
||||
.contains((new IPAddressString(addr)).toAddress())) {
|
||||
if (whitelist) type = EnumBlacklistType.NONE;
|
||||
else if (!type.isBlacklisted()) type = EnumBlacklistType.ADDR;
|
||||
if (whitelist)
|
||||
type = EnumBlacklistType.NONE;
|
||||
else if (!type.isBlacklisted())
|
||||
type = EnumBlacklistType.ADDR;
|
||||
break;
|
||||
}
|
||||
} catch (final AddressStringException exception) {
|
||||
if (this.isDebugEnabled()) exception.printStackTrace();
|
||||
if (this.isDebugEnabled())
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,10 +331,37 @@ public final class OriginBlacklist {
|
||||
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,
|
||||
final String blockTypeAlt, final String notAllowed, final String notAllowedAlt, final String blockValue,
|
||||
final String action) {
|
||||
final Json5Array arr = this.config.getArray("messages." + type);
|
||||
final String action, final boolean isMOTD) {
|
||||
final Json5Array arr = this.config.getArray(isMOTD ? (type + ".text") : ("messages." + type));
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
if (i > 0)
|
||||
@@ -272,68 +374,74 @@ public final class OriginBlacklist {
|
||||
.replaceAll("%block_type%", blockType)
|
||||
.replaceAll("%not_allowed%", notAllowed)
|
||||
.replaceAll("%not_allowed_alt%", notAllowedAlt)
|
||||
.replaceAll("%blocked_value%", blockValue);
|
||||
.replaceAll("%blocked_value%", blockValue)
|
||||
.replaceAll("%discord_invite%", this.config.getString("discord.invite"));
|
||||
return MiniMessage.miniMessage().deserialize(str);
|
||||
}
|
||||
|
||||
private final void sendWebhooks(final OriginBlacklistLoginEvent event, final EnumBlacklistType type) {
|
||||
if (this.config.getBoolean("discord.enabled")) {
|
||||
if (this.isWebhooksEnabled()) {
|
||||
final OPlayer player = event.getPlayer();
|
||||
final EnumConnectionType connType = event.getConnectionType();
|
||||
final String userAgent;
|
||||
if (connType == EnumConnectionType.EAGLER) {
|
||||
final IEaglerLoginConnection loginConn = event.getEaglerEvent().getLoginConnection();
|
||||
userAgent = loginConn.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT);
|
||||
} else {
|
||||
userAgent = UNKNOWN_STR;
|
||||
}
|
||||
/*
|
||||
* final String userAgent;
|
||||
* 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**→ User Agent:** %s\\n**→ Rewind:** %s\\n**→ Player Type:** %s",
|
||||
"color": 15801922,
|
||||
"fields": [],
|
||||
"footer": {
|
||||
"text": "OriginBlacklist 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": "🌐"
|
||||
"""
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
""",
|
||||
type.getAltString(),
|
||||
player.getName().replaceAll("_", "\\_"),
|
||||
player.getOrigin(),
|
||||
player.getBrand(),
|
||||
this.config.getBoolean("discord.send_ips") ? player.getAddr() : "*\\*CENSORED\\**",
|
||||
player.getPVN(),
|
||||
userAgent,
|
||||
player.isRewind() ? "YES" : "NO",
|
||||
connType.toString(),
|
||||
this.plugin.getPluginVersion(),
|
||||
PLUGIN_REPO,
|
||||
PLUGIN_REPO
|
||||
).getBytes();
|
||||
],
|
||||
"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(() -> {
|
||||
@@ -371,7 +479,28 @@ public final class OriginBlacklist {
|
||||
} 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) {
|
||||
@@ -393,4 +522,10 @@ public final class OriginBlacklist {
|
||||
public static final boolean isNonNull(final String str) {
|
||||
return str != null && !str.isEmpty() && !str.isBlank() && !str.equals("null");
|
||||
}
|
||||
|
||||
public static final class BSTATS {
|
||||
public static final int VELOCITY = 29033;
|
||||
public static final int BUNGEE = 29034;
|
||||
public static final int BUKKIT = 29035;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,20 +24,21 @@ public class OriginBlacklistCommand implements ICommand {
|
||||
if (ctx.hasPermission("originblacklist.command")) {
|
||||
if (args.length > 0) {
|
||||
final OriginBlacklistConfig config = this.plugin.getConfig();
|
||||
final String command = args[0].toLowerCase();
|
||||
final String argA = args.length > 1 ? args[1].toLowerCase() : null;
|
||||
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".equals(command);
|
||||
final boolean remove = "remove".equals(command);
|
||||
if ("reload".equals(command)) {
|
||||
final boolean add = "add".equalsIgnoreCase(command);
|
||||
final boolean remove = "remove".equalsIgnoreCase(command);
|
||||
if ("reload".equalsIgnoreCase(command)) {
|
||||
if (ctx.hasPermission("originblacklist.command.reload")) {
|
||||
config.reloadConfig();
|
||||
this.plugin.handleReload();
|
||||
ctx.reply("<green>Configuration Reloaded</green>");
|
||||
} else {
|
||||
ctx.reply(NO_PERMISSION);
|
||||
}
|
||||
} else if ("update".equals(command)) {
|
||||
} else if ("update".equalsIgnoreCase(command)) {
|
||||
if (ctx.hasPermission("originblacklist.command.update")) {
|
||||
ctx.reply("<aqua>Checking for updates...</aqua>");
|
||||
this.plugin.checkForUpdates(() -> {
|
||||
@@ -57,13 +58,13 @@ public class OriginBlacklistCommand implements ICommand {
|
||||
if ((add && ctx.hasPermission("originblacklist.command.add"))
|
||||
|| (remove && ctx.hasPermission("originblacklist.command.add"))) {
|
||||
final String arrName;
|
||||
if ("origin".equals(argA)) {
|
||||
if ("origin".equalsIgnoreCase(argA)) {
|
||||
arrName = "origins";
|
||||
} else if ("brand".equals(argA)) {
|
||||
} else if ("brand".equalsIgnoreCase(argA)) {
|
||||
arrName = "brands";
|
||||
} else if ("name".equals(argA)) {
|
||||
} else if ("name".equalsIgnoreCase(argA)) {
|
||||
arrName = "player_names";
|
||||
} else if ("ip".equals(argA)) {
|
||||
} else if ("ip".equalsIgnoreCase(argA)) {
|
||||
arrName = "ip_addresses";
|
||||
} else {
|
||||
arrName = null;
|
||||
@@ -94,7 +95,7 @@ public class OriginBlacklistCommand implements ICommand {
|
||||
} else {
|
||||
ctx.reply(NO_PERMISSION);
|
||||
}
|
||||
} else if ("test".equals(command) && OriginBlacklist.isNonNull(argA)) {
|
||||
} 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>");
|
||||
@@ -104,7 +105,7 @@ public class OriginBlacklistCommand implements ICommand {
|
||||
} else {
|
||||
ctx.reply(NO_PERMISSION);
|
||||
}
|
||||
} else if ("list".equals(command)) {
|
||||
} else if ("list".equalsIgnoreCase(command)) {
|
||||
if (ctx.hasPermission("originblacklist.command.list")) {
|
||||
ctx.reply("<aqua>Blacklist:</aqua>");
|
||||
ctx.reply("<gold> - Origins:</gold>");
|
||||
@@ -148,14 +149,14 @@ public class OriginBlacklistCommand implements ICommand {
|
||||
ctx.reply("<aqua>Commands:</aqua>");
|
||||
ctx.reply("<gray> - /originblacklist reload</gray>");
|
||||
ctx.reply("<gray> - /originblacklist update</gray>");
|
||||
ctx.reply("<gray> - /originblacklist add <origin/brand/name/ip> <argB></gray>");
|
||||
ctx.reply("<gray> - /originblacklist remove <origin/brand/name/ip> <argB></gray>");
|
||||
ctx.reply("<gray> - /originblacklist test <argB></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>");
|
||||
}
|
||||
|
||||
private final boolean isBlacklisted(final String str) {
|
||||
final OPlayer player = new OPlayer(null, str, null, str, str, -1);
|
||||
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;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -12,6 +11,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
@@ -22,6 +22,9 @@ import de.marhali.json5.Json5Object;
|
||||
import de.marhali.json5.Json5Primitive;
|
||||
|
||||
public final class OriginBlacklistConfig {
|
||||
public static final Json5Object DEFAULT_CONFIG = getDefaultConfig();
|
||||
public static final int LATEST_CONFIG_VERSION = 2;
|
||||
|
||||
private final Json5 json5;
|
||||
private final File file;
|
||||
private final Path filePath;
|
||||
@@ -31,7 +34,7 @@ public final class OriginBlacklistConfig {
|
||||
private byte[] icon;
|
||||
private String icon64;
|
||||
|
||||
public OriginBlacklistConfig(final IOriginBlacklistPlugin plugin) {
|
||||
public OriginBlacklistConfig(final OriginBlacklist plugin) {
|
||||
this.json5 = Json5.builder(builder -> builder
|
||||
.quoteless()
|
||||
.quoteSingle()
|
||||
@@ -39,10 +42,10 @@ public final class OriginBlacklistConfig {
|
||||
.writeComments()
|
||||
.prettyPrinting()
|
||||
.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.iconFile = new File(dir + "/blacklisted.png");
|
||||
this.iconFile = new File(plugin.getDataDir() + "/blacklisted.png");
|
||||
this.iconPath = iconFile.toPath();
|
||||
this.loadConfig();
|
||||
}
|
||||
@@ -50,19 +53,19 @@ public final class OriginBlacklistConfig {
|
||||
private final void loadConfig() {
|
||||
try {
|
||||
this.reloadConfigUnsafe();
|
||||
this.reloadIconImage();
|
||||
} catch (final IOException exception) {
|
||||
throw new RuntimeException("Failed to load config.", exception);
|
||||
}
|
||||
this.reloadIconImage();
|
||||
}
|
||||
|
||||
public final void reloadConfig() {
|
||||
try {
|
||||
this.reloadConfigUnsafe();
|
||||
this.reloadIconImage();
|
||||
} catch (final IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
this.reloadIconImage();
|
||||
}
|
||||
|
||||
private final void reloadConfigUnsafe() throws IOException {
|
||||
@@ -71,16 +74,15 @@ public final class OriginBlacklistConfig {
|
||||
Json5Element parsed = this.json5.parse(text);
|
||||
if (parsed instanceof Json5Object) {
|
||||
this.config = (Json5Object) parsed;
|
||||
if (merge(this.config, getDefaultConfig())) {
|
||||
this.saveConfig();
|
||||
}
|
||||
this.config = OriginBlacklistConfigTransformer.transformConfig(this.config);
|
||||
merge(this.config, DEFAULT_CONFIG);
|
||||
} else {
|
||||
throw new IOException("Config must be an object!");
|
||||
}
|
||||
} else {
|
||||
this.config = getDefaultConfig();
|
||||
this.saveConfig();
|
||||
this.config = DEFAULT_CONFIG;
|
||||
}
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
private final void reloadIconImage() {
|
||||
@@ -95,10 +97,10 @@ public final class OriginBlacklistConfig {
|
||||
final BufferedImage img = ImageIO.read(iconFile);
|
||||
|
||||
if (img.getWidth() == 64 && img.getHeight() == 64) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(img, "png", baos);
|
||||
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 x = 0; x < 64; x++) {
|
||||
int pixel = img.getRGB(x, y);
|
||||
@@ -207,7 +209,6 @@ public final class OriginBlacklistConfig {
|
||||
} else {
|
||||
element = null;
|
||||
}
|
||||
|
||||
if (element == null) {
|
||||
break;
|
||||
}
|
||||
@@ -255,7 +256,7 @@ public final class OriginBlacklistConfig {
|
||||
private static final Json5Object getDefaultConfig() {
|
||||
final Json5Object obj = new Json5Object();
|
||||
addJSONObj(obj, "debug", Json5Primitive.fromBoolean(false), null);
|
||||
final Json5Object mobj = new Json5Object();
|
||||
final Json5Object mObj = new Json5Object();
|
||||
final Json5Array kick = new Json5Array();
|
||||
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>");
|
||||
@@ -263,19 +264,30 @@ public final class OriginBlacklistConfig {
|
||||
kick.add("%action%");
|
||||
kick.add("");
|
||||
kick.add("<aqua>Think this is a mistake? Join our discord:</aqua>");
|
||||
kick.add("<blue>discord.gg/changethisintheconfig</blue>");
|
||||
addJSONObj(mobj, "kick", kick, null);
|
||||
final Json5Array motd = new Json5Array();
|
||||
motd.add("<red>This %block_type% is %not_allowed%!</red>");
|
||||
motd.add("<dark_gray>»</dark_gray> <gray>%blocked_value%</gray>");
|
||||
addJSONObj(mobj, "motd", motd, null);
|
||||
kick.add("<blue>%discord_invite%</blue>");
|
||||
addJSONObj(mObj, "kick", kick, null);
|
||||
final Json5Object actions = new Json5Object();
|
||||
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("ip_address", Json5Primitive.fromString("<gold>Please contact staff for assistance.</gold>"));
|
||||
addJSONObj(mobj, "actions", actions, null);
|
||||
addJSONObj(obj, "messages", mobj, null);
|
||||
final Json5Object bobj = new Json5Object();
|
||||
addJSONObj(mObj, "actions", actions, null);
|
||||
addJSONObj(obj, "messages", mObj, null);
|
||||
final Json5Object nObj = new Json5Object();
|
||||
addJSONObj(nObj, "enabled", Json5Primitive.fromBoolean(true), null);
|
||||
final Json5Array mArr = new Json5Array();
|
||||
mArr.add("<red>This %block_type% is %not_allowed%!</red>");
|
||||
mArr.add("<dark_gray>»</dark_gray> <gray>%blocked_value%</gray>");
|
||||
addJSONObj(nObj, "text", mArr, null);
|
||||
final Json5Object mPlayers = new Json5Object();
|
||||
addJSONObj(mPlayers, "online", Json5Primitive.fromNumber(0), null);
|
||||
addJSONObj(mPlayers, "max", Json5Primitive.fromNumber(0), null);
|
||||
final Json5Array hArr = new Json5Array();
|
||||
hArr.add("<blue>Join our discord</blue>");
|
||||
hArr.add("<blue>%discord_invite%</blue>");
|
||||
addJSONObj(mPlayers, "hover", hArr, null);
|
||||
addJSONObj(nObj, "players", mPlayers, null);
|
||||
addJSONObj(obj, "motd", nObj, null);
|
||||
final Json5Object bObj = new Json5Object();
|
||||
final Json5Array origins = new Json5Array();
|
||||
origins.add(".*eaglerhackedclients\\.vercel\\.app.*");
|
||||
origins.add(".*eaglerhacks\\.github\\.io.*");
|
||||
@@ -287,57 +299,195 @@ public final class OriginBlacklistConfig {
|
||||
origins.add(".*uec\\.vercel\\.app.*");
|
||||
origins.add(".*valux-game\\.github\\.io.*");
|
||||
origins.add(".*project516\\.dev.*");
|
||||
addJSONObj(bobj, "origins", origins, null);
|
||||
addJSONObj(bObj, "origins", origins, null);
|
||||
final Json5Array brands = new Json5Array();
|
||||
brands.add(".*dragonx.*");
|
||||
brands.add(".*piclient.*");
|
||||
brands.add(".*justin.*");
|
||||
brands.add(".*wurstx.*");
|
||||
brands.add(".*moonlight.*");
|
||||
addJSONObj(bobj, "brands", brands, null);
|
||||
addJSONObj(bObj, "brands", brands, null);
|
||||
final Json5Array players = new Json5Array();
|
||||
players.add("Admin");
|
||||
addJSONObj(bobj, "player_names", players, null);
|
||||
addJSONObj(bObj, "player_names", players, null);
|
||||
final Json5Array ips = new Json5Array();
|
||||
ips.add("192.0.2.0/24");
|
||||
addJSONObj(bobj, "ip_addresses", ips, null);
|
||||
addJSONObj(obj, "blacklist", bobj, null);
|
||||
final Json5Object dobj = new Json5Object();
|
||||
addJSONObj(dobj, "enabled", Json5Primitive.fromBoolean(false), null);
|
||||
addJSONObj(dobj, "webhook_urls", new Json5Array(), null);
|
||||
addJSONObj(dobj, "send_ips", Json5Primitive.fromBoolean(true), null);
|
||||
addJSONObj(obj, "discord", dobj, null);
|
||||
final Json5Object uobj = new Json5Object();
|
||||
addJSONObj(uobj, "enabled", Json5Primitive.fromBoolean(true), null);
|
||||
addJSONObj(uobj, "allow_snapshots", Json5Primitive.fromBoolean(false), null);
|
||||
addJSONObj(uobj, "check_timer", Json5Primitive.fromNumber(3600), null);
|
||||
addJSONObj(uobj, "auto_update", Json5Primitive.fromBoolean(true), null);
|
||||
addJSONObj(obj, "update_checker", uobj, null);
|
||||
addJSONObj(bObj, "ip_addresses", ips, null);
|
||||
addJSONObj(obj, "blacklist", bObj, null);
|
||||
final Json5Object dObj = new Json5Object();
|
||||
addJSONObj(dObj, "invite", Json5Primitive.fromString("discord.gg/changeme"), null);
|
||||
final Json5Object webhook = new Json5Object();
|
||||
addJSONObj(webhook, "enabled", Json5Primitive.fromBoolean(false), null);
|
||||
addJSONObj(webhook, "webhook_urls", new Json5Array(), null);
|
||||
addJSONObj(webhook, "send_ips", Json5Primitive.fromBoolean(true), null);
|
||||
addJSONObj(dObj, "webhook", webhook, null);
|
||||
addJSONObj(obj, "discord", dObj, null);
|
||||
final Json5Object uObj = new Json5Object();
|
||||
addJSONObj(uObj, "enabled", Json5Primitive.fromBoolean(true), null);
|
||||
addJSONObj(uObj, "allow_snapshots", Json5Primitive.fromBoolean(false), 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, "config_version", Json5Primitive.fromNumber(1), "DO NOT CHANGE");
|
||||
addJSONObj(obj, "logFile", Json5Primitive.fromBoolean(true), null);
|
||||
addJSONObj(obj, "config_version", Json5Primitive.fromNumber(LATEST_CONFIG_VERSION), "DO NOT CHANGE");
|
||||
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;
|
||||
|
||||
for (String key : b.keySet()) {
|
||||
Json5Element element = b.get(key);
|
||||
if (!a.has(key)) {
|
||||
a.add(key, element.deepCopy());
|
||||
changed = true;
|
||||
} else {
|
||||
final Json5Element _element = a.get(key);
|
||||
if (_element instanceof Json5Object objA && element instanceof Json5Object objB) {
|
||||
if (merge(objA, objB)) {
|
||||
for (final String key : bObj.keySet()) {
|
||||
final Json5Element dv = bObj.get(key);
|
||||
if (aObj.has(key)) {
|
||||
final Json5Element v = aObj.get(key);
|
||||
if (dv instanceof Json5Object) {
|
||||
if (v instanceof Json5Object) {
|
||||
final boolean c = merge((Json5Object) v, (Json5Object) dv);
|
||||
ret.add(key, (Json5Object) v);
|
||||
if (c) {
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
ret.add(key, dv.deepCopy());
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package xyz.webmc.originblacklist.base.config;
|
||||
|
||||
import de.marhali.json5.Json5Array;
|
||||
import de.marhali.json5.Json5Object;
|
||||
import de.marhali.json5.Json5Primitive;
|
||||
|
||||
public final class OriginBlacklistConfigTransformer {
|
||||
public static final Json5Object transformConfig(final Json5Object config) {
|
||||
final Json5Object obj = config.deepCopy();
|
||||
final int ver = obj.get("config_version").getAsInt();
|
||||
if (ver <= 1) {
|
||||
final Json5Object mObj = obj.get("messages").getAsJson5Object().deepCopy();
|
||||
final Json5Array motd = mObj.get("motd").getAsJson5Array().deepCopy();
|
||||
mObj.remove("motd");
|
||||
final Json5Object nObj = new Json5Object();
|
||||
nObj.add("text", motd);
|
||||
obj.remove("messages");
|
||||
obj.add("messages", mObj);
|
||||
obj.add("motd", nObj);
|
||||
final Json5Object dObj = obj.get("discord").getAsJson5Object().deepCopy();
|
||||
final Json5Primitive wEnabled = dObj.get("enabled").getAsJson5Primitive();
|
||||
final Json5Array wURLS = dObj.get("webhook_urls").getAsJson5Array().deepCopy();
|
||||
final Json5Primitive wAddrs = dObj.get("send_ips").getAsJson5Primitive();
|
||||
dObj.remove("enabled");
|
||||
dObj.remove("webhook_urls");
|
||||
dObj.remove("send_ips");
|
||||
final Json5Object oObj = new Json5Object();
|
||||
oObj.add("enabled", wEnabled);
|
||||
oObj.add("webhook_urls", wURLS);
|
||||
oObj.add("send_ips", wAddrs);
|
||||
dObj.add("webhook", oObj);
|
||||
obj.remove("discord");
|
||||
obj.add("discord", dObj);
|
||||
}
|
||||
obj.remove("config_version");
|
||||
obj.add("config_version", Json5Primitive.fromNumber(OriginBlacklistConfig.LATEST_CONFIG_VERSION));
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -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,5 @@
|
||||
package xyz.webmc.originblacklist.base.util;
|
||||
|
||||
public final class EaglerEventPriority {
|
||||
public static final int EAGLER_MOTD_EVENT = 100;
|
||||
}
|
||||
@@ -8,8 +8,10 @@ import java.nio.file.Path;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import org.semver4j.Semver;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public interface IOriginBlacklistPlugin {
|
||||
public String getPluginId();
|
||||
|
||||
@@ -17,6 +19,8 @@ public interface IOriginBlacklistPlugin {
|
||||
|
||||
public Path getPluginJarPath();
|
||||
|
||||
public IEaglerXServerAPI getEaglerAPI();
|
||||
|
||||
public void log(final EnumLogLevel level, final String txt);
|
||||
|
||||
public void kickPlayer(final Component txt, final OriginBlacklistLoginEvent event);
|
||||
|
||||
@@ -16,16 +16,18 @@ public final class OPlayer {
|
||||
private final String name;
|
||||
private final UUID uuid;
|
||||
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,
|
||||
final String brand, final int pvn) {
|
||||
final String brand, final String vhost, final int pvn) {
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
if (conn != null) {
|
||||
this.origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||
this.addr = formatSocketAddress(conn.getSocketAddress());
|
||||
this.vhost = conn.isWebSocketSecure() ? "wss://" : "ws://" + conn.getWebSocketHost();
|
||||
if (conn instanceof IEaglerLoginConnection) {
|
||||
final IEaglerLoginConnection loginConn = (IEaglerLoginConnection) conn;
|
||||
this.brand = loginConn.getEaglerBrandString();
|
||||
@@ -40,13 +42,14 @@ public final class OPlayer {
|
||||
this.origin = OriginBlacklist.UNKNOWN_STR;
|
||||
this.addr = formatIPAddress(addr);
|
||||
this.brand = brand;
|
||||
this.vhost = vhost;
|
||||
this.rewind = false;
|
||||
this.pvn = pvn;
|
||||
}
|
||||
}
|
||||
|
||||
public OPlayer(final IEaglerConnection conn, final String name, final UUID uuid) {
|
||||
this(conn, name, uuid, null, null, -1);
|
||||
this(conn, name, uuid, null, null, null, -1);
|
||||
}
|
||||
|
||||
public final String getOrigin() {
|
||||
@@ -69,6 +72,10 @@ public final class OPlayer {
|
||||
return this.brand;
|
||||
}
|
||||
|
||||
public final String getVHost() {
|
||||
return this.vhost;
|
||||
}
|
||||
|
||||
public final boolean isRewind() {
|
||||
return this.rewind;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public final class UpdateChecker {
|
||||
String comm;
|
||||
try {
|
||||
comm = ver.getBuild().get(0).trim();
|
||||
} catch (Throwable t) {
|
||||
} catch (final Throwable t) {
|
||||
comm = "";
|
||||
}
|
||||
if (ver.isGreaterThan(currentVersion) || (allowSnapshots && currentVersion.diff(ver) == VersionDiff.BUILD
|
||||
|
||||
@@ -45,7 +45,6 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
||||
private boolean papiPlaceholdersEnabled;
|
||||
private Object papi;
|
||||
private OriginBlacklist blacklist;
|
||||
private IEaglerXServerAPI eaglerAPI;
|
||||
private Metrics metrics;
|
||||
|
||||
private CachedServerIcon iconCache;
|
||||
@@ -73,17 +72,16 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
||||
this.papi = null;
|
||||
}
|
||||
this.blacklist = new OriginBlacklist(this);
|
||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
||||
this.getCommand("originblacklist").setExecutor(new OriginBlacklistCommandBukkit(this.blacklist));
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
this.blacklist.init();
|
||||
if (this.blacklist.isMetricsEnabled()) {
|
||||
this.metrics = new Metrics(this, OriginBlacklist.BSTATS_ID);
|
||||
this.metrics = new Metrics(this, OriginBlacklist.BSTATS.BUKKIT);
|
||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||
final Map<String, Integer> playerMap = new HashMap<>();
|
||||
|
||||
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";
|
||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||
}
|
||||
@@ -93,6 +91,11 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.blacklist.shutdown();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
||||
@@ -107,15 +110,14 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public final void onJavaLogin(final AsyncPlayerPreLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(null, event.getName(), event.getUniqueId(),
|
||||
event.getAddress() != null ? event.getAddress().toString() : null, OriginBlacklist.UNKNOWN_STR, -1);
|
||||
final OPlayer player = new OPlayer(null, event.getName(), event.getUniqueId(), event.getAddress().toString(),
|
||||
OriginBlacklist.UNKNOWN_STR, OriginBlacklist.UNKNOWN_STR, -1);
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onJavaMOTD(final ServerListPingEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null,
|
||||
event.getAddress() != null ? event.getAddress().toString() : null, null, -1);
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getAddress().toString(), null, null, -1);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@@ -134,6 +136,11 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
||||
return Paths.get(this.getFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IEaglerXServerAPI getEaglerAPI() {
|
||||
return EaglerXServerAPI.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void log(final EnumLogLevel level, final String txt) {
|
||||
if (level == EnumLogLevel.WARN) {
|
||||
|
||||
@@ -5,11 +5,13 @@ import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||
import xyz.webmc.originblacklist.base.util.EaglerEventPriority;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
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;
|
||||
@@ -23,6 +25,7 @@ import net.lax1dude.eaglercraft.backend.server.api.bungee.event.EaglercraftLogin
|
||||
import net.lax1dude.eaglercraft.backend.server.api.bungee.event.EaglercraftMOTDEvent;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
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.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.event.PreLoginEvent;
|
||||
@@ -41,7 +44,6 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
private boolean papiPlaceholdersEnabled;
|
||||
private Object papi;
|
||||
private OriginBlacklist blacklist;
|
||||
private IEaglerXServerAPI eaglerAPI;
|
||||
private Metrics metrics;
|
||||
|
||||
@Override
|
||||
@@ -69,17 +71,17 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
this.papi = null;
|
||||
}
|
||||
this.blacklist = new OriginBlacklist(this);
|
||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
||||
this.getProxy().getPluginManager().registerCommand(this, new OriginBlacklistCommandBungee(this, this.blacklist, "originblacklist"));
|
||||
this.getProxy().getPluginManager().registerCommand(this,
|
||||
new OriginBlacklistCommandBungee(this, this.blacklist, "originblacklist"));
|
||||
this.getProxy().getPluginManager().registerListener(this, this);
|
||||
this.blacklist.init();
|
||||
if (this.blacklist.isMetricsEnabled()) {
|
||||
this.metrics = new Metrics(this, OriginBlacklist.BSTATS_ID);
|
||||
this.metrics = new Metrics(this, OriginBlacklist.BSTATS.BUNGEE);
|
||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||
final Map<String, Integer> playerMap = new HashMap<>();
|
||||
|
||||
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";
|
||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||
}
|
||||
@@ -89,13 +91,18 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.blacklist.shutdown();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
@EventHandler(priority = EaglerEventPriority.EAGLER_MOTD_EVENT)
|
||||
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||
@@ -103,21 +110,30 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onJavaLogin(final PostLoginEvent event) {
|
||||
final PendingConnection conn = event.getPlayer().getPendingConnection();
|
||||
final InetSocketAddress vhost = conn.getVirtualHost();
|
||||
final ProxiedPlayer aPlayer = event.getPlayer();
|
||||
final OPlayer bPlayer = new OPlayer(null, aPlayer.getName(), aPlayer.getUniqueId(),
|
||||
aPlayer.getAddress().toString(), aPlayer.getClientBrand(), event.getPlayer().getPendingConnection().getVersion());
|
||||
aPlayer.getAddress().toString(), aPlayer.getClientBrand(), vhost.getHostString() + vhost.getPort(),
|
||||
conn.getVersion());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onJavaHandshake(final PreLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getAddress().toString(), OriginBlacklist.UNKNOWN_STR, event.getConnection().getVersion());
|
||||
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));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getAddress().toString(), null, -1);
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -136,6 +152,11 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
return Paths.get(this.getFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IEaglerXServerAPI getEaglerAPI() {
|
||||
return EaglerXServerAPI.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void log(final EnumLogLevel level, final String txt) {
|
||||
if (level == EnumLogLevel.WARN) {
|
||||
|
||||
@@ -5,11 +5,13 @@ import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||
import xyz.webmc.originblacklist.base.util.EaglerEventPriority;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
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;
|
||||
@@ -24,7 +26,9 @@ import com.velocitypowered.api.event.connection.PreLoginEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerClientBrandEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.proxy.InboundConnection;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
@@ -51,7 +55,6 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
private boolean papiPlaceholdersEnabled;
|
||||
private Object papi;
|
||||
private OriginBlacklist blacklist;
|
||||
private IEaglerXServerAPI eaglerAPI;
|
||||
private Metrics metrics;
|
||||
|
||||
@Inject
|
||||
@@ -86,16 +89,15 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
this.papi = null;
|
||||
}
|
||||
this.blacklist = new OriginBlacklist(this);
|
||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
||||
this.proxy.getCommandManager().register("originblacklist", new OriginBlacklistCommandVelocity(this.blacklist));
|
||||
this.blacklist.init();
|
||||
if (this.blacklist.isMetricsEnabled()) {
|
||||
this.metrics = this.metricsFactory.make(this, OriginBlacklist.BSTATS_ID);
|
||||
this.metrics = this.metricsFactory.make(this, OriginBlacklist.BSTATS.VELOCITY);
|
||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||
final Map<String, Integer> playerMap = new HashMap<>();
|
||||
|
||||
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";
|
||||
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)
|
||||
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
@Subscribe(priority = EaglerEventPriority.EAGLER_MOTD_EVENT, order = PostOrder.LAST)
|
||||
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||
@@ -119,24 +126,30 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
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(),
|
||||
event.getConnection().getRemoteAddress().toString(), OriginBlacklist.UNKNOWN_STR,
|
||||
event.getConnection().getProtocolVersion().getProtocol());
|
||||
conn.getRemoteAddress().toString(), OriginBlacklist.UNKNOWN_STR, vhost.getHostString() + vhost.getPort(),
|
||||
conn.getProtocolVersion().getProtocol());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
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(),
|
||||
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));
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getRemoteAddress().getHostString(),
|
||||
final InboundConnection conn = event.getConnection();
|
||||
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));
|
||||
}
|
||||
@@ -160,6 +173,11 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IEaglerXServerAPI getEaglerAPI() {
|
||||
return EaglerXServerAPI.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void log(final EnumLogLevel level, final String txt) {
|
||||
if (level == EnumLogLevel.WARN) {
|
||||
|
||||
Reference in New Issue
Block a user