Compare commits

...

8 Commits

Author SHA1 Message Date
Colbster937
eab1eb27e7 fix 2026-01-02 19:51:06 -06:00
Colbster937
0b6e9e1b83 rm .vscode 2026-01-02 19:45:23 -06:00
Colbster937
07fa4bc21c switch to kotlin dsl & fix build on gradle 9 2026-01-02 19:44:41 -06:00
Colbster937
b10882c65f Update build.gradle 2026-01-02 19:37:46 -06:00
Colbster937
ee4b14bf30 Merge pull request #2 from Cirsius/main
bug fixes by @cirsius
2026-01-02 19:37:27 -06:00
Cirsius
c913d9d34e make work with eaglermotd 2026-01-02 19:12:21 -06:00
Cirsius
bfed49407f fix bug w ipv6 2026-01-02 17:42:22 -06:00
Colbster937
d4541c9de4 udpate 2025-08-08 10:40:19 -05:00
11 changed files with 158 additions and 165 deletions

View File

@@ -28,7 +28,7 @@ jobs:
- name: Build Jar - name: Build Jar
run: | run: |
gradle wrapper gradle wrapper
./gradlew shadowJar ./gradlew clean shadowJar
- name: Publish Jar - name: Publish Jar
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
@@ -39,7 +39,7 @@ jobs:
- name: Extract Version - name: Extract Version
id: version id: version
run: | run: |
VERSION=$(grep "^version" build.gradle | head -n 1 | cut -d\' -f2) VERSION="$(./gradlew -q properties | sed -n 's/^version: //p' | head -n 1)"
echo "version=$VERSION" >> "$GITHUB_OUTPUT" echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Remove Existing Release - name: Remove Existing Release

View File

@@ -1,86 +0,0 @@
plugins {
id 'java'
id 'eclipse'
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.8'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id("xyz.jpenilla.run-velocity") version "2.3.1"
}
group = 'dev.colbster937'
version = '1.1.1'
description = 'A reimplementation of OriginBlacklist for EaglerXServer'
def targetJavaVersion = 17
repositories {
mavenCentral()
maven {
name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
maven {
name = "spigotmc-repo"
url = "https://hub.spigotmc.org/nexus/content/repositories/public/"
}
maven {
name = "md_5"
url = "https://repo.md-5.net/content/repositories/releases/"
}
maven {
name = "aikar"
url = "https://repo.aikar.co/nexus/content/groups/aikar/"
}
maven {
name = "lax1dude"
url = "https://repo.lax1dude.net/repository/releases/"
}
}
dependencies {
compileOnly("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
annotationProcessor("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
compileOnly("org.bukkit:bukkit:1.8-R0.1-SNAPSHOT")
compileOnly("net.md-5:bungeecord-api:1.8-SNAPSHOT")
compileOnly("net.lax1dude.eaglercraft.backend:api-velocity:1.0.0")
compileOnly("net.lax1dude.eaglercraft.backend:api-bungee:1.0.0")
compileOnly("net.lax1dude.eaglercraft.backend:api-bukkit:1.0.0")
implementation("org.yaml:snakeyaml:2.2")
implementation("net.kyori:adventure-text-serializer-legacy:4.20.0")
implementation("net.kyori:adventure-text-minimessage:4.20.0")
implementation("com.github.seancfoley:ipaddress:5.3.4")
}
tasks {
runVelocity {
velocityVersion("3.3.0-SNAPSHOT")
}
}
java {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
processResources {
filesMatching(['plugin.yml', 'bungee.yml', 'velocity-plugin.json', 'Base.java']) {
expand(
version: project.version,
description: project.description
)
}
}
shadowJar {
relocate 'org.yaml.snakeyaml', 'dev.colbster937.shaded.snakeyaml'
relocate 'inet.ipaddr', 'dev.colbster937.shaded.ipaddr'
archiveVersion.set('')
archiveClassifier.set('')
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release.set(targetJavaVersion)
}

70
build.gradle.kts Normal file
View File

@@ -0,0 +1,70 @@
plugins {
id("java")
id("eclipse")
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.8"
id("com.gradleup.shadow") version "9.3.0"
id("xyz.jpenilla.run-velocity") version "2.3.1"
}
group = "dev.colbster937"
version = "1.1.3"
description = "A reimplementation of OriginBlacklist for EaglerXServer"
val targetJavaVersion = 17
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://hub.spigotmc.org/nexus/content/repositories/public/")
maven("https://repo.md-5.net/content/repositories/releases/")
maven("https://repo.aikar.co/nexus/content/groups/aikar/")
maven("https://repo.lax1dude.net/repository/releases/")
}
dependencies {
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
compileOnly("org.bukkit:bukkit:1.8-R0.1-SNAPSHOT")
compileOnly("net.md-5:bungeecord-api:1.8-SNAPSHOT")
compileOnly("net.lax1dude.eaglercraft.backend:api-velocity:1.0.0")
compileOnly("net.lax1dude.eaglercraft.backend:api-bungee:1.0.0")
compileOnly("net.lax1dude.eaglercraft.backend:api-bukkit:1.0.0")
implementation("org.yaml:snakeyaml:2.2")
implementation("net.kyori:adventure-text-serializer-legacy:4.20.0")
implementation("net.kyori:adventure-text-minimessage:4.20.0")
implementation("com.github.seancfoley:ipaddress:5.3.4")
annotationProcessor("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
}
tasks {
named<xyz.jpenilla.runvelocity.task.RunVelocity>("runVelocity") {
velocityVersion("3.4.0-SNAPSHOT")
}
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(targetJavaVersion))
}
tasks.processResources {
filesMatching(listOf("plugin.yml", "bungee.yml", "velocity-plugin.json", "Base.java")) {
expand(
mapOf(
"version" to project.version,
"description" to project.description
)
)
}
}
tasks.shadowJar {
relocate("org.yaml.snakeyaml", "dev.colbster937.shaded.snakeyaml")
relocate("inet.ipaddr", "dev.colbster937.shaded.ipaddr")
archiveVersion.set("")
archiveClassifier.set("")
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(targetJavaVersion)
}

View File

View File

@@ -1 +0,0 @@
rootProject.name = 'OriginBlacklist'

View File

@@ -69,6 +69,7 @@ public class Base {
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN); String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
String brand = conn.getEaglerBrandString(); String brand = conn.getEaglerBrandString();
String name = conn.getUsername(); String name = conn.getUsername();
String ip = getAddr(conn);
String notAllowed1 = "not allowed on the server"; String notAllowed1 = "not allowed on the server";
String notAllowed2 = "not allowed"; String notAllowed2 = "not allowed";
@@ -96,11 +97,18 @@ public class Base {
for (String name1 : config.blacklist.players) { for (String name1 : config.blacklist.players) {
if (matches(name, name1) || (name.length() > 16 || name.length() < 3)) { if (matches(name, name1) || (name.length() > 16 || name.length() < 3)) {
setKick(e, formatKickMessage("player", "username", notAllowed1, notAllowed2, name, conn.getWebSocketHost())); setKick(e, formatKickMessage("player", "username", notAllowed1, notAllowed2, name, conn.getWebSocketHost()));
webhook(conn, origin, name, "player"); webhook(conn, origin, brand, "player");
return; return;
} }
} }
} }
if (ip != null && !ip.equalsIgnoreCase("null")) {
if (ipblacklist.check(ip)) {
setKick(e, formatKickMessage("ip address", "ip", notAllowed1, notAllowed2, ip, conn.getWebSocketHost()));
webhook(conn, origin, brand, "ip");
}
}
} }
public static void setKick(IEaglercraftLoginEvent e, Component msg) { public static void setKick(IEaglercraftLoginEvent e, Component msg) {
@@ -114,30 +122,61 @@ public class Base {
} }
public static void handleMOTD(IEaglercraftMOTDEvent e) { public static void handleMOTD(IEaglercraftMOTDEvent e) {
if (config.messages.motd.enabled) { if (!config.messages.motd.enabled) return;
IMOTDConnection conn = e.getMOTDConnection(); IMOTDConnection conn = e.getMOTDConnection();
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN); String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
String host = conn.getWebSocketHost() != null ? conn.getWebSocketHost() : "";
String ip = getAddr(conn);
String blocktype1 = null;
String easyblocktype1 = null;
String blocked1 = null;
if (origin != null && !"null".equals(origin)) {
for (String origin2 : config.blacklist.origins) {
if (matches(origin, origin2)) {
blocktype1 = "origin";
easyblocktype1 = "website";
blocked1 = origin;
break;
}
}
}
if (blocktype1 == null && ip != null && !"null".equalsIgnoreCase(ip)) {
boolean blocked = ipblacklist != null && ipblacklist.check(ip);
if (!blocked) {
for (String ip2 : config.blacklist.ips) {
if (matches(ip, ip2)) { blocked = true; break; }
}
}
if (blocked) {
blocktype1 = "ip address";
easyblocktype1 = "ip";
blocked1 = ip;
}
}
if (blocktype1 == null) return;
final String finalBlocktype = blocktype1;
final String finalEasyblocktype = easyblocktype1;
final String finalBlocked = blocked1;
List<String> m = List.of(config.messages.motd.text.split("\n")).stream() List<String> m = List.of(config.messages.motd.text.split("\n")).stream()
.map(line -> line .map(line -> line
.replaceAll("%blocktype%", "origin") .replace("%blocktype%", finalBlocktype)
.replaceAll("%easyblocktype%", "website") .replace("%easyblocktype%", finalEasyblocktype)
.replaceAll("%notallowed1%", "blacklisted") .replace("%notallowed1%", "blacklisted")
.replaceAll("%notallowed2%", "blacklisted") .replace("%notallowed2%", "blacklisted")
.replaceAll("%blocked%", origin) .replace("%blocked%", finalBlocked)
.replaceAll("%host%", conn.getWebSocketHost())) .replace("%host%", host))
.map(line -> LegacyComponentSerializer.legacySection().serialize( .map(line -> LegacyComponentSerializer.legacySection()
MiniMessage.miniMessage().deserialize(line))) .serialize(MiniMessage.miniMessage().deserialize(line)))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (origin != null && !origin.equals("null")) {
for (String origin1 : config.blacklist.origins) {
if (matches(origin, origin1)) {
setMOTD(conn, m); setMOTD(conn, m);
return;
}
}
}
}
} }
public static void setMOTD(IMOTDConnection conn, List<String> m) { public static void setMOTD(IMOTDConnection conn, List<String> m) {
@@ -170,18 +209,8 @@ public class Base {
getLogger().error(ex.toString()); getLogger().error(ex.toString());
} }
} }
} conn.sendToUser();
conn.disconnect();
public static String handlePre(String ip, String name) {
if (ip != null && !ip.equalsIgnoreCase("null")) {
for (String ip1 : Base.config.blacklist.ips) {
if (ipblacklist.check(ip)) {
Component kick = formatKickMessage("ip address", "ip", "blacklisted", "blacklisted", ip, "");
return LegacyComponentSerializer.legacySection().serialize(kick);
}
}
}
return "false";
} }
public static boolean matches(String text1, String text2) { public static boolean matches(String text1, String text2) {
@@ -190,12 +219,12 @@ public class Base {
public static Component formatKickMessage(String type, String easytype, String notAllowed1, String notAllowed2, String value, String host) { public static Component formatKickMessage(String type, String easytype, String notAllowed1, String notAllowed2, String value, String host) {
String help = ""; String help = "";
if (type != "player") { if ("player".equals(type)) {
help = config.messages.help.generic; help = config.messages.help.player;
} else if (type == "ip") { } else if ("ip address".equals(type)) {
help = config.messages.help.ip; help = config.messages.help.ip;
} else { } else {
help = config.messages.help.player; help = config.messages.help.generic;
} }
return MiniMessage.miniMessage().deserialize( return MiniMessage.miniMessage().deserialize(
config.messages.kick config.messages.kick
@@ -229,7 +258,7 @@ public class Base {
"embeds": [ "embeds": [
{ {
"title": "Player Information", "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" "description": "🎮 **Name:** %s\\n🏠 **IP:** %s\\n🌄 **PVN:** %s\\n🌐 **Origin:** %s\\n🔋 **Brand:** %s\\n🪑 **Host:** %s\\n🧊 **UA:** %s\\n⏪ **Rewind:** %s"
} }
] ]
} }
@@ -255,8 +284,14 @@ public class Base {
}); });
} }
public static String getAddr(IEaglerLoginConnection plr) { public static String getAddr(IEaglerLoginConnection conn) {
var addr1 = plr.getPlayerAddress() != null ? plr.getPlayerAddress().toString().substring(1) : "undefined:undefined"; var addr1 = conn.getPlayerAddress() != null ? conn.getPlayerAddress().toString().substring(1) : "0.0.0.0:0";
var addr2 = addr1.lastIndexOf(':') != -1 ? addr1.substring(0, addr1.lastIndexOf(':')) : addr1;
return addr2;
}
public static String getAddr(IMOTDConnection conn) {
var addr1 = conn.getSocketAddress() != null ? conn.getSocketAddress().toString().substring(1) : "0.0.0.0:0";
var addr2 = addr1.lastIndexOf(':') != -1 ? addr1.substring(0, addr1.lastIndexOf(':')) : addr1; var addr2 = addr1.lastIndexOf(':') != -1 ? addr1.substring(0, addr1.lastIndexOf(':')) : addr1;
return addr2; return addr2;
} }

View File

@@ -22,6 +22,9 @@ public class IPBlacklist {
if (addr.startsWith("/")) { if (addr.startsWith("/")) {
addr1 = addr.substring(1); addr1 = addr.substring(1);
} }
if (addr1.startsWith("[") && addr1.endsWith("]")) {
addr1 = addr1.substring(1, addr1.length() - 1);
}
ip = new IPAddressString(addr1).toAddress(); ip = new IPAddressString(addr1).toAddress();
} catch (AddressStringException e) { } catch (AddressStringException e) {
throw new RuntimeException("Invalid IP address: " + addr, e); throw new RuntimeException("Invalid IP address: " + addr, e);

View File

@@ -5,8 +5,9 @@ import net.lax1dude.eaglercraft.backend.server.api.bukkit.EaglerXServerAPI;
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftLoginEvent; import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftLoginEvent;
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftMOTDEvent; import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftMOTDEvent;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@@ -47,18 +48,8 @@ public class OriginBlacklistBukkit extends JavaPlugin implements Listener {
Base.handleConnection(event); Base.handleConnection(event);
} }
@EventHandler @EventHandler(priority = EventPriority.MONITOR)
public void onMOTD(EaglercraftMOTDEvent event) { public void onMOTD(EaglercraftMOTDEvent event) {
Base.handleMOTD(event); Base.handleMOTD(event);
} }
@EventHandler
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
String ip = event.getAddress().getHostAddress();
String name = event.getName();
String blacklisted = Base.handlePre(ip, name);
if (!blacklisted.equals("false")) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, blacklisted);
}
}
} }

View File

@@ -8,6 +8,7 @@ import net.md_5.bungee.api.event.PreLoginEvent;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
public class OriginBlacklistBungee extends Plugin implements Listener { public class OriginBlacklistBungee extends Plugin implements Listener {
@@ -46,19 +47,8 @@ public class OriginBlacklistBungee extends Plugin implements Listener {
Base.handleConnection(event); Base.handleConnection(event);
} }
@EventHandler @EventHandler(priority = EventPriority.HIGHEST)
public void onMOTD(EaglercraftMOTDEvent event) { public void onMOTD(EaglercraftMOTDEvent event) {
Base.handleMOTD(event); Base.handleMOTD(event);
} }
@EventHandler
public void onPreLogin(PreLoginEvent event) {
String ip = event.getConnection().getAddress().getAddress().getHostAddress();
String name = event.getConnection().getName();
String blacklisted = Base.handlePre(ip, name);
if (!blacklisted.equals("false")) {
event.setCancelReason(blacklisted);
event.setCancelled(true);
}
}
} }

View File

@@ -1,6 +1,7 @@
package dev.colbster937.originblacklist.velocity; package dev.colbster937.originblacklist.velocity;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.event.connection.PreLoginEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
@@ -51,18 +52,8 @@ public class OriginBlacklistVelocity {
Base.handleConnection(event); Base.handleConnection(event);
} }
@Subscribe @Subscribe(order = PostOrder.LAST)
public void onMOTD(EaglercraftMOTDEvent event) { public void onMOTD(EaglercraftMOTDEvent event) {
Base.handleMOTD(event); Base.handleMOTD(event);
} }
@Subscribe
public void onPreLogin(PreLoginEvent event) {
String ip = event.getConnection().getRemoteAddress().getAddress().toString();
String name = event.getUsername();
String blacklisted = Base.handlePre(ip, name);
if (!blacklisted.equals("false")) {
event.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(blacklisted)));
}
}
} }

View File

@@ -27,7 +27,7 @@ messages:
enabled: true enabled: true
text: | text: |
<red>This %easyblocktype% is %notallowed2%!</red> <red>This %easyblocktype% is %notallowed2%!</red>
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray> <dark_gray>»</dark_gray> <gray>%blocked%</gray>
icon: "blacklisted.png" icon: "blacklisted.png"
# Origin + Brand blacklist supports wildcards # Origin + Brand blacklist supports wildcards