mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 19:17:40 +00:00
Compare commits
5 Commits
v2.0.6+c43
...
v2.0.7+1cd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cd60a4dba | ||
|
|
ebcae682aa | ||
|
|
f22e800439 | ||
|
|
f0274ff4d4 | ||
|
|
12f9d669b4 |
@@ -15,6 +15,7 @@
|
|||||||
- [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] Ingame blacklist management commands
|
||||||
|
- [x] Blacklist sharing via EaglerXServer routes
|
||||||
- [x] Reverse blacklist (whitelist)
|
- [x] Reverse blacklist (whitelist)
|
||||||
- [ ] Subscribe to an auto-updating blacklist
|
- [ ] Subscribe to an auto-updating blacklist
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ val PLUGIN_NAME = "OriginBlacklist"
|
|||||||
val PLUGIN_IDEN = "originblacklist"
|
val PLUGIN_IDEN = "originblacklist"
|
||||||
val PLUGIN_DOMN = "xyz.webmc.$PLUGIN_IDEN"
|
val PLUGIN_DOMN = "xyz.webmc.$PLUGIN_IDEN"
|
||||||
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
||||||
val PLUGIN_VERS = "2.0.6"
|
val PLUGIN_VERS = "2.0.7"
|
||||||
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
||||||
val PLUGIN_DEPA = listOf("EaglercraftXServer")
|
val PLUGIN_DEPA = listOf("EaglercraftXServer")
|
||||||
val PLUGIN_DEPB = listOf("EaglercraftXServer")
|
val PLUGIN_DEPB = listOf("EaglercraftXServer")
|
||||||
|
|||||||
@@ -6,7 +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.http.OriginBlacklistRequestHandler;
|
||||||
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;
|
||||||
@@ -38,9 +38,11 @@ import inet.ipaddr.IPAddressString;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
||||||
import org.semver4j.Semver;
|
import org.semver4j.Semver;
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes" })
|
||||||
public final class OriginBlacklist {
|
public final class OriginBlacklist {
|
||||||
private static final String COMMIT_L = BuildInfo.get("git_cm_hash");
|
private static final String COMMIT_L = BuildInfo.get("git_cm_hash");
|
||||||
private static final String COMMIT_S = COMMIT_L.substring(0, 8);
|
private static final String COMMIT_S = COMMIT_L.substring(0, 8);
|
||||||
@@ -50,11 +52,9 @@ public final class OriginBlacklist {
|
|||||||
public static final String UNKNOWN_STR = "UNKNOWN";
|
public static final String UNKNOWN_STR = "UNKNOWN";
|
||||||
public static final String CENSORED_STR = "CENSORED";
|
public static final String CENSORED_STR = "CENSORED";
|
||||||
public static final String PLUGIN_REPO = "WebMCDevelopment/originblacklist";
|
public static final String PLUGIN_REPO = "WebMCDevelopment/originblacklist";
|
||||||
public static final int BSTATS_ID = 28776;
|
|
||||||
|
|
||||||
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 final Json5 json5;
|
||||||
private String updateURL;
|
private String updateURL;
|
||||||
private Path jarFile;
|
private Path jarFile;
|
||||||
@@ -62,7 +62,6 @@ public final class OriginBlacklist {
|
|||||||
public OriginBlacklist(final IOriginBlacklistPlugin plugin) {
|
public OriginBlacklist(final IOriginBlacklistPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.config = new OriginBlacklistConfig(this);
|
this.config = new OriginBlacklistConfig(this);
|
||||||
this.http = new OriginBlacklistHTTPServer(this);
|
|
||||||
this.json5 = Json5.builder(builder -> builder.prettyPrinting().indentFactor(0).build());
|
this.json5 = Json5.builder(builder -> builder.prettyPrinting().indentFactor(0).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,8 +70,8 @@ public final class OriginBlacklist {
|
|||||||
this.plugin.scheduleRepeat(() -> {
|
this.plugin.scheduleRepeat(() -> {
|
||||||
this.checkForUpdates();
|
this.checkForUpdates();
|
||||||
}, this.config.getInteger("update_checker.check_timer"), TimeUnit.SECONDS);
|
}, this.config.getInteger("update_checker.check_timer"), TimeUnit.SECONDS);
|
||||||
if (this.isHTTPServerEnabled()) {
|
if (this.isBlacklistAPIEnabled()) {
|
||||||
this.http.start();
|
OriginBlacklistRequestHandler.register(this);
|
||||||
}
|
}
|
||||||
this.plugin.log(EnumLogLevel.INFO, "Initialized Plugin");
|
this.plugin.log(EnumLogLevel.INFO, "Initialized Plugin");
|
||||||
this.plugin.log(EnumLogLevel.DEBUG, "Commit " + COMMIT_L);
|
this.plugin.log(EnumLogLevel.DEBUG, "Commit " + COMMIT_L);
|
||||||
@@ -80,15 +79,20 @@ public final class OriginBlacklist {
|
|||||||
|
|
||||||
public final void shutdown() {
|
public final void shutdown() {
|
||||||
this.plugin.log(EnumLogLevel.INFO, "Shutting down...");
|
this.plugin.log(EnumLogLevel.INFO, "Shutting down...");
|
||||||
this.http.stop();
|
if (this.isBlacklistAPIEnabled()) {
|
||||||
|
OriginBlacklistRequestHandler.unRegister(this);
|
||||||
|
}
|
||||||
this.plugin.shutdown();
|
this.plugin.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void handleReload() {
|
public final void handleReload() {
|
||||||
if (this.isHTTPServerEnabled()) {
|
try {
|
||||||
this.http.start();
|
if (this.isBlacklistAPIEnabled()) {
|
||||||
|
OriginBlacklistRequestHandler.register(this);
|
||||||
} else {
|
} else {
|
||||||
this.http.stop();
|
OriginBlacklistRequestHandler.unRegister(this);
|
||||||
|
}
|
||||||
|
} catch (final Throwable t) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,8 +154,8 @@ public final class OriginBlacklist {
|
|||||||
return this.config.getBoolean("logFile");
|
return this.config.getBoolean("logFile");
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isHTTPServerEnabled() {
|
public final boolean isBlacklistAPIEnabled() {
|
||||||
return this.config.getBoolean("blacklist_http_share.enabled");
|
return this.config.getBoolean("blacklist_http_api");
|
||||||
}
|
}
|
||||||
|
|
||||||
public final OriginBlacklistConfig getConfig() {
|
public final OriginBlacklistConfig getConfig() {
|
||||||
@@ -316,6 +320,7 @@ public final class OriginBlacklist {
|
|||||||
try {
|
try {
|
||||||
final Json5Object obj = new Json5Object();
|
final Json5Object obj = new Json5Object();
|
||||||
obj.addProperty("plugin_version", this.plugin.getPluginVersion().getVersion());
|
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("blacklist_to_whitelist", this.config.getBoolean("blacklist_to_whitelist"));
|
||||||
obj.addProperty("block_undefined_origin", this.config.getBoolean("block_undefined_origin"));
|
obj.addProperty("block_undefined_origin", this.config.getBoolean("block_undefined_origin"));
|
||||||
final Json5Object bObj = new Json5Object();
|
final Json5Object bObj = new Json5Object();
|
||||||
@@ -334,6 +339,10 @@ public final class OriginBlacklist {
|
|||||||
return "plugins/" + plugin.getPluginId();
|
return "plugins/" + plugin.getPluginId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final IEaglerXServerAPI getEaglerAPI() {
|
||||||
|
return this.plugin.getEaglerAPI();
|
||||||
|
}
|
||||||
|
|
||||||
private final Component getBlacklistedComponent(final String type, final String id, final String blockType,
|
private final Component getBlacklistedComponent(final String type, final String id, final String blockType,
|
||||||
final String blockTypeAlt, final String notAllowed, final String notAllowedAlt, final String blockValue,
|
final String blockTypeAlt, final String notAllowed, final String notAllowedAlt, final String blockValue,
|
||||||
final String action) {
|
final String action) {
|
||||||
@@ -493,4 +502,10 @@ public final class OriginBlacklist {
|
|||||||
public static final boolean isNonNull(final String str) {
|
public static final boolean isNonNull(final String str) {
|
||||||
return str != null && !str.isEmpty() && !str.isBlank() && !str.equals("null");
|
return str != null && !str.isEmpty() && !str.isBlank() && !str.equals("null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class BSTATS {
|
||||||
|
public static final int VELOCITY = 29033;
|
||||||
|
public static final int BUNGEE = 29034;
|
||||||
|
public static final int BUKKIT = 29035;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
@@ -21,6 +22,8 @@ import de.marhali.json5.Json5Object;
|
|||||||
import de.marhali.json5.Json5Primitive;
|
import de.marhali.json5.Json5Primitive;
|
||||||
|
|
||||||
public final class OriginBlacklistConfig {
|
public final class OriginBlacklistConfig {
|
||||||
|
private static final Json5Object DEFAULT_CONFIG = getDefaultConfig();
|
||||||
|
|
||||||
private final Json5 json5;
|
private final Json5 json5;
|
||||||
private final File file;
|
private final File file;
|
||||||
private final Path filePath;
|
private final Path filePath;
|
||||||
@@ -70,16 +73,14 @@ public final class OriginBlacklistConfig {
|
|||||||
Json5Element parsed = this.json5.parse(text);
|
Json5Element parsed = this.json5.parse(text);
|
||||||
if (parsed instanceof Json5Object) {
|
if (parsed instanceof Json5Object) {
|
||||||
this.config = (Json5Object) parsed;
|
this.config = (Json5Object) parsed;
|
||||||
if (merge(this.config, getDefaultConfig())) {
|
merge(this.config, DEFAULT_CONFIG);
|
||||||
this.saveConfig();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Config must be an object!");
|
throw new IOException("Config must be an object!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.config = getDefaultConfig();
|
this.config = DEFAULT_CONFIG;
|
||||||
this.saveConfig();
|
|
||||||
}
|
}
|
||||||
|
this.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void reloadIconImage() {
|
private final void reloadIconImage() {
|
||||||
@@ -206,7 +207,6 @@ public final class OriginBlacklistConfig {
|
|||||||
} else {
|
} else {
|
||||||
element = null;
|
element = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -312,11 +312,7 @@ public final class OriginBlacklistConfig {
|
|||||||
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(obj, "blacklist_http_api", Json5Primitive.fromBoolean(false), null);
|
||||||
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);
|
||||||
@@ -325,24 +321,157 @@ public final class OriginBlacklistConfig {
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final boolean merge(final Json5Object a, final Json5Object b) {
|
private static final boolean merge(final Json5Object aObj, final Json5Object bObj) {
|
||||||
|
final Json5Object ret = new Json5Object();
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
for (final String key : bObj.keySet()) {
|
||||||
for (String key : b.keySet()) {
|
final Json5Element dv = bObj.get(key);
|
||||||
Json5Element element = b.get(key);
|
if (aObj.has(key)) {
|
||||||
if (!a.has(key)) {
|
final Json5Element v = aObj.get(key);
|
||||||
a.add(key, element.deepCopy());
|
if (dv instanceof Json5Object) {
|
||||||
|
if (v instanceof Json5Object) {
|
||||||
|
final boolean c = merge((Json5Object) v, (Json5Object) dv);
|
||||||
|
ret.add(key, (Json5Object) v);
|
||||||
|
if (c) {
|
||||||
changed = true;
|
changed = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
final Json5Element _element = a.get(key);
|
ret.add(key, dv.deepCopy());
|
||||||
if (_element instanceof Json5Object objA && element instanceof Json5Object objB) {
|
changed = true;
|
||||||
if (merge(objA, objB)) {
|
}
|
||||||
|
} 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;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else if (dv instanceof Json5Primitive) {
|
||||||
|
if (v instanceof Json5Primitive) {
|
||||||
|
final Json5Primitive dp = (Json5Primitive) dv;
|
||||||
|
final Json5Primitive vp = (Json5Primitive) v;
|
||||||
|
if (dp.isBoolean()) {
|
||||||
|
if (vp.isBoolean()) {
|
||||||
|
ret.add(key, vp.deepCopy());
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else if (dp.isNumber()) {
|
||||||
|
if (vp.isNumber()) {
|
||||||
|
ret.add(key, vp.deepCopy());
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else if (dp.isString()) {
|
||||||
|
if (vp.isString()) {
|
||||||
|
ret.add(key, vp.deepCopy());
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret.add(key, dv.deepCopy());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (final String key : aObj.keySet()) {
|
||||||
|
if (!bObj.has(key)) {
|
||||||
|
ret.add(key, aObj.get(key).deepCopy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (final String key : aObj.keySet()) {
|
||||||
|
if (!bObj.has(key)) {
|
||||||
|
ret.add(key, aObj.get(key).deepCopy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (final String k : new ArrayList<>(aObj.keySet())) {
|
||||||
|
aObj.remove(k);
|
||||||
|
}
|
||||||
|
for (final String k : ret.keySet()) {
|
||||||
|
aObj.add(k, ret.get(k));
|
||||||
|
}
|
||||||
|
for (final String key : ret.keySet()) {
|
||||||
|
aObj.add(key, ret.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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 java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||||
import org.semver4j.Semver;
|
import org.semver4j.Semver;
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes" })
|
||||||
public interface IOriginBlacklistPlugin {
|
public interface IOriginBlacklistPlugin {
|
||||||
public String getPluginId();
|
public String getPluginId();
|
||||||
|
|
||||||
@@ -17,6 +19,8 @@ public interface IOriginBlacklistPlugin {
|
|||||||
|
|
||||||
public Path getPluginJarPath();
|
public Path getPluginJarPath();
|
||||||
|
|
||||||
|
public IEaglerXServerAPI getEaglerAPI();
|
||||||
|
|
||||||
public void log(final EnumLogLevel level, final String txt);
|
public void log(final EnumLogLevel level, final String txt);
|
||||||
|
|
||||||
public void kickPlayer(final Component txt, final OriginBlacklistLoginEvent event);
|
public void kickPlayer(final Component txt, final OriginBlacklistLoginEvent event);
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
private boolean papiPlaceholdersEnabled;
|
private boolean papiPlaceholdersEnabled;
|
||||||
private Object papi;
|
private Object papi;
|
||||||
private OriginBlacklist blacklist;
|
private OriginBlacklist blacklist;
|
||||||
private IEaglerXServerAPI eaglerAPI;
|
|
||||||
private Metrics metrics;
|
private Metrics metrics;
|
||||||
|
|
||||||
private CachedServerIcon iconCache;
|
private CachedServerIcon iconCache;
|
||||||
@@ -73,17 +72,16 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
this.papi = null;
|
this.papi = null;
|
||||||
}
|
}
|
||||||
this.blacklist = new OriginBlacklist(this);
|
this.blacklist = new OriginBlacklist(this);
|
||||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
|
||||||
this.getCommand("originblacklist").setExecutor(new OriginBlacklistCommandBukkit(this.blacklist));
|
this.getCommand("originblacklist").setExecutor(new OriginBlacklistCommandBukkit(this.blacklist));
|
||||||
this.getServer().getPluginManager().registerEvents(this, this);
|
this.getServer().getPluginManager().registerEvents(this, this);
|
||||||
this.blacklist.init();
|
this.blacklist.init();
|
||||||
if (this.blacklist.isMetricsEnabled()) {
|
if (this.blacklist.isMetricsEnabled()) {
|
||||||
this.metrics = new Metrics(this, OriginBlacklist.BSTATS_ID);
|
this.metrics = new Metrics(this, OriginBlacklist.BSTATS.BUKKIT);
|
||||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||||
final Map<String, Integer> playerMap = new HashMap<>();
|
final Map<String, Integer> playerMap = new HashMap<>();
|
||||||
|
|
||||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||||
final boolean eagler = eaglerAPI.isEaglerPlayerByUUID(player.getUniqueId());
|
final boolean eagler = this.getEaglerAPI().isEaglerPlayerByUUID(player.getUniqueId());
|
||||||
final String key = eagler ? "Eagler" : "Java";
|
final String key = eagler ? "Eagler" : "Java";
|
||||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||||
}
|
}
|
||||||
@@ -112,7 +110,8 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public final void onJavaLogin(final AsyncPlayerPreLoginEvent event) {
|
public final void onJavaLogin(final AsyncPlayerPreLoginEvent event) {
|
||||||
final OPlayer player = new OPlayer(null, event.getName(), event.getUniqueId(), event.getAddress().toString(), OriginBlacklist.UNKNOWN_STR, 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));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +136,11 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
|||||||
return Paths.get(this.getFile().getAbsolutePath());
|
return Paths.get(this.getFile().getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final IEaglerXServerAPI getEaglerAPI() {
|
||||||
|
return EaglerXServerAPI.instance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void log(final EnumLogLevel level, final String txt) {
|
public final void log(final EnumLogLevel level, final String txt) {
|
||||||
if (level == EnumLogLevel.WARN) {
|
if (level == EnumLogLevel.WARN) {
|
||||||
|
|||||||
@@ -5,6 +5,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.util.EaglerEventPriority;
|
||||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||||
@@ -43,7 +44,6 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
private boolean papiPlaceholdersEnabled;
|
private boolean papiPlaceholdersEnabled;
|
||||||
private Object papi;
|
private Object papi;
|
||||||
private OriginBlacklist blacklist;
|
private OriginBlacklist blacklist;
|
||||||
private IEaglerXServerAPI eaglerAPI;
|
|
||||||
private Metrics metrics;
|
private Metrics metrics;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,17 +71,17 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
this.papi = null;
|
this.papi = null;
|
||||||
}
|
}
|
||||||
this.blacklist = new OriginBlacklist(this);
|
this.blacklist = new OriginBlacklist(this);
|
||||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
this.getProxy().getPluginManager().registerCommand(this,
|
||||||
this.getProxy().getPluginManager().registerCommand(this, new OriginBlacklistCommandBungee(this, this.blacklist, "originblacklist"));
|
new OriginBlacklistCommandBungee(this, this.blacklist, "originblacklist"));
|
||||||
this.getProxy().getPluginManager().registerListener(this, this);
|
this.getProxy().getPluginManager().registerListener(this, this);
|
||||||
this.blacklist.init();
|
this.blacklist.init();
|
||||||
if (this.blacklist.isMetricsEnabled()) {
|
if (this.blacklist.isMetricsEnabled()) {
|
||||||
this.metrics = new Metrics(this, OriginBlacklist.BSTATS_ID);
|
this.metrics = new Metrics(this, OriginBlacklist.BSTATS.BUNGEE);
|
||||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||||
final Map<String, Integer> playerMap = new HashMap<>();
|
final Map<String, Integer> playerMap = new HashMap<>();
|
||||||
|
|
||||||
for (final ProxiedPlayer player : this.proxy.getPlayers()) {
|
for (final ProxiedPlayer player : this.proxy.getPlayers()) {
|
||||||
final boolean eagler = eaglerAPI.isEaglerPlayerByUUID(player.getUniqueId());
|
final boolean eagler = this.getEaglerAPI().isEaglerPlayerByUUID(player.getUniqueId());
|
||||||
final String key = eagler ? "Eagler" : "Java";
|
final String key = eagler ? "Eagler" : "Java";
|
||||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EaglerEventPriority.EAGLER_MOTD_EVENT)
|
||||||
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
||||||
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
||||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||||
@@ -114,7 +114,8 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
final InetSocketAddress vhost = conn.getVirtualHost();
|
final InetSocketAddress vhost = conn.getVirtualHost();
|
||||||
final ProxiedPlayer aPlayer = event.getPlayer();
|
final ProxiedPlayer aPlayer = event.getPlayer();
|
||||||
final OPlayer bPlayer = new OPlayer(null, aPlayer.getName(), aPlayer.getUniqueId(),
|
final OPlayer bPlayer = new OPlayer(null, aPlayer.getName(), aPlayer.getUniqueId(),
|
||||||
aPlayer.getAddress().toString(), aPlayer.getClientBrand(), vhost.getHostString() + vhost.getPort(), conn.getVersion());
|
aPlayer.getAddress().toString(), aPlayer.getClientBrand(), vhost.getHostString() + vhost.getPort(),
|
||||||
|
conn.getVersion());
|
||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +123,8 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
public final void onJavaHandshake(final PreLoginEvent event) {
|
public final void onJavaHandshake(final PreLoginEvent event) {
|
||||||
final PendingConnection conn = event.getConnection();
|
final PendingConnection conn = event.getConnection();
|
||||||
final InetSocketAddress vhost = conn.getVirtualHost();
|
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());
|
final OPlayer player = new OPlayer(null, null, null, conn.getAddress().toString(), OriginBlacklist.UNKNOWN_STR,
|
||||||
|
vhost.getHostString() + vhost.getPort(), conn.getVersion());
|
||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +132,8 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||||
final PendingConnection conn = event.getConnection();
|
final PendingConnection conn = event.getConnection();
|
||||||
final InetSocketAddress vhost = conn.getVirtualHost();
|
final InetSocketAddress vhost = conn.getVirtualHost();
|
||||||
final OPlayer player = new OPlayer(null, null, null, conn.getAddress().toString(), null, vhost.getHostString() + vhost.getPort(), -1);
|
final OPlayer player = new OPlayer(null, null, null, conn.getAddress().toString(), null,
|
||||||
|
vhost.getHostString() + vhost.getPort(), -1);
|
||||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +152,11 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
|||||||
return Paths.get(this.getFile().getAbsolutePath());
|
return Paths.get(this.getFile().getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final IEaglerXServerAPI getEaglerAPI() {
|
||||||
|
return EaglerXServerAPI.instance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void log(final EnumLogLevel level, final String txt) {
|
public final void log(final EnumLogLevel level, final String txt) {
|
||||||
if (level == EnumLogLevel.WARN) {
|
if (level == EnumLogLevel.WARN) {
|
||||||
|
|||||||
@@ -5,6 +5,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.util.EaglerEventPriority;
|
||||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||||
@@ -54,7 +55,6 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
private boolean papiPlaceholdersEnabled;
|
private boolean papiPlaceholdersEnabled;
|
||||||
private Object papi;
|
private Object papi;
|
||||||
private OriginBlacklist blacklist;
|
private OriginBlacklist blacklist;
|
||||||
private IEaglerXServerAPI eaglerAPI;
|
|
||||||
private Metrics metrics;
|
private Metrics metrics;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -89,16 +89,15 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
this.papi = null;
|
this.papi = null;
|
||||||
}
|
}
|
||||||
this.blacklist = new OriginBlacklist(this);
|
this.blacklist = new OriginBlacklist(this);
|
||||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
|
||||||
this.proxy.getCommandManager().register("originblacklist", new OriginBlacklistCommandVelocity(this.blacklist));
|
this.proxy.getCommandManager().register("originblacklist", new OriginBlacklistCommandVelocity(this.blacklist));
|
||||||
this.blacklist.init();
|
this.blacklist.init();
|
||||||
if (this.blacklist.isMetricsEnabled()) {
|
if (this.blacklist.isMetricsEnabled()) {
|
||||||
this.metrics = this.metricsFactory.make(this, OriginBlacklist.BSTATS_ID);
|
this.metrics = this.metricsFactory.make(this, OriginBlacklist.BSTATS.VELOCITY);
|
||||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||||
final Map<String, Integer> playerMap = new HashMap<>();
|
final Map<String, Integer> playerMap = new HashMap<>();
|
||||||
|
|
||||||
for (final Player player : this.proxy.getAllPlayers()) {
|
for (final Player player : this.proxy.getAllPlayers()) {
|
||||||
final boolean eagler = eaglerAPI.isEaglerPlayerByUUID(player.getUniqueId());
|
final boolean eagler = this.getEaglerAPI().isEaglerPlayerByUUID(player.getUniqueId());
|
||||||
final String key = eagler ? "Eagler" : "Java";
|
final String key = eagler ? "Eagler" : "Java";
|
||||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||||
}
|
}
|
||||||
@@ -119,7 +118,7 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LAST)
|
@Subscribe(priority = EaglerEventPriority.EAGLER_MOTD_EVENT, order = PostOrder.LAST)
|
||||||
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
||||||
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
||||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||||
@@ -149,7 +148,8 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||||
final InboundConnection conn = event.getConnection();
|
final InboundConnection conn = event.getConnection();
|
||||||
final InetSocketAddress vhost = conn.getVirtualHost().orElseThrow();
|
final InetSocketAddress vhost = conn.getVirtualHost().orElseThrow();
|
||||||
final OPlayer player = new OPlayer(null, null, null, conn.getRemoteAddress().getHostString(), vhost.getHostString() + vhost.getPort(),
|
final OPlayer player = new OPlayer(null, null, null, conn.getRemoteAddress().getHostString(),
|
||||||
|
vhost.getHostString() + vhost.getPort(),
|
||||||
null, -1);
|
null, -1);
|
||||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||||
}
|
}
|
||||||
@@ -173,6 +173,11 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final IEaglerXServerAPI getEaglerAPI() {
|
||||||
|
return EaglerXServerAPI.instance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void log(final EnumLogLevel level, final String txt) {
|
public final void log(final EnumLogLevel level, final String txt) {
|
||||||
if (level == EnumLogLevel.WARN) {
|
if (level == EnumLogLevel.WARN) {
|
||||||
|
|||||||
Reference in New Issue
Block a user