diff --git a/bin/main/bungee.yml b/bin/main/bungee.yml
new file mode 100644
index 0000000..7916bf5
--- /dev/null
+++ b/bin/main/bungee.yml
@@ -0,0 +1,7 @@
+name: OriginBlacklist
+version: ${version}
+main: dev.colbster937.originblacklist.bungee.OriginBlacklistBungee
+description: ${description}
+author: Colbster937
+depends:
+ - EaglercraftXServer
\ No newline at end of file
diff --git a/bin/main/config.yml b/bin/main/config.yml
new file mode 100644
index 0000000..6d34b2b
--- /dev/null
+++ b/bin/main/config.yml
@@ -0,0 +1,69 @@
+messages:
+ # Valid Placeholders:
+ # - %blocked% - The player's origin/brand that was blocked
+ # - %blocktype% - Shows what the player was blocked for
+ # - %easyblocktype% - Shows what the player was blocked for in an eagler-kid readable form
+ # - %host% - The IP the player pinged
+
+ kick: |
+ This %easyblocktype% is not allowed on the server!
+ ยป %blocked% ยซ
+
+ Think this is a mistake? Join our discord:
+ discord.gg/changethisintheconfig
+
+ motd:
+ enabled: true
+ text: |
+ This %easyblocktype% is not allowed!
+ ยป %blocked% ยซ
+ icon: "blacklisted.png"
+
+# Origin + Brand blacklist supports wildcards
+# Everything should be lowercase
+blacklist:
+ origins:
+ - "hack.example.com"
+ brands:
+ - "*dragonx*"
+ - "*piclient*"
+ missing_origin: false
+ blacklist_redirect: ""
+
+discord:
+ webhook: ""
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# :>
\ No newline at end of file
diff --git a/bin/main/dev/colbster937/originblacklist/base/Base$LoggerAdapter.class b/bin/main/dev/colbster937/originblacklist/base/Base$LoggerAdapter.class
new file mode 100644
index 0000000..6e15c25
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/base/Base$LoggerAdapter.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/base/Base.class b/bin/main/dev/colbster937/originblacklist/base/Base.class
new file mode 100644
index 0000000..3feeb61
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/base/Base.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/base/Command$CommandContext.class b/bin/main/dev/colbster937/originblacklist/base/Command$CommandContext.class
new file mode 100644
index 0000000..f162159
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/base/Command$CommandContext.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/base/Command.class b/bin/main/dev/colbster937/originblacklist/base/Command.class
new file mode 100644
index 0000000..91c01d5
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/base/Command.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/base/ConfigManager$Blacklist.class b/bin/main/dev/colbster937/originblacklist/base/ConfigManager$Blacklist.class
new file mode 100644
index 0000000..4b26a81
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/base/ConfigManager$Blacklist.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/base/ConfigManager$Discord.class b/bin/main/dev/colbster937/originblacklist/base/ConfigManager$Discord.class
new file mode 100644
index 0000000..364c6f6
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/base/ConfigManager$Discord.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/base/ConfigManager$MOTD.class b/bin/main/dev/colbster937/originblacklist/base/ConfigManager$MOTD.class
new file mode 100644
index 0000000..e7767e6
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/base/ConfigManager$MOTD.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/base/ConfigManager$Messages.class b/bin/main/dev/colbster937/originblacklist/base/ConfigManager$Messages.class
new file mode 100644
index 0000000..0bd9f8e
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/base/ConfigManager$Messages.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/base/ConfigManager.class b/bin/main/dev/colbster937/originblacklist/base/ConfigManager.class
new file mode 100644
index 0000000..81a937a
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/base/ConfigManager.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/bukkit/CommandBukkit$1.class b/bin/main/dev/colbster937/originblacklist/bukkit/CommandBukkit$1.class
new file mode 100644
index 0000000..40160d7
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/bukkit/CommandBukkit$1.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/bukkit/CommandBukkit.class b/bin/main/dev/colbster937/originblacklist/bukkit/CommandBukkit.class
new file mode 100644
index 0000000..9674d6a
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/bukkit/CommandBukkit.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit$1.class b/bin/main/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit$1.class
new file mode 100644
index 0000000..1c8f2a4
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit$1.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit.class b/bin/main/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit.class
new file mode 100644
index 0000000..63b2337
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/bungee/CommandBungee$1.class b/bin/main/dev/colbster937/originblacklist/bungee/CommandBungee$1.class
new file mode 100644
index 0000000..b6f8737
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/bungee/CommandBungee$1.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/bungee/CommandBungee.class b/bin/main/dev/colbster937/originblacklist/bungee/CommandBungee.class
new file mode 100644
index 0000000..6b29473
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/bungee/CommandBungee.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee$1.class b/bin/main/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee$1.class
new file mode 100644
index 0000000..29e89be
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee$1.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee.class b/bin/main/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee.class
new file mode 100644
index 0000000..169b89e
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/velocity/CommandVelocity$1.class b/bin/main/dev/colbster937/originblacklist/velocity/CommandVelocity$1.class
new file mode 100644
index 0000000..99769cf
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/velocity/CommandVelocity$1.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/velocity/CommandVelocity.class b/bin/main/dev/colbster937/originblacklist/velocity/CommandVelocity.class
new file mode 100644
index 0000000..4ed656f
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/velocity/CommandVelocity.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity$1.class b/bin/main/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity$1.class
new file mode 100644
index 0000000..01a1bc6
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity$1.class differ
diff --git a/bin/main/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity.class b/bin/main/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity.class
new file mode 100644
index 0000000..5260eaa
Binary files /dev/null and b/bin/main/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity.class differ
diff --git a/bin/main/plugin.yml b/bin/main/plugin.yml
new file mode 100644
index 0000000..e583b2c
--- /dev/null
+++ b/bin/main/plugin.yml
@@ -0,0 +1,9 @@
+name: OriginBlacklist
+version: ${version}
+main: dev.colbster937.originblacklist.bukkit.OriginBlacklistBukkit
+description: ${description}
+author: Colbster937
+depend:
+ - EaglercraftXServer
+commands:
+ originblacklist:
\ No newline at end of file
diff --git a/bin/main/server-blocked.png b/bin/main/server-blocked.png
new file mode 100644
index 0000000..001ee13
Binary files /dev/null and b/bin/main/server-blocked.png differ
diff --git a/bin/main/velocity-plugin.json b/bin/main/velocity-plugin.json
new file mode 100644
index 0000000..bf1052d
--- /dev/null
+++ b/bin/main/velocity-plugin.json
@@ -0,0 +1,14 @@
+{
+ "id": "originblacklist",
+ "name": "OriginBlacklist",
+ "version": "${version}",
+ "description": "${description}",
+ "main": "dev.colbster937.originblacklist.velocity.OriginBlacklistVelocity",
+ "authors": ["Colbster937"],
+ "dependencies": [
+ {
+ "id": "eaglerxserver",
+ "optional": false
+ }
+ ]
+}
diff --git a/build.gradle b/build.gradle
index 5df1ba4..308e6b2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,7 +8,7 @@ plugins {
group = 'dev.colbster937'
-version = '1.0.4'
+version = '1.0.5'
description = 'A reimplementation of OriginBlacklist for EaglerXServer'
def targetJavaVersion = 17
@@ -64,7 +64,7 @@ java {
}
processResources {
- filesMatching(['plugin.yml', 'bungee.yml', 'velocity-plugin.json']) {
+ filesMatching(['plugin.yml', 'bungee.yml', 'velocity-plugin.json', 'Base.java']) {
expand(
version: project.version,
description: project.description
diff --git a/src/main/java/dev/colbster937/originblacklist/base/Base.java b/src/main/java/dev/colbster937/originblacklist/base/Base.java
index a423c34..892bfc2 100644
--- a/src/main/java/dev/colbster937/originblacklist/base/Base.java
+++ b/src/main/java/dev/colbster937/originblacklist/base/Base.java
@@ -5,20 +5,21 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.lax1dude.eaglercraft.backend.server.api.*;
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftClientBrandEvent;
+import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftLoginEvent;
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftMOTDEvent;
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
+import java.net.HttpURLConnection;
import java.net.URL;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.List;
+import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
public class Base {
@@ -42,46 +43,51 @@ public class Base {
for (int i = 0; i < Math.max(c.length, r.length); i++) {
int c1 = i < c.length ? Integer.parseInt(c[i]) : 0;
int r1 = i < r.length ? Integer.parseInt(r[i]) : 0;
- if (c1 < r1) return false;
- if (c1 > r1) return true;
+ if (c1 < r1)
+ return false;
+ if (c1 > r1)
+ return true;
}
return true;
- }
+ }
public static LoggerAdapter getLogger() {
- if (adapter == null) throw new IllegalStateException("Logger not initialized!");
+ if (adapter == null)
+ throw new IllegalStateException("Logger not initialized!");
return adapter;
}
public interface LoggerAdapter {
void info(String msg);
+
void warn(String msg);
+
void error(String msg);
}
- public static void handleConnection(IEaglercraftClientBrandEvent e) {
- IEaglerPendingConnection conn = e.getPendingConnection();
+ public static void handleConnection(IEaglercraftLoginEvent e) {
+ IEaglerLoginConnection conn = e.getLoginConnection();
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
String brand = conn.getEaglerBrandString();
- if ((origin != "null" || origin != null) && !config.blacklist.missing_origin) {
+
+ if (origin != null && !origin.equals("null") && !config.blacklist.missing_origin) {
for (String origin1 : config.blacklist.origins) {
if (matches(origin, origin1)) {
- setKickMessage(e, kick("origin", "website", origin, conn.getWebSocketHost()));
+ setKick(e, kick("origin", "website", origin, conn.getWebSocketHost()));
webhook(conn, origin, brand, "origin");
return;
}
}
- } else {
- if (origin != "null" || origin != null) {
- setKickMessage(e, kick("origin", "website", origin, conn.getWebSocketHost()));
- webhook(conn, "null", brand, "origin");
- return;
- }
+ } else if (origin != null && !origin.equals("null")) {
+ setKick(e, kick("origin", "website", origin, conn.getWebSocketHost()));
+ webhook(conn, "null", brand, "origin");
+ return;
}
- if (brand != "null" && brand != null) {
+
+ if (brand != null && !brand.equals("null")) {
for (String brand1 : config.blacklist.brands) {
if (matches(brand, brand1)) {
- setKickMessage(e, kick("brand", "client", brand, conn.getWebSocketHost()));
+ setKick(e, kick("brand", "client", brand, conn.getWebSocketHost()));
webhook(conn, origin, brand, "brand");
return;
}
@@ -89,9 +95,15 @@ public class Base {
}
}
- public static void setKickMessage(IEaglercraftClientBrandEvent e, Component msg) {
+ public static void setKick(IEaglercraftLoginEvent e, Component msg) {
try {
- e.setKickMessage(msg);
+ String redir = config.blacklist.blacklist_redirect;
+ if (redir.equals("") || redir.equals("null")) {
+ e.setKickMessage(msg);
+ } else {
+ e.setKickRedirect(redir);
+ }
+ getLogger().info("Kicked " + e.getProfileUsername());
} catch (Throwable ignored) {
String msg1 = LegacyComponentSerializer.legacySection().serialize(msg);
e.setKickMessage(msg1);
@@ -104,26 +116,23 @@ public class Base {
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
List m = List.of(config.messages.motd.text.split("\n")).stream()
.map(line -> line
- .replaceAll("%blocktype%", "origin")
- .replaceAll("%easyblocktype%", "website")
- .replaceAll("%blocked%", origin)
- .replaceAll("%host%", conn.getWebSocketHost()))
+ .replaceAll("%blocktype%", "origin")
+ .replaceAll("%easyblocktype%", "website")
+ .replaceAll("%blocked%", origin)
+ .replaceAll("%host%", conn.getWebSocketHost()))
.map(line -> LegacyComponentSerializer.legacySection().serialize(
- MiniMessage.miniMessage().deserialize(
- line
- )
- )).collect(Collectors.toList());
- if ((origin != "null" || origin != null) && !config.blacklist.missing_origin) {
+ MiniMessage.miniMessage().deserialize(line)))
+ .collect(Collectors.toList());
+
+ if (origin != null && !origin.equals("null") && !config.blacklist.missing_origin) {
for (String origin1 : config.blacklist.origins) {
if (matches(origin, origin1)) {
setMOTD(conn, m);
return;
}
}
- } else {
- if (origin != "null" || origin != null) {
- setMOTD(conn, m);
- }
+ } else if (origin != null && !origin.equals("null")) {
+ setMOTD(conn, m);
}
}
}
@@ -133,13 +142,15 @@ public class Base {
conn.setPlayerTotal(0);
conn.setPlayerMax(0);
conn.setPlayerList(List.of());
- if (config.messages.motd.icon != null && !config.messages.motd.icon.isEmpty())
+
+ if (config.messages.motd.icon != null && !config.messages.motd.icon.isEmpty()) {
try {
BufferedImage img = ImageIO.read(new File(config.messages.motd.icon));
if (img.getWidth() != 64 || img.getHeight() != 64) {
getLogger().warn("Icon must be 64x64");
return;
}
+
byte[] bytes = new byte[64 * 64 * 4];
for (int y = 0; y < 64; y++) {
for (int x = 0; x < 64; x++) {
@@ -155,6 +166,7 @@ public class Base {
} catch (IOException ex) {
getLogger().error(ex.toString());
}
+ }
}
public static boolean matches(String text1, String text2) {
@@ -163,55 +175,58 @@ public class Base {
public static Component kick(String type, String easytype, String value, String host) {
return MiniMessage.miniMessage().deserialize(
- config.messages.kick
- .replaceAll("%blocktype%", type)
- .replaceAll("%easyblocktype%", easytype)
- .replaceAll("%blocked%", value)
- .replaceAll("%host%", host)
- );
+ config.messages.kick
+ .replaceAll("%blocktype%", type)
+ .replaceAll("%easyblocktype%", easytype)
+ .replaceAll("%blocked%", value)
+ .replaceAll("%host%", host));
}
- public static void webhook(IEaglerPendingConnection plr, String origin, String brand, String type) {
+ public static void webhook(IEaglerLoginConnection plr, String origin, String brand, String type) {
String webhook = config.discord.webhook;
- if (webhook == null || webhook.isBlank()) return;
+ if (webhook == null || webhook.isBlank())
+ return;
- String addr = plr.getPlayerAddress() != null ? plr.getPlayerAddress().toString().substring(1) : "undefined";
- String protocol = plr.isEaglerXRewindPlayer()
- ? (String.valueOf(plr.getRewindProtocolVersion()) != null ? String.valueOf(plr.getRewindProtocolVersion()) : "undefined")
- : (String.valueOf(plr.getMinecraftProtocol()) != null ? String.valueOf(plr.getMinecraftProtocol()) : "undefined");
- String rewind = plr.isEaglerXRewindPlayer() ? "Yes" : "No";
- String host = plr.getWebSocketHost();
- String userAgent = plr.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT);
- if (userAgent == null || userAgent.isEmpty()) userAgent = "undefined";
+ CompletableFuture.runAsync(() -> {
+ String addr = (plr.getPlayerAddress() != null ? plr.getPlayerAddress().toString().substring(1) : "undefined:undefined").split(":")[0];
+ int protocol = !plr.isEaglerXRewindPlayer() ? plr.getMinecraftProtocol() : plr.getRewindProtocolVersion();
+ String host = plr.getWebSocketHost();
+ String userAgent = plr.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT);
+ Boolean rewind = plr.isEaglerXRewindPlayer();
+ if (userAgent == null || userAgent.isEmpty())
+ userAgent = "undefined";
- String payload = String.format("""
- {
- "content": "Blocked a blacklisted %s from joining",
- "embeds": [
- {
- "title": "Player Information",
- "description": "๐ฎ **Name:** %s\\n๐ **Address:** %s\\n๐ **PVN:** %s\\n๐ **Origin:** %s\\n๐ **Brand:** %s\\n๐ช **Host:** %s\\n๐ง **User Agent:** %s\\nโช **Rewind:** %s"
+ String payload = String.format(
+ """
+ {
+ "content": "Blocked a blacklisted %s from joining",
+ "embeds": [
+ {
+ "title": "Player Information",
+ "description": "๐ฎ **Name:** %s\\n๐ **IP:** %s\\n๐ **PVN:** %s\\n๐ **Origin:** %s\\n๐ **Brand:** %s\\n๐ช **Host:** %s\\n๐ง **User Agent:** %s\\nโช **Rewind:** %s"
+ }
+ ]
+ }
+ """,
+ type, plr.getUsername(), addr, protocol, origin, brand, plr.isWebSocketSecure() ? "wss://" : "ws://" + host, userAgent, rewind ? "Yes" : "No");
+
+ try {
+ HttpURLConnection conn = (HttpURLConnection) new URL(webhook).openConnection();
+ conn.setRequestMethod("POST");
+ conn.setRequestProperty("Content-Type", "application/json");
+ conn.setDoOutput(true);
+ conn.setConnectTimeout(5000);
+ conn.setReadTimeout(5000);
+
+ try (OutputStream os = conn.getOutputStream()) {
+ os.write(payload.getBytes());
+ }
+
+ conn.getInputStream().close();
+ } catch (Exception e) {
+ getLogger().warn("Failed to send webhook: " + e);
}
- ]
- }
- """, type, plr.getAuthUsername(), addr, protocol, origin, brand, host, userAgent, rewind);
-
- try {
- HttpURLConnection conn = (HttpURLConnection) new URL(webhook).openConnection();
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Content-Type", "application/json");
- conn.setDoOutput(true);
- conn.setConnectTimeout(5000);
- conn.setReadTimeout(5000);
-
- try (OutputStream os = conn.getOutputStream()) {
- os.write(payload.getBytes());
- }
-
- conn.getInputStream().close();
- } catch (Exception e) {
- getLogger().warn("Failed to send webhook: " + e);
- }
+ });
}
public static void init() {
diff --git a/src/main/java/dev/colbster937/originblacklist/base/ConfigManager.java b/src/main/java/dev/colbster937/originblacklist/base/ConfigManager.java
index 2310ba4..f0a6268 100644
--- a/src/main/java/dev/colbster937/originblacklist/base/ConfigManager.java
+++ b/src/main/java/dev/colbster937/originblacklist/base/ConfigManager.java
@@ -3,47 +3,73 @@ package dev.colbster937.originblacklist.base;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.constructor.Constructor;
-import java.io.File;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
+import org.yaml.snakeyaml.DumperOptions;
+import java.io.*;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.List;
+import java.util.Map;
public class ConfigManager {
public Messages messages = new Messages();
- public List subscriptions;
+ public List subscriptions = List.of();
public Blacklist blacklist = new Blacklist();
public Discord discord = new Discord();
public static ConfigManager loadConfig(Base.LoggerAdapter logger) {
- File conf = new File("plugins/originblacklist/config.yml");
+ File f = new File("plugins/originblacklist/config.yml");
try {
- if (!conf.exists()) {
- conf.getParentFile().mkdirs();
+ if (!f.exists()) {
+ f.getParentFile().mkdirs();
try (InputStream in = ConfigManager.class.getResourceAsStream("/config.yml")) {
- if (in != null) {
- Files.copy(in, conf.toPath(), StandardCopyOption.REPLACE_EXISTING);
- }
+ if (in != null) Files.copy(in, f.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
- LoaderOptions options = new LoaderOptions();
- Constructor constructor = new Constructor(ConfigManager.class, options);
- Yaml yaml = new Yaml(constructor);
- return yaml.load(new FileInputStream(conf));
+ Yaml y = new Yaml(new Constructor(ConfigManager.class, new LoaderOptions()));
+ ConfigManager l;
+ try (InputStream in = new FileInputStream(f)) { l = y.load(in); }
+
+ if (l == null) l = new ConfigManager();
+
+ Yaml raw = new Yaml();
+ Map u = raw.load(new FileInputStream(f));
+ Map d = raw.load(ConfigManager.class.getResourceAsStream("/config.yml"));
+ if (mergeConfig(u, d)) saveConfig(u, f);
+
+ return l;
} catch (IOException e) {
return new ConfigManager();
}
}
+ @SuppressWarnings("unchecked")
+ private static boolean mergeConfig(Map u, Map d) {
+ boolean c = false;
+ for (String k : d.keySet()) {
+ if (!u.containsKey(k)) {
+ u.put(k, d.get(k));
+ c = true;
+ } else if (u.get(k) instanceof Map && d.get(k) instanceof Map)
+ c |= mergeConfig((Map) u.get(k), (Map) d.get(k));
+ }
+ return c;
+ }
+
+ private static void saveConfig(Map m, File f) throws IOException {
+ DumperOptions o = new DumperOptions();
+ o.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ o.setPrettyFlow(true);
+ new Yaml(o).dump(m, new FileWriter(f));
+ }
+
public static class Blacklist {
public List origins;
public List brands;
public List players;
public boolean missing_origin;
+ public String blacklist_redirect;
}
public static class Discord {
diff --git a/src/main/java/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit.java b/src/main/java/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit.java
index 5354538..4735e1a 100644
--- a/src/main/java/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit.java
+++ b/src/main/java/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit.java
@@ -2,7 +2,7 @@ package dev.colbster937.originblacklist.bukkit;
import dev.colbster937.originblacklist.base.Base;
import net.lax1dude.eaglercraft.backend.server.api.bukkit.EaglerXServerAPI;
-import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftClientBrandEvent;
+import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftLoginEvent;
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftMOTDEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -42,7 +42,7 @@ public class OriginBlacklistBukkit extends JavaPlugin implements Listener {
}
@EventHandler
- public void onLogin(EaglercraftClientBrandEvent event) {
+ public void onLogin(EaglercraftLoginEvent event) {
Base.handleConnection(event);
}
diff --git a/src/main/java/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee.java b/src/main/java/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee.java
index 5ed6065..aea4236 100644
--- a/src/main/java/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee.java
+++ b/src/main/java/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee.java
@@ -2,7 +2,7 @@ package dev.colbster937.originblacklist.bungee;
import dev.colbster937.originblacklist.base.Base;
import net.lax1dude.eaglercraft.backend.server.api.bungee.EaglerXServerAPI;
-import net.lax1dude.eaglercraft.backend.server.api.bungee.event.EaglercraftClientBrandEvent;
+import net.lax1dude.eaglercraft.backend.server.api.bungee.event.EaglercraftLoginEvent;
import net.lax1dude.eaglercraft.backend.server.api.bungee.event.EaglercraftMOTDEvent;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.Listener;
@@ -41,7 +41,7 @@ public class OriginBlacklistBungee extends Plugin implements Listener {
}
@EventHandler
- public void onLogin(EaglercraftClientBrandEvent event) {
+ public void onLogin(EaglercraftLoginEvent event) {
Base.handleConnection(event);
}
diff --git a/src/main/java/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity.java b/src/main/java/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity.java
index 2019582..ed6f89a 100644
--- a/src/main/java/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity.java
+++ b/src/main/java/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity.java
@@ -6,7 +6,7 @@ import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.proxy.ProxyServer;
import dev.colbster937.originblacklist.base.Base;
import net.lax1dude.eaglercraft.backend.server.api.velocity.EaglerXServerAPI;
-import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftClientBrandEvent;
+import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftLoginEvent;
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftMOTDEvent;
import org.slf4j.Logger;
@@ -44,7 +44,7 @@ public class OriginBlacklistVelocity {
}
@Subscribe
- public void onLogin(EaglercraftClientBrandEvent event) {
+ public void onLogin(EaglercraftLoginEvent event) {
Base.handleConnection(event);
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index e7e8b09..6d34b2b 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -28,6 +28,7 @@ blacklist:
- "*dragonx*"
- "*piclient*"
missing_origin: false
+ blacklist_redirect: ""
discord:
webhook: ""
@@ -63,7 +64,6 @@ discord:
-
# :>
\ No newline at end of file