Skip to content

Commit 16953bc

Browse files
committed
1.0.6 cool cool player blacklisting
1 parent 0f80dde commit 16953bc

File tree

4 files changed

+41
-29
lines changed

4 files changed

+41
-29
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ basically just a reimplementation of originblacklist but for eaglerxserver
88
### Features
99
- [x] Origin Blacklisting
1010
- [x] Brand Blacklisting
11+
- [x] Username blacklisting
1112
- [x] Custom kick message
1213
- [x] Custom blacklist MOTD
1314
- [x] MiniMessage formatting for messages

src/main/java/dev/colbster937/originblacklist/base/Base.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import net.kyori.adventure.text.minimessage.MiniMessage;
55
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
66
import net.lax1dude.eaglercraft.backend.server.api.*;
7-
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftClientBrandEvent;
87
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftLoginEvent;
98
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftMOTDEvent;
109
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
@@ -14,8 +13,6 @@
1413
import java.io.*;
1514
import java.net.HttpURLConnection;
1615
import java.net.URL;
17-
import java.nio.charset.Charset;
18-
import java.nio.charset.StandardCharsets;
1916
import java.nio.file.Files;
2017
import java.nio.file.StandardCopyOption;
2118
import java.util.List;
@@ -69,41 +66,43 @@ public static void handleConnection(IEaglercraftLoginEvent e) {
6966
IEaglerLoginConnection conn = e.getLoginConnection();
7067
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
7168
String brand = conn.getEaglerBrandString();
69+
String name = conn.getUsername();
7270

73-
if (origin != null && !origin.equals("null") && !config.blacklist.missing_origin) {
71+
if (origin != null && !origin.equals("null")) {
7472
for (String origin1 : config.blacklist.origins) {
7573
if (matches(origin, origin1)) {
76-
setKick(e, kick("origin", "website", origin, conn.getWebSocketHost()));
74+
setKick(e, formatKickMessage("origin", "website", origin, conn.getWebSocketHost()));
7775
webhook(conn, origin, brand, "origin");
7876
return;
7977
}
8078
}
81-
} else if (origin != null && !origin.equals("null")) {
82-
setKick(e, kick("origin", "website", origin, conn.getWebSocketHost()));
83-
webhook(conn, "null", brand, "origin");
84-
return;
8579
}
8680

8781
if (brand != null && !brand.equals("null")) {
8882
for (String brand1 : config.blacklist.brands) {
8983
if (matches(brand, brand1)) {
90-
setKick(e, kick("brand", "client", brand, conn.getWebSocketHost()));
84+
setKick(e, formatKickMessage("brand", "client", brand, conn.getWebSocketHost()));
9185
webhook(conn, origin, brand, "brand");
9286
return;
9387
}
9488
}
9589
}
90+
91+
if (name != null && !name.equals("null")) {
92+
for (String name1 : config.blacklist.players) {
93+
if (matches(name, name1) || (name.length() > 16 || name.length() < 3)) {
94+
setKick(e, formatKickMessage("player", "username", name, conn.getWebSocketHost()));
95+
webhook(conn, origin, name, "player");
96+
return;
97+
}
98+
}
99+
}
96100
}
97101

98102
public static void setKick(IEaglercraftLoginEvent e, Component msg) {
99103
try {
100-
String redir = config.blacklist.blacklist_redirect;
101-
if (redir.equals("") || redir.equals("null")) {
102-
e.setKickMessage(msg);
103-
} else {
104-
e.setKickRedirect(redir);
105-
}
106104
getLogger().info("Kicked " + e.getProfileUsername());
105+
e.setKickMessage(msg);
107106
} catch (Throwable ignored) {
108107
String msg1 = LegacyComponentSerializer.legacySection().serialize(msg);
109108
e.setKickMessage(msg1);
@@ -124,7 +123,7 @@ public static void handleMOTD(IEaglercraftMOTDEvent e) {
124123
MiniMessage.miniMessage().deserialize(line)))
125124
.collect(Collectors.toList());
126125

127-
if (origin != null && !origin.equals("null") && !config.blacklist.missing_origin) {
126+
if (origin != null && !origin.equals("null")) {
128127
for (String origin1 : config.blacklist.origins) {
129128
if (matches(origin, origin1)) {
130129
setMOTD(conn, m);
@@ -173,9 +172,16 @@ public static boolean matches(String text1, String text2) {
173172
return text1.toLowerCase().matches(text2.replace(".", "\\.").replaceAll("\\*", ".*").toLowerCase());
174173
}
175174

176-
public static Component kick(String type, String easytype, String value, String host) {
175+
public static Component formatKickMessage(String type, String easytype, String value, String host) {
176+
String help = "";
177+
if (type != "player") {
178+
help = config.messages.help.generic;
179+
} else {
180+
help = config.messages.help.player;
181+
}
177182
return MiniMessage.miniMessage().deserialize(
178183
config.messages.kick
184+
.replaceAll("%help%", help)
179185
.replaceAll("%blocktype%", type)
180186
.replaceAll("%easyblocktype%", easytype)
181187
.replaceAll("%blocked%", value)

src/main/java/dev/colbster937/originblacklist/base/ConfigManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,17 @@ public static class Discord {
7979
public static class Messages {
8080
public String kick;
8181
public MOTD motd;
82+
public Help help;
8283
}
8384

8485
public static class MOTD {
8586
public boolean enabled;
8687
public String text;
8788
public String icon;
8889
}
90+
91+
public static class Help {
92+
public String generic;
93+
public String player;
94+
}
8995
}

src/main/resources/config.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ messages:
44
# - %blocktype% - Shows what the player was blocked for
55
# - %easyblocktype% - Shows what the player was blocked for in an eagler-kid readable form
66
# - %host% - The IP the player pinged
7+
# - %help% - The configured help message for the block type
78

89
kick: |
910
<red>This %easyblocktype% is not allowed on the server!</red>
1011
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
12+
13+
%help%
1114
1215
<gray>Think this is a mistake? Join our discord:</gray>
1316
<blue>discord.gg/changethisintheconfig</blue>
17+
18+
# Please note that help is only supported in the kick message, not the MOTD
19+
help:
20+
generic: "<gray>Please switch to a different %easyblocktype%.</gray>"
21+
player: "<gray>Please change your %easyblocktype%.</gray>"
1422

1523
motd:
1624
enabled: true
@@ -27,8 +35,8 @@ blacklist:
2735
brands:
2836
- "*dragonx*"
2937
- "*piclient*"
30-
missing_origin: false
31-
blacklist_redirect: ""
38+
players:
39+
- "Admin"
3240

3341
discord:
3442
webhook: ""
@@ -47,15 +55,6 @@ discord:
4755

4856

4957

50-
51-
52-
53-
54-
55-
56-
57-
58-
5958

6059

6160

0 commit comments

Comments
 (0)