mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 11:07:41 +00:00
Compare commits
1 Commits
v2.0.7+1cd
...
v2.0.8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00b1c99dc4 |
@@ -14,7 +14,7 @@ val PLUGIN_NAME = "OriginBlacklist"
|
|||||||
val PLUGIN_IDEN = "originblacklist"
|
val PLUGIN_IDEN = "originblacklist"
|
||||||
val PLUGIN_DOMN = "xyz.webmc.$PLUGIN_IDEN"
|
val PLUGIN_DOMN = "xyz.webmc.$PLUGIN_IDEN"
|
||||||
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
||||||
val PLUGIN_VERS = "2.0.7"
|
val PLUGIN_VERS = "2.0.8"
|
||||||
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
||||||
val PLUGIN_DEPA = listOf("EaglercraftXServer")
|
val PLUGIN_DEPA = listOf("EaglercraftXServer")
|
||||||
val PLUGIN_DEPB = listOf("EaglercraftXServer")
|
val PLUGIN_DEPB = listOf("EaglercraftXServer")
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public final class OriginBlacklist {
|
|||||||
}
|
}
|
||||||
this.plugin.kickPlayer(this.getBlacklistedComponent("kick", blacklisted.getArrayString(),
|
this.plugin.kickPlayer(this.getBlacklistedComponent("kick", blacklisted.getArrayString(),
|
||||||
blacklisted.getAltString(), blacklisted.getString(), "not allowed", "not allowed on the server",
|
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);
|
this.sendWebhooks(event, blacklisted);
|
||||||
final String name = player.getName();
|
final String name = player.getName();
|
||||||
if (isNonNull(name)) {
|
if (isNonNull(name)) {
|
||||||
@@ -136,9 +136,12 @@ public final class OriginBlacklist {
|
|||||||
} else {
|
} else {
|
||||||
blacklisted_value = UNKNOWN_STR;
|
blacklisted_value = UNKNOWN_STR;
|
||||||
}
|
}
|
||||||
this.plugin.setMOTD(this.getBlacklistedComponent("motd", blacklisted.getArrayString(), blacklisted.getAltString(),
|
if (this.isMOTDEnabled()) {
|
||||||
blacklisted.getString(), "blacklisted", "blacklisted from the server", blacklisted_value,
|
this.plugin
|
||||||
blacklisted.getActionString()), event);
|
.setMOTD(this.getBlacklistedComponent("motd", blacklisted.getArrayString(), blacklisted.getAltString(),
|
||||||
|
blacklisted.getString(), "blacklisted", "blacklisted from the server", blacklisted_value,
|
||||||
|
blacklisted.getActionString(), true), event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +153,14 @@ public final class OriginBlacklist {
|
|||||||
return this.config.getBoolean("bStats");
|
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() {
|
public final boolean isLogFileEnabled() {
|
||||||
return this.config.getBoolean("logFile");
|
return this.config.getBoolean("logFile");
|
||||||
}
|
}
|
||||||
@@ -165,13 +176,17 @@ public final class OriginBlacklist {
|
|||||||
public final void setEaglerMOTD(final Component comp, final OriginBlacklistMOTDEvent event) {
|
public final void setEaglerMOTD(final Component comp, final OriginBlacklistMOTDEvent event) {
|
||||||
final IMOTDConnection conn = event.getEaglerEvent().getMOTDConnection();
|
final IMOTDConnection conn = event.getEaglerEvent().getMOTDConnection();
|
||||||
final List<String> lst = new ArrayList<>();
|
final List<String> lst = new ArrayList<>();
|
||||||
for (String ln : getComponentString(comp).split("\n")) {
|
for (final String ln : getComponentString(comp).split("\n")) {
|
||||||
lst.add(ln);
|
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.setServerMOTD(lst);
|
||||||
conn.setPlayerTotal(0);
|
conn.setPlayerTotal(this.config.getInteger("motd.players.online"));
|
||||||
conn.setPlayerUnlimited();
|
conn.setPlayerMax(this.config.getInteger("motd.players.max"));
|
||||||
conn.setPlayerList(List.of());
|
conn.setPlayerList(pLst);
|
||||||
conn.setServerIcon(this.config.getIconBytes());
|
conn.setServerIcon(this.config.getIconBytes());
|
||||||
conn.sendToUser();
|
conn.sendToUser();
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
@@ -345,8 +360,8 @@ public final class OriginBlacklist {
|
|||||||
|
|
||||||
private final Component getBlacklistedComponent(final String type, final String id, final String blockType,
|
private final Component getBlacklistedComponent(final String type, final String id, final String blockType,
|
||||||
final String blockTypeAlt, final String notAllowed, final String notAllowedAlt, final String blockValue,
|
final String blockTypeAlt, final String notAllowed, final String notAllowedAlt, final String blockValue,
|
||||||
final String action) {
|
final String action, final boolean isMOTD) {
|
||||||
final Json5Array arr = this.config.getArray("messages." + type);
|
final Json5Array arr = this.config.getArray(isMOTD ? (type + ".text") : ("messages." + type));
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
@@ -359,21 +374,26 @@ public final class OriginBlacklist {
|
|||||||
.replaceAll("%block_type%", blockType)
|
.replaceAll("%block_type%", blockType)
|
||||||
.replaceAll("%not_allowed%", notAllowed)
|
.replaceAll("%not_allowed%", notAllowed)
|
||||||
.replaceAll("%not_allowed_alt%", notAllowedAlt)
|
.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);
|
return MiniMessage.miniMessage().deserialize(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void sendWebhooks(final OriginBlacklistLoginEvent event, final EnumBlacklistType type) {
|
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 OPlayer player = event.getPlayer();
|
||||||
final EnumConnectionType connType = event.getConnectionType();
|
final EnumConnectionType connType = event.getConnectionType();
|
||||||
/* final String userAgent;
|
/*
|
||||||
if (connType == EnumConnectionType.EAGLER) {
|
* final String userAgent;
|
||||||
final IEaglerLoginConnection loginConn = event.getEaglerEvent().getLoginConnection();
|
* if (connType == EnumConnectionType.EAGLER) {
|
||||||
userAgent = loginConn.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT);
|
* final IEaglerLoginConnection loginConn =
|
||||||
} else {
|
* event.getEaglerEvent().getLoginConnection();
|
||||||
userAgent = UNKNOWN_STR;
|
* userAgent =
|
||||||
} */
|
* loginConn.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT);
|
||||||
|
* } else {
|
||||||
|
* userAgent = UNKNOWN_STR;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
final byte[] payload = String.format(
|
final byte[] payload = String.format(
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
@@ -466,17 +486,17 @@ public final class OriginBlacklist {
|
|||||||
private final void updateLogFile(final OriginBlacklistLoginEvent event, final EnumBlacklistType type) {
|
private final void updateLogFile(final OriginBlacklistLoginEvent event, final EnumBlacklistType type) {
|
||||||
if (this.isLogFileEnabled()) {
|
if (this.isLogFileEnabled()) {
|
||||||
final OPlayer player = event.getPlayer();
|
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());
|
final Path dir = Paths.get(this.getDataDir());
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
Files.writeString(
|
Files.writeString(
|
||||||
dir.resolve("blacklist.log"),
|
dir.resolve("blacklist.log"),
|
||||||
txt + "\n",
|
txt + "\n",
|
||||||
StandardOpenOption.CREATE,
|
StandardOpenOption.CREATE,
|
||||||
StandardOpenOption.WRITE,
|
StandardOpenOption.WRITE,
|
||||||
StandardOpenOption.APPEND
|
StandardOpenOption.APPEND);
|
||||||
);
|
|
||||||
} catch (final Throwable t) {
|
} catch (final Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ import de.marhali.json5.Json5Object;
|
|||||||
import de.marhali.json5.Json5Primitive;
|
import de.marhali.json5.Json5Primitive;
|
||||||
|
|
||||||
public final class OriginBlacklistConfig {
|
public final class OriginBlacklistConfig {
|
||||||
private static final Json5Object DEFAULT_CONFIG = getDefaultConfig();
|
public static final Json5Object DEFAULT_CONFIG = getDefaultConfig();
|
||||||
|
public static final int LATEST_CONFIG_VERSION = 2;
|
||||||
|
|
||||||
private final Json5 json5;
|
private final Json5 json5;
|
||||||
private final File file;
|
private final File file;
|
||||||
@@ -73,6 +74,7 @@ public final class OriginBlacklistConfig {
|
|||||||
Json5Element parsed = this.json5.parse(text);
|
Json5Element parsed = this.json5.parse(text);
|
||||||
if (parsed instanceof Json5Object) {
|
if (parsed instanceof Json5Object) {
|
||||||
this.config = (Json5Object) parsed;
|
this.config = (Json5Object) parsed;
|
||||||
|
this.config = OriginBlacklistConfigTransformer.transformConfig(this.config);
|
||||||
merge(this.config, DEFAULT_CONFIG);
|
merge(this.config, DEFAULT_CONFIG);
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Config must be an object!");
|
throw new IOException("Config must be an object!");
|
||||||
@@ -262,18 +264,29 @@ public final class OriginBlacklistConfig {
|
|||||||
kick.add("%action%");
|
kick.add("%action%");
|
||||||
kick.add("");
|
kick.add("");
|
||||||
kick.add("<aqua>Think this is a mistake? Join our discord:</aqua>");
|
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);
|
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();
|
final Json5Object actions = new Json5Object();
|
||||||
actions.add("generic", Json5Primitive.fromString("<gold>Please switch to a different %block_type%.</gold>"));
|
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("player_name", Json5Primitive.fromString("<gold>Please change your %block_type%.</gold>"));
|
||||||
actions.add("ip_address", Json5Primitive.fromString("<gold>Please contact staff for assistance.</gold>"));
|
actions.add("ip_address", Json5Primitive.fromString("<gold>Please contact staff for assistance.</gold>"));
|
||||||
addJSONObj(mObj, "actions", actions, null);
|
addJSONObj(mObj, "actions", actions, null);
|
||||||
addJSONObj(obj, "messages", mObj, 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 Json5Object bObj = new Json5Object();
|
||||||
final Json5Array origins = new Json5Array();
|
final Json5Array origins = new Json5Array();
|
||||||
origins.add(".*eaglerhackedclients\\.vercel\\.app.*");
|
origins.add(".*eaglerhackedclients\\.vercel\\.app.*");
|
||||||
@@ -302,9 +315,12 @@ public final class OriginBlacklistConfig {
|
|||||||
addJSONObj(bObj, "ip_addresses", ips, null);
|
addJSONObj(bObj, "ip_addresses", ips, null);
|
||||||
addJSONObj(obj, "blacklist", bObj, null);
|
addJSONObj(obj, "blacklist", bObj, null);
|
||||||
final Json5Object dObj = new Json5Object();
|
final Json5Object dObj = new Json5Object();
|
||||||
addJSONObj(dObj, "enabled", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(dObj, "invite", Json5Primitive.fromString("discord.gg/changeme"), null);
|
||||||
addJSONObj(dObj, "webhook_urls", new Json5Array(), null);
|
final Json5Object webhook = new Json5Object();
|
||||||
addJSONObj(dObj, "send_ips", Json5Primitive.fromBoolean(true), null);
|
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);
|
addJSONObj(obj, "discord", dObj, null);
|
||||||
final Json5Object uObj = new Json5Object();
|
final Json5Object uObj = new Json5Object();
|
||||||
addJSONObj(uObj, "enabled", Json5Primitive.fromBoolean(true), null);
|
addJSONObj(uObj, "enabled", Json5Primitive.fromBoolean(true), null);
|
||||||
@@ -317,7 +333,7 @@ public final class OriginBlacklistConfig {
|
|||||||
addJSONObj(obj, "block_undefined_origin", Json5Primitive.fromBoolean(false), null);
|
addJSONObj(obj, "block_undefined_origin", Json5Primitive.fromBoolean(false), null);
|
||||||
addJSONObj(obj, "bStats", Json5Primitive.fromBoolean(true), null);
|
addJSONObj(obj, "bStats", Json5Primitive.fromBoolean(true), null);
|
||||||
addJSONObj(obj, "logFile", 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;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user