mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 19:17:40 +00:00
Compare commits
16 Commits
v2.0.6+c43
...
v2.0.9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c0f084bb4 | ||
|
|
c391ec3ad6 | ||
|
|
ce7685367f | ||
|
|
bc16324342 | ||
|
|
f6cf685d1c | ||
|
|
9b955ea77d | ||
|
|
f1fe503357 | ||
|
|
e315eeab24 | ||
|
|
c4dbe81de0 | ||
|
|
2883adc928 | ||
|
|
00b1c99dc4 | ||
|
|
1cd60a4dba | ||
|
|
ebcae682aa | ||
|
|
f22e800439 | ||
|
|
f0274ff4d4 | ||
|
|
12f9d669b4 |
19
.github/dependabot.yml
vendored
Normal file
19
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "gradle"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
open-pull-requests-limit: 10
|
||||
ignore:
|
||||
- dependency-name: "*"
|
||||
update-types: ["version-update:semver-major"]
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
open-pull-requests-limit: 10
|
||||
ignore:
|
||||
- dependency-name: "*"
|
||||
update-types: ["version-update:semver-major"]
|
||||
22
.github/workflows/dependabot.yml
vendored
Normal file
22
.github/workflows/dependabot.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
dependabot:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.pull_request.user.login == 'dependabot[bot]'
|
||||
steps:
|
||||
- id: metadata
|
||||
uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a
|
||||
with:
|
||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
|
||||
- if: steps.metadata.outputs.update-type != 'version-update:semver-major'
|
||||
run: gh pr merge --auto --squash "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{ github.event.pull_request.html_url }}
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
2
.github/workflows/gradle.yml
vendored
2
.github/workflows/gradle.yml
vendored
@@ -1,5 +1,3 @@
|
||||
name: Build Plugin
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -23,6 +24,11 @@
|
||||
- [x] Modular multi-platform support
|
||||
- [x] JSON5 based configuration
|
||||
|
||||
<h2>Requirements</h2>
|
||||
|
||||
- Eagler(craft)XServer v1.0.2 or newer
|
||||
- JDK 21 or newer
|
||||
|
||||
<h2>Download</h2>
|
||||
The latest release can be found at <b><a href="https://github.com/WebMCDevelopment/originblacklist/releases/latest/">https://github.com/WebMCDevelopment/originblacklist/releases/latest/</a></b>
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ val PLUGIN_NAME = "OriginBlacklist"
|
||||
val PLUGIN_IDEN = "originblacklist"
|
||||
val PLUGIN_DOMN = "xyz.webmc.$PLUGIN_IDEN"
|
||||
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
||||
val PLUGIN_VERS = "2.0.6"
|
||||
val PLUGIN_VERS = "2.0.9"
|
||||
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
||||
val PLUGIN_DEPA = listOf("EaglercraftXServer")
|
||||
val PLUGIN_DEPB = listOf("EaglercraftXServer")
|
||||
@@ -42,7 +42,7 @@ val EAGXS_VER = "1.0.8"
|
||||
|
||||
plugins {
|
||||
id("java")
|
||||
id("com.gradleup.shadow") version "9.3.1"
|
||||
id("com.gradleup.shadow") version "9.3.0"
|
||||
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"
|
||||
@@ -65,7 +65,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
|
||||
compileOnly("com.velocitypowered:velocity-api:3.5.0-SNAPSHOT")
|
||||
compileOnly("org.bukkit:bukkit:1.8-R0.1-SNAPSHOT")
|
||||
compileOnly("net.md-5:bungeecord-api:1.21-R0.5-SNAPSHOT")
|
||||
compileOnly("net.lax1dude.eaglercraft.backend:api-velocity:1.0.0")
|
||||
@@ -91,7 +91,7 @@ sourceSets {
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
}
|
||||
|
||||
val BUILD_PROPS = mapOf(
|
||||
@@ -113,7 +113,7 @@ val BUILD_PROPS = mapOf(
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.encoding = "UTF-8"
|
||||
options.release.set(17)
|
||||
options.release.set(21)
|
||||
}
|
||||
|
||||
tasks.withType<ProcessResources>().configureEach {
|
||||
|
||||
@@ -6,7 +6,8 @@ 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.OriginBlacklistHTTPServer;
|
||||
import xyz.webmc.originblacklist.base.http.OriginBlacklistRequestHandler;
|
||||
import xyz.webmc.originblacklist.base.metrics.GenericMetricsAdapter;
|
||||
import xyz.webmc.originblacklist.base.util.BuildInfo;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
@@ -15,6 +16,7 @@ import xyz.webmc.originblacklist.base.util.UpdateChecker;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -26,7 +28,9 @@ import java.nio.file.StandardOpenOption;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import de.marhali.json5.Json5;
|
||||
@@ -38,9 +42,14 @@ 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.IBasePlayer;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerPlayer;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
||||
import org.bstats.charts.AdvancedPie;
|
||||
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);
|
||||
@@ -50,11 +59,10 @@ public final class OriginBlacklist {
|
||||
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 OriginBlacklistHTTPServer http;
|
||||
private final GenericMetricsAdapter metrics;
|
||||
private final Json5 json5;
|
||||
private String updateURL;
|
||||
private Path jarFile;
|
||||
@@ -62,7 +70,7 @@ public final class OriginBlacklist {
|
||||
public OriginBlacklist(final IOriginBlacklistPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.config = new OriginBlacklistConfig(this);
|
||||
this.http = new OriginBlacklistHTTPServer(this);
|
||||
this.metrics = plugin.getMetrics();
|
||||
this.json5 = Json5.builder(builder -> builder.prettyPrinting().indentFactor(0).build());
|
||||
}
|
||||
|
||||
@@ -71,24 +79,56 @@ public final class OriginBlacklist {
|
||||
this.plugin.scheduleRepeat(() -> {
|
||||
this.checkForUpdates();
|
||||
}, this.config.getInteger("update_checker.check_timer"), TimeUnit.SECONDS);
|
||||
if (this.isHTTPServerEnabled()) {
|
||||
this.http.start();
|
||||
if (this.isBlacklistAPIEnabled()) {
|
||||
OriginBlacklistRequestHandler.register(this);
|
||||
}
|
||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||
final Map<String, Integer> playerMap = new HashMap<>();
|
||||
for (final Object player : this.getEaglerAPI().getAllPlayers()) {
|
||||
if (player instanceof IBasePlayer bPlayer) {
|
||||
final String key = (bPlayer instanceof IEaglerPlayer) ? "Eagler" : "Java";
|
||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||
}
|
||||
}
|
||||
return playerMap;
|
||||
}));
|
||||
this.plugin.log(EnumLogLevel.INFO, "Initialized Plugin");
|
||||
this.plugin.log(EnumLogLevel.DEBUG, "Commit " + COMMIT_L);
|
||||
if (this.isMetricsEnabled()) {
|
||||
this.metrics.start();
|
||||
}
|
||||
this.plugin.scheduleRepeat(() -> {
|
||||
this.plugin.log(EnumLogLevel.INFO, String.valueOf(this.isMetricsEnabled()));
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public final void shutdown() {
|
||||
this.plugin.log(EnumLogLevel.INFO, "Shutting down...");
|
||||
this.http.stop();
|
||||
if (this.isBlacklistAPIEnabled()) {
|
||||
OriginBlacklistRequestHandler.unRegister(this);
|
||||
}
|
||||
if (this.isMetricsEnabled()) {
|
||||
this.metrics.shutdown();
|
||||
}
|
||||
this.plugin.shutdown();
|
||||
}
|
||||
|
||||
public final void handleReload() {
|
||||
if (this.isHTTPServerEnabled()) {
|
||||
this.http.start();
|
||||
try {
|
||||
if (this.isBlacklistAPIEnabled()) {
|
||||
OriginBlacklistRequestHandler.register(this);
|
||||
} else {
|
||||
this.http.stop();
|
||||
OriginBlacklistRequestHandler.unRegister(this);
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
}
|
||||
try {
|
||||
if (this.isMetricsEnabled()) {
|
||||
this.metrics.start();
|
||||
} else {
|
||||
this.metrics.shutdown();
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,10 +150,10 @@ 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)) {
|
||||
if (isNonNullStr(name)) {
|
||||
this.plugin.log(EnumLogLevel.INFO, "Prevented blacklisted player " + name + " from joining.");
|
||||
this.updateLogFile(event, blacklisted);
|
||||
}
|
||||
@@ -132,9 +172,12 @@ public final class OriginBlacklist {
|
||||
} else {
|
||||
blacklisted_value = UNKNOWN_STR;
|
||||
}
|
||||
this.plugin.setMOTD(this.getBlacklistedComponent("motd", blacklisted.getArrayString(), blacklisted.getAltString(),
|
||||
if (this.isMOTDEnabled()) {
|
||||
this.plugin
|
||||
.setMOTD(this.getBlacklistedComponent("motd", blacklisted.getArrayString(), blacklisted.getAltString(),
|
||||
blacklisted.getString(), "blacklisted", "blacklisted from the server", blacklisted_value,
|
||||
blacklisted.getActionString()), event);
|
||||
blacklisted.getActionString(), true), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,12 +189,20 @@ 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 isHTTPServerEnabled() {
|
||||
return this.config.getBoolean("blacklist_http_share.enabled");
|
||||
public final boolean isBlacklistAPIEnabled() {
|
||||
return this.config.getBoolean("blacklist_http_api");
|
||||
}
|
||||
|
||||
public final OriginBlacklistConfig getConfig() {
|
||||
@@ -161,13 +212,18 @@ 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();
|
||||
@@ -178,7 +234,7 @@ public final class OriginBlacklist {
|
||||
this.plugin.runAsync(() -> {
|
||||
this.updateURL = UpdateChecker.checkForUpdates(PLUGIN_REPO, this.plugin.getPluginVersion(),
|
||||
this.config.getBoolean("update_checker.allow_snapshots"));
|
||||
if (isNonNull((this.updateURL))) {
|
||||
if (isNonNullStr((this.updateURL))) {
|
||||
action1.run();
|
||||
return;
|
||||
}
|
||||
@@ -191,7 +247,7 @@ public final class OriginBlacklist {
|
||||
|
||||
public final void updatePlugin(final Runnable action1, final Runnable action2) {
|
||||
try {
|
||||
final URL url = new URL(this.updateURL);
|
||||
final URL url = (new URI(this.updateURL)).toURL();
|
||||
final Path jar = this.jarFile;
|
||||
final Path bak = jar.resolveSibling(jar.getFileName().toString() + ".bak");
|
||||
final Path upd = jar
|
||||
@@ -221,8 +277,8 @@ public final class OriginBlacklist {
|
||||
action1.run();
|
||||
return;
|
||||
} catch (final Throwable t) {
|
||||
t.printStackTrace();
|
||||
Files.move(bak, jar, StandardCopyOption.REPLACE_EXISTING);
|
||||
throw t;
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
t.printStackTrace();
|
||||
@@ -245,7 +301,7 @@ public final class OriginBlacklist {
|
||||
final boolean whitelist = this.config.getBoolean("blacklist_to_whitelist");
|
||||
EnumBlacklistType type = EnumBlacklistType.NONE;
|
||||
|
||||
if (isNonNull(origin)) {
|
||||
if (isNonNullStr(origin)) {
|
||||
if (whitelist && !type.isBlacklisted())
|
||||
type = EnumBlacklistType.ORIGIN;
|
||||
for (final Json5Element element : this.config.getArray("blacklist.origins").getAsJson5Array()) {
|
||||
@@ -261,7 +317,7 @@ public final class OriginBlacklist {
|
||||
return whitelist ? EnumBlacklistType.NONE : EnumBlacklistType.ORIGIN;
|
||||
}
|
||||
|
||||
if (isNonNull(brand)) {
|
||||
if (isNonNullStr(brand)) {
|
||||
if (whitelist && !type.isBlacklisted())
|
||||
type = EnumBlacklistType.BRAND;
|
||||
for (final Json5Element element : this.config.getArray("blacklist.brands")) {
|
||||
@@ -275,7 +331,7 @@ public final class OriginBlacklist {
|
||||
}
|
||||
}
|
||||
|
||||
if (isNonNull(name)) {
|
||||
if (isNonNullStr(name)) {
|
||||
if (whitelist && !type.isBlacklisted())
|
||||
type = EnumBlacklistType.NAME;
|
||||
for (final Json5Element element : this.config.getArray("blacklist.player_names")) {
|
||||
@@ -289,7 +345,7 @@ public final class OriginBlacklist {
|
||||
}
|
||||
}
|
||||
|
||||
if (isNonNull(addr)) {
|
||||
if (isNonNullStr(addr)) {
|
||||
if (whitelist && !type.isBlacklisted())
|
||||
type = EnumBlacklistType.ADDR;
|
||||
for (final Json5Element element : this.config.getArray("blacklist.ip_addresses")) {
|
||||
@@ -316,6 +372,7 @@ public final class OriginBlacklist {
|
||||
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();
|
||||
@@ -334,10 +391,14 @@ public final class OriginBlacklist {
|
||||
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)
|
||||
@@ -350,21 +411,26 @@ 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(
|
||||
"""
|
||||
{
|
||||
@@ -417,7 +483,7 @@ public final class OriginBlacklist {
|
||||
for (final Json5Element element : arr) {
|
||||
this.plugin.runAsync(() -> {
|
||||
try {
|
||||
final URL url = new URL(element.getAsString());
|
||||
final URL url = (new URI(element.getAsString())).toURL();
|
||||
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
@@ -457,7 +523,8 @@ public final class OriginBlacklist {
|
||||
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 String txt = Instant.now() + " - [player=" + player.getName() + "," + "blacklist_reason=" + type.toString()
|
||||
+ "]";
|
||||
final Path dir = Paths.get(this.getDataDir());
|
||||
try {
|
||||
Files.createDirectories(dir);
|
||||
@@ -466,8 +533,7 @@ public final class OriginBlacklist {
|
||||
txt + "\n",
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.WRITE,
|
||||
StandardOpenOption.APPEND
|
||||
);
|
||||
StandardOpenOption.APPEND);
|
||||
} catch (final Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
@@ -490,7 +556,13 @@ public final class OriginBlacklist {
|
||||
return BuildInfo.get("plugin_name") + "/" + BuildInfo.get("plugin_vers") + "+" + BuildInfo.get("git_cm_hash");
|
||||
}
|
||||
|
||||
public static final boolean isNonNull(final String str) {
|
||||
public static final boolean isNonNullStr(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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class OriginBlacklistCommand implements ICommand {
|
||||
} else {
|
||||
ctx.reply(NO_PERMISSION);
|
||||
}
|
||||
} else if ((add || remove) && OriginBlacklist.isNonNull(argB)) {
|
||||
} else if ((add || remove) && OriginBlacklist.isNonNullStr(argB)) {
|
||||
if ((add && ctx.hasPermission("originblacklist.command.add"))
|
||||
|| (remove && ctx.hasPermission("originblacklist.command.add"))) {
|
||||
final String arrName;
|
||||
@@ -69,7 +69,7 @@ public class OriginBlacklistCommand implements ICommand {
|
||||
} else {
|
||||
arrName = null;
|
||||
}
|
||||
if (OriginBlacklist.isNonNull(arrName)) {
|
||||
if (OriginBlacklist.isNonNullStr(arrName)) {
|
||||
final String arrPath = "blacklist." + arrName;
|
||||
final Json5Array arr = config.getArray(arrPath);
|
||||
if (add) {
|
||||
@@ -95,7 +95,7 @@ public class OriginBlacklistCommand implements ICommand {
|
||||
} else {
|
||||
ctx.reply(NO_PERMISSION);
|
||||
}
|
||||
} else if ("test".equalsIgnoreCase(command) && OriginBlacklist.isNonNull(argA)) {
|
||||
} else if ("test".equalsIgnoreCase(command) && OriginBlacklist.isNonNullStr(argA)) {
|
||||
if (ctx.hasPermission("originblacklist.command.test")) {
|
||||
if (this.isBlacklisted(argA)) {
|
||||
ctx.reply("<green>" + argA + " is on the blacklist.</green>");
|
||||
|
||||
@@ -11,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;
|
||||
|
||||
@@ -21,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;
|
||||
@@ -70,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() {
|
||||
@@ -129,7 +132,7 @@ public final class OriginBlacklistConfig {
|
||||
public final Json5Element get(final String key) {
|
||||
Json5Element element = null;
|
||||
|
||||
if (this.config != null && OriginBlacklist.isNonNull(key)) {
|
||||
if (this.config != null && OriginBlacklist.isNonNullStr(key)) {
|
||||
element = this.config;
|
||||
final String[] parts = splitPath(key);
|
||||
|
||||
@@ -206,7 +209,6 @@ public final class OriginBlacklistConfig {
|
||||
} else {
|
||||
element = null;
|
||||
}
|
||||
|
||||
if (element == null) {
|
||||
break;
|
||||
}
|
||||
@@ -262,18 +264,29 @@ 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>");
|
||||
kick.add("<blue>%discord_invite%</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);
|
||||
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 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.*");
|
||||
@@ -302,9 +315,12 @@ public final class OriginBlacklistConfig {
|
||||
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(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);
|
||||
@@ -312,43 +328,172 @@ public final class OriginBlacklistConfig {
|
||||
addJSONObj(uObj, "check_timer", Json5Primitive.fromNumber(3600), null);
|
||||
addJSONObj(uObj, "auto_update", Json5Primitive.fromBoolean(true), null);
|
||||
addJSONObj(obj, "update_checker", uObj, null);
|
||||
final Json5Object hObj = new Json5Object();
|
||||
addJSONObj(hObj, "enabled", Json5Primitive.fromBoolean(false), null);
|
||||
addJSONObj(hObj, "http_port", Json5Primitive.fromNumber(8080), null);
|
||||
addJSONObj(hObj, "listen_addr", Json5Primitive.fromString("0.0.0.0"), null);
|
||||
addJSONObj(obj, "blacklist_http_share", hObj, null);
|
||||
addJSONObj(obj, "blacklist_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, "logFile", Json5Primitive.fromBoolean(true), null);
|
||||
addJSONObj(obj, "config_version", Json5Primitive.fromNumber(1), "DO NOT CHANGE");
|
||||
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());
|
||||
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 {
|
||||
final Json5Element _element = a.get(key);
|
||||
if (_element instanceof Json5Object objA && element instanceof Json5Object objB) {
|
||||
if (merge(objA, objB)) {
|
||||
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;
|
||||
}
|
||||
|
||||
private static final void addJSONObj(final Json5Object obj, final String key, final Json5Element value,
|
||||
final String comment) {
|
||||
if (OriginBlacklist.isNonNull(comment)) {
|
||||
if (OriginBlacklist.isNonNullStr(comment)) {
|
||||
value.setComment(comment);
|
||||
}
|
||||
obj.add(key, value);
|
||||
@@ -357,7 +502,7 @@ public final class OriginBlacklistConfig {
|
||||
private static final String[] splitPath(final String key) {
|
||||
final String[] ret;
|
||||
|
||||
if (OriginBlacklist.isNonNull(key)) {
|
||||
if (OriginBlacklist.isNonNullStr(key)) {
|
||||
ret = key.split("\\.");
|
||||
} else {
|
||||
ret = new String[0];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public enum EnumBlacklistType {
|
||||
this.str = str;
|
||||
this.alt = alt;
|
||||
this.arr = arr;
|
||||
this.act = OriginBlacklist.isNonNull(act) ? act : OriginBlacklist.GENERIC_STR.toLowerCase();
|
||||
this.act = OriginBlacklist.isNonNullStr(act) ? act : OriginBlacklist.GENERIC_STR.toLowerCase();
|
||||
}
|
||||
|
||||
public final String getString() {
|
||||
|
||||
@@ -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 final 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,21 @@
|
||||
package xyz.webmc.originblacklist.base.metrics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bstats.charts.CustomChart;
|
||||
|
||||
public abstract class GenericMetricsAdapter {
|
||||
protected final List<CustomChart> charts;
|
||||
|
||||
protected GenericMetricsAdapter() {
|
||||
this.charts = new ArrayList<>();
|
||||
}
|
||||
|
||||
public final void addCustomChart(final CustomChart chart) {
|
||||
this.charts.add(chart);
|
||||
}
|
||||
|
||||
public abstract void start();
|
||||
public abstract void shutdown();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package xyz.webmc.originblacklist.base.util;
|
||||
|
||||
public final class EaglerEventPriority {
|
||||
public static final int EAGLER_MOTD_EVENT = 100;
|
||||
}
|
||||
@@ -3,13 +3,16 @@ package xyz.webmc.originblacklist.base.util;
|
||||
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.metrics.GenericMetricsAdapter;
|
||||
|
||||
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 +20,10 @@ public interface IOriginBlacklistPlugin {
|
||||
|
||||
public Path getPluginJarPath();
|
||||
|
||||
public GenericMetricsAdapter getMetrics();
|
||||
|
||||
public IEaglerXServerAPI getEaglerAPI();
|
||||
|
||||
public void log(final EnumLogLevel level, final String txt);
|
||||
|
||||
public void kickPlayer(final Component txt, final OriginBlacklistLoginEvent event);
|
||||
|
||||
@@ -85,7 +85,7 @@ public final class OPlayer {
|
||||
}
|
||||
|
||||
private static final String formatIPAddress(String addr) {
|
||||
if (OriginBlacklist.isNonNull(addr)) {
|
||||
if (OriginBlacklist.isNonNullStr(addr)) {
|
||||
if (addr.startsWith("/")) {
|
||||
addr = addr.substring(1);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
import de.marhali.json5.Json5;
|
||||
@@ -20,7 +21,7 @@ public final class UpdateChecker {
|
||||
public static final String checkForUpdates(final String repo, final Semver currentVersion,
|
||||
final boolean allowSnapshots) {
|
||||
try {
|
||||
final URL url = new URL("https://api.github.com/repos/" + repo + "/releases");
|
||||
final URL url = (new URI("https://api.github.com/repos/" + repo + "/releases")).toURL();
|
||||
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(5000);
|
||||
@@ -75,7 +76,7 @@ public final class UpdateChecker {
|
||||
comm = "";
|
||||
}
|
||||
if (ver.isGreaterThan(currentVersion) || (allowSnapshots && currentVersion.diff(ver) == VersionDiff.BUILD
|
||||
&& OriginBlacklist.isNonNull(comm) && !BuildInfo.get("git_cm_hash").startsWith(comm))) {
|
||||
&& OriginBlacklist.isNonNullStr(comm) && !BuildInfo.get("git_cm_hash").startsWith(comm))) {
|
||||
element = obj.get("assets");
|
||||
if (element instanceof Json5Array) {
|
||||
final Json5Array aArr = element.getAsJson5Array();
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package xyz.webmc.originblacklist.bukkit;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.metrics.GenericMetricsAdapter;
|
||||
|
||||
import org.bstats.charts.CustomChart;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
|
||||
public final class BukkitMetricsAdapter extends GenericMetricsAdapter {
|
||||
private final OriginBlacklistBukkit plugin;
|
||||
private Metrics metrics;
|
||||
|
||||
public BukkitMetricsAdapter(final OriginBlacklistBukkit plugin) {
|
||||
super();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (this.metrics == null) {
|
||||
this.metrics = new Metrics(this.plugin, OriginBlacklist.BSTATS.BUKKIT);
|
||||
for (final CustomChart chart : this.charts) {
|
||||
this.metrics.addCustomChart(chart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
if (this.metrics != null) {
|
||||
this.metrics.shutdown();
|
||||
this.metrics = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -112,7 +110,8 @@ 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().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));
|
||||
}
|
||||
|
||||
@@ -137,6 +136,16 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
||||
return Paths.get(this.getFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BukkitMetricsAdapter getMetrics() {
|
||||
return new BukkitMetricsAdapter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IEaglerXServerAPI getEaglerAPI() {
|
||||
return EaglerXServerAPI.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void log(final EnumLogLevel level, final String txt) {
|
||||
if (level == EnumLogLevel.WARN) {
|
||||
@@ -244,7 +253,6 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
||||
|
||||
@Override
|
||||
public final void shutdown() {
|
||||
this.metrics.shutdown();
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package xyz.webmc.originblacklist.bungee;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.metrics.GenericMetricsAdapter;
|
||||
|
||||
import org.bstats.charts.CustomChart;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
|
||||
public final class BungeeMetricsAdapter extends GenericMetricsAdapter {
|
||||
private final OriginBlacklistBungee plugin;
|
||||
private Metrics metrics;
|
||||
|
||||
public BungeeMetricsAdapter(final OriginBlacklistBungee plugin) {
|
||||
super();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (this.metrics == null) {
|
||||
this.metrics = new Metrics(this.plugin, OriginBlacklist.BSTATS.BUNGEE);
|
||||
for (final CustomChart chart : this.charts) {
|
||||
this.metrics.addCustomChart(chart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
if (this.metrics != null) {
|
||||
this.metrics.shutdown();
|
||||
this.metrics = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,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.util.EaglerEventPriority;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
@@ -13,8 +14,6 @@ import xyz.webmc.originblacklist.bungee.command.OriginBlacklistCommandBungee;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -33,8 +32,6 @@ import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
import org.bstats.charts.AdvancedPie;
|
||||
import org.semver4j.Semver;
|
||||
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
@@ -43,8 +40,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
|
||||
public final void onEnable() {
|
||||
@@ -71,24 +66,10 @@ 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.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 String key = eagler ? "Eagler" : "Java";
|
||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||
}
|
||||
|
||||
return playerMap;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,7 +83,7 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
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));
|
||||
@@ -114,7 +95,8 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
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(), 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));
|
||||
}
|
||||
|
||||
@@ -122,7 +104,8 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
public final void onJavaHandshake(final PreLoginEvent event) {
|
||||
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());
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -130,7 +113,8 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -149,6 +133,16 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
return Paths.get(this.getFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BungeeMetricsAdapter getMetrics() {
|
||||
return new BungeeMetricsAdapter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IEaglerXServerAPI getEaglerAPI() {
|
||||
return EaglerXServerAPI.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void log(final EnumLogLevel level, final String txt) {
|
||||
if (level == EnumLogLevel.WARN) {
|
||||
@@ -218,7 +212,6 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
|
||||
@Override
|
||||
public final void shutdown() {
|
||||
this.metrics.shutdown();
|
||||
this.proxy.getScheduler().cancel(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,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.util.EaglerEventPriority;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
@@ -13,9 +14,7 @@ import xyz.webmc.originblacklist.velocity.command.OriginBlacklistCommandVelocity
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
@@ -38,13 +37,11 @@ import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.EaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftLoginEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftMOTDEvent;
|
||||
import org.bstats.charts.AdvancedPie;
|
||||
import org.bstats.velocity.Metrics;
|
||||
import org.bstats.velocity.Metrics.Factory;
|
||||
import org.semver4j.Semver;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@SuppressWarnings({ "deprecation", "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
private final PluginContainer plugin;
|
||||
private final Factory metricsFactory;
|
||||
@@ -54,8 +51,6 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
private boolean papiPlaceholdersEnabled;
|
||||
private Object papi;
|
||||
private OriginBlacklist blacklist;
|
||||
private IEaglerXServerAPI eaglerAPI;
|
||||
private Metrics metrics;
|
||||
|
||||
@Inject
|
||||
public OriginBlacklistVelocity(final PluginContainer plugin, Factory metricsFactory, final ProxyServer proxy,
|
||||
@@ -67,7 +62,7 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public final void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
public final void onProxyInitialization(final ProxyInitializeEvent event) {
|
||||
this.proxy.getPluginManager().getPlugin("eaglerxserver").ifPresentOrElse(plugin -> {
|
||||
final Semver version = new Semver(plugin.getDescription().getVersion().orElse("1.0.0"));
|
||||
if (version.isLowerThan(OriginBlacklist.REQUIRED_API_VER)) {
|
||||
@@ -89,23 +84,8 @@ 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.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 String key = eagler ? "Eagler" : "Java";
|
||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||
}
|
||||
|
||||
return playerMap;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -119,7 +99,7 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
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));
|
||||
@@ -149,7 +129,8 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||
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(),
|
||||
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));
|
||||
}
|
||||
@@ -173,6 +154,16 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final VelocityMetricsAdapter getMetrics() {
|
||||
return new VelocityMetricsAdapter(this, this.metricsFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IEaglerXServerAPI getEaglerAPI() {
|
||||
return EaglerXServerAPI.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void log(final EnumLogLevel level, final String txt) {
|
||||
if (level == EnumLogLevel.WARN) {
|
||||
@@ -249,7 +240,6 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
|
||||
@Override
|
||||
public final void shutdown() {
|
||||
this.metrics.shutdown();
|
||||
for (ScheduledTask task : this.proxy.getScheduler().tasksByPlugin(this.plugin)) {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package xyz.webmc.originblacklist.velocity;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.metrics.GenericMetricsAdapter;
|
||||
|
||||
import org.bstats.charts.CustomChart;
|
||||
import org.bstats.velocity.Metrics;
|
||||
import org.bstats.velocity.Metrics.Factory;
|
||||
|
||||
public final class VelocityMetricsAdapter extends GenericMetricsAdapter {
|
||||
private final OriginBlacklistVelocity plugin;
|
||||
private final Factory factory;
|
||||
private Metrics metrics;
|
||||
|
||||
public VelocityMetricsAdapter(final OriginBlacklistVelocity plugin, final Factory factory) {
|
||||
super();
|
||||
this.plugin = plugin;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (this.metrics == null) {
|
||||
this.metrics = this.factory.make(this.plugin, OriginBlacklist.BSTATS.VELOCITY);
|
||||
for (final CustomChart chart : this.charts) {
|
||||
this.metrics.addCustomChart(chart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
if (this.metrics != null) {
|
||||
this.metrics.shutdown();
|
||||
this.metrics = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user