mirror of
https://github.com/colbster937/originblacklist.git
synced 2025-06-07 16:24:48 +00:00
1.0.1
This commit is contained in:
parent
3a7b88f362
commit
7de763e640
15
README.md
15
README.md
@ -5,12 +5,25 @@ basically just a reimplementation of originblacklist but for eaglerxserver
|
||||
> [!WARNING]
|
||||
> **Velocity is the main platform I'm developing this for, bungee & bukkit will still work but will probably have some bugs and will receive less support!**
|
||||
|
||||
### Features
|
||||
- [x] Origin Blacklisting
|
||||
- [x] Brand Blacklisting
|
||||
- [x] Custom kick message
|
||||
- [x] Custom blacklist MOTD
|
||||
- [x] MiniMessage formatting for messages
|
||||
- [x] Velocity, *Bungee, and *Bukkit support
|
||||
<br>_<sub><span style="color:gray">Bungee and Bukkit are should work, but have bugs.</span></sub>_
|
||||
- [x] Send blacklists to a discord webhook
|
||||
- [ ] Blacklist subscription URLs
|
||||
- [ ] Blacklist -> Whitelist
|
||||
- [ ] IP blacklisting
|
||||
|
||||
### Download
|
||||
**[https://github.com/colbster937/originblacklist/releases](https://github.com/colbster937/originblacklist/releases)**
|
||||
|
||||
### Building
|
||||
```
|
||||
$ git clone https://github.com/colbster937/originblacklist
|
||||
$ git clone https://github.com/colbster937/originblacklist.git
|
||||
$ cd originblacklist
|
||||
$ gradle wrapper
|
||||
$ ./gradle.<bat|sh> shadowJar
|
||||
|
@ -8,7 +8,7 @@ plugins {
|
||||
|
||||
|
||||
group = 'dev.colbster937'
|
||||
version = '1.0.0'
|
||||
version = '1.0.1'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -6,9 +6,21 @@ import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerPlayer;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.EnumWebSocketHeader;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftInitializePlayerEvent;
|
||||
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.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Base {
|
||||
private static LoggerAdapter adapter;
|
||||
@ -61,6 +73,60 @@ public class Base {
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleMOTD(IEaglercraftMOTDEvent e) {
|
||||
if (config.messages.motd.enabled) {
|
||||
IMOTDConnection conn = e.getMOTDConnection();
|
||||
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||
List<String> m = List.of(config.messages.motd.text.split("\n")).stream()
|
||||
.map(line -> line
|
||||
.replace("%blocktype%", "origin")
|
||||
.replace("%easyblocktype%", "website")
|
||||
.replace("%blocked%", origin))
|
||||
.map(line -> LegacyComponentSerializer.legacySection()
|
||||
.serialize(MiniMessage.miniMessage().deserialize(line)))
|
||||
.collect(Collectors.toList());
|
||||
if ((origin != "null" || origin != null) && !config.blacklist.missing_origin) {
|
||||
for (String origin1 : config.blacklist.origins) {
|
||||
if (matches(origin, origin1)) {
|
||||
setMOTD(conn, m);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setMOTD(conn, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setMOTD(IMOTDConnection conn, List<String> m) {
|
||||
conn.setServerMOTD(m);
|
||||
conn.setPlayerTotal(0);
|
||||
conn.setPlayerMax(0);
|
||||
conn.setPlayerList(List.of());
|
||||
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++) {
|
||||
int pixel = img.getRGB(x, y);
|
||||
int i = (y * 64 + x) * 4;
|
||||
bytes[i] = (byte) ((pixel >> 16) & 0xFF);
|
||||
bytes[i + 1] = (byte) ((pixel >> 8) & 0xFF);
|
||||
bytes[i + 2] = (byte) (pixel & 0xFF);
|
||||
bytes[i + 3] = (byte) ((pixel >> 24) & 0xFF);
|
||||
}
|
||||
}
|
||||
conn.setServerIcon(bytes);
|
||||
} catch (IOException ex) {
|
||||
getLogger().error(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean matches(String text1, String text2) {
|
||||
return text1.toLowerCase().matches(text2.replace(".", "\\.").replaceAll("\\*", ".*").toLowerCase());
|
||||
}
|
||||
@ -119,6 +185,19 @@ public class Base {
|
||||
}
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
File motdIcon = new File(config.messages.motd.icon);
|
||||
if (!motdIcon.exists()) {
|
||||
try (InputStream in = ConfigManager.class.getResourceAsStream("/server-blocked.png")) {
|
||||
if (in != null) {
|
||||
Files.copy(in, motdIcon.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
getLogger().warn(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadConfig() {
|
||||
config = ConfigManager.loadConfig(adapter);
|
||||
}
|
||||
|
@ -44,8 +44,6 @@ public class ConfigManager {
|
||||
public List<String> brands;
|
||||
public List<String> players;
|
||||
public boolean missing_origin;
|
||||
|
||||
public Blacklist() {}
|
||||
}
|
||||
|
||||
public static class Discord {
|
||||
@ -54,5 +52,12 @@ public class ConfigManager {
|
||||
|
||||
public static class Messages {
|
||||
public String kick;
|
||||
public MOTD motd;
|
||||
}
|
||||
|
||||
public static class MOTD {
|
||||
public boolean enabled;
|
||||
public String text;
|
||||
public String icon;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,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.EaglercraftInitializePlayerEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftMOTDEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -19,6 +20,7 @@ public class OriginBlacklistBukkit extends JavaPlugin implements Listener {
|
||||
|
||||
Base.setApi(EaglerXServerAPI.instance());
|
||||
Base.reloadConfig();
|
||||
Base.init();
|
||||
|
||||
getCommand("originblacklist").setExecutor(new CommandBukkit());
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
@ -30,4 +32,9 @@ public class OriginBlacklistBukkit extends JavaPlugin implements Listener {
|
||||
public void onLogin(EaglercraftInitializePlayerEvent event) {
|
||||
Base.handleConnection(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||
Base.handleMOTD(event);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,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.EaglercraftInitializePlayerEvent;
|
||||
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;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
@ -19,6 +20,7 @@ public class OriginBlacklistBungee extends Plugin implements Listener {
|
||||
|
||||
Base.setApi(EaglerXServerAPI.instance());
|
||||
Base.reloadConfig();
|
||||
Base.init();
|
||||
|
||||
getProxy().getPluginManager().registerCommand(this, new CommandBungee());
|
||||
getProxy().getPluginManager().registerListener(this, this);
|
||||
@ -30,4 +32,9 @@ public class OriginBlacklistBungee extends Plugin implements Listener {
|
||||
public void onLogin(EaglercraftInitializePlayerEvent event) {
|
||||
Base.handleConnection(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||
Base.handleMOTD(event);
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,14 @@ 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.EaglercraftInitializePlayerEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftMOTDEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftMOTDEvent;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@Plugin(
|
||||
id = "originblacklist",
|
||||
name = "OriginBlacklist",
|
||||
version = "1.0.0",
|
||||
version = "1.0.1",
|
||||
authors = {"Colbster937"},
|
||||
description = "A reimplementation of OriginBlacklist for EaglerXServer",
|
||||
dependencies = {@Dependency(id = "eaglerxserver")}
|
||||
@ -39,6 +41,7 @@ public class OriginBlacklistVelocity {
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
Base.setApi(EaglerXServerAPI.instance());
|
||||
Base.reloadConfig();
|
||||
Base.init();
|
||||
proxy.getCommandManager().register("originblacklist", new CommandVelocity());
|
||||
logger.info("Loaded Velocity plugin");
|
||||
}
|
||||
@ -47,4 +50,9 @@ public class OriginBlacklistVelocity {
|
||||
public void onLogin(EaglercraftInitializePlayerEvent event) {
|
||||
Base.handleConnection(event);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onMOTD(IEaglercraftMOTDEvent event) {
|
||||
Base.handleMOTD(event);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: OriginBlacklist
|
||||
version: 1.0.0
|
||||
version: 1.0.1
|
||||
main: dev.colbster937.originblacklist.bungee.OriginBlacklistBungee
|
||||
description: A reimplementation of OriginBlacklist for EaglerXServer
|
||||
author: Colbster937
|
||||
|
@ -11,6 +11,13 @@ messages:
|
||||
<gray>Think this is a mistake? Join our discord:</gray>
|
||||
<blue>discord.gg/changethisintheconfig</blue>
|
||||
|
||||
motd:
|
||||
enabled: true
|
||||
text: |
|
||||
<red>This %easyblocktype% is not allowed!</red>
|
||||
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
|
||||
icon: "blacklisted.png"
|
||||
|
||||
# Origin + Brand blacklist supports wildcards
|
||||
# Everything should be lowercase
|
||||
blacklist:
|
||||
@ -51,13 +58,6 @@ discord:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: OriginBlacklist
|
||||
version: 1.0.0
|
||||
version: 1.0.1
|
||||
main: dev.colbster937.originblacklist.bukkit.OriginBlacklistBukkit
|
||||
description: A reimplementation of OriginBlacklist for EaglerXServer
|
||||
author: Colbster937
|
||||
|
BIN
src/main/resources/server-blocked.png
Normal file
BIN
src/main/resources/server-blocked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
Loading…
x
Reference in New Issue
Block a user