mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 11:07:41 +00:00
2.0
This commit is contained in:
@@ -1,316 +0,0 @@
|
||||
package dev.colbster937.originblacklist.base;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
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.IEaglercraftLoginEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftMOTDEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
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 {
|
||||
private static LoggerAdapter adapter;
|
||||
private static IEaglerXServerAPI api;
|
||||
private static IPBlacklist ipblacklist;
|
||||
|
||||
public static void setLogger(LoggerAdapter log) {
|
||||
adapter = log;
|
||||
}
|
||||
|
||||
public static void setApi(IEaglerXServerAPI api1) {
|
||||
api = api1;
|
||||
}
|
||||
|
||||
public static ConfigManager config;
|
||||
|
||||
public static String pluginVer = "1.0.2";
|
||||
|
||||
public static boolean checkVer(String v1, String v2) {
|
||||
String[] c = v1.split("\\.");
|
||||
String[] r = v2.split("\\.");
|
||||
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;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static LoggerAdapter getLogger() {
|
||||
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(IEaglercraftLoginEvent e) {
|
||||
IEaglerLoginConnection conn = e.getLoginConnection();
|
||||
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||
String brand = conn.getEaglerBrandString();
|
||||
String name = conn.getUsername();
|
||||
String ip = getAddr(conn);
|
||||
String notAllowed1 = "not allowed on the server";
|
||||
String notAllowed2 = "not allowed";
|
||||
|
||||
if (origin != null && !origin.equals("null")) {
|
||||
for (String origin1 : config.blacklist.origins) {
|
||||
if (matches(origin, origin1)) {
|
||||
setKick(e, formatKickMessage("origin", "website", notAllowed1, notAllowed2, origin, conn.getWebSocketHost()));
|
||||
webhook(conn, origin, brand, "origin");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (brand != null && !brand.equals("null")) {
|
||||
for (String brand1 : config.blacklist.brands) {
|
||||
if (matches(brand, brand1)) {
|
||||
setKick(e, formatKickMessage("brand", "client", notAllowed1, notAllowed2, brand, conn.getWebSocketHost()));
|
||||
webhook(conn, origin, brand, "brand");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (name != null && !name.equals("null")) {
|
||||
for (String name1 : config.blacklist.players) {
|
||||
if (matches(name, name1) || (name.length() > 16 || name.length() < 3)) {
|
||||
setKick(e, formatKickMessage("player", "username", notAllowed1, notAllowed2, name, conn.getWebSocketHost()));
|
||||
webhook(conn, origin, brand, "player");
|
||||
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) {
|
||||
try {
|
||||
getLogger().info("Kicked " + e.getProfileUsername());
|
||||
e.setKickMessage(msg);
|
||||
} catch (Throwable ignored) {
|
||||
String msg1 = LegacyComponentSerializer.legacySection().serialize(msg);
|
||||
e.setKickMessage(msg1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleMOTD(IEaglercraftMOTDEvent e) {
|
||||
if (!config.messages.motd.enabled) return;
|
||||
|
||||
IMOTDConnection conn = e.getMOTDConnection();
|
||||
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()
|
||||
.map(line -> line
|
||||
.replace("%blocktype%", finalBlocktype)
|
||||
.replace("%easyblocktype%", finalEasyblocktype)
|
||||
.replace("%notallowed1%", "blacklisted")
|
||||
.replace("%notallowed2%", "blacklisted")
|
||||
.replace("%blocked%", finalBlocked)
|
||||
.replace("%host%", host))
|
||||
.map(line -> LegacyComponentSerializer.legacySection()
|
||||
.serialize(MiniMessage.miniMessage().deserialize(line)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
conn.sendToUser();
|
||||
conn.disconnect();
|
||||
}
|
||||
|
||||
public static boolean matches(String text1, String text2) {
|
||||
return text1.toLowerCase().matches(text2.replace(".", "\\.").replaceAll("\\*", ".*").toLowerCase());
|
||||
}
|
||||
|
||||
public static Component formatKickMessage(String type, String easytype, String notAllowed1, String notAllowed2, String value, String host) {
|
||||
String help = "";
|
||||
if ("player".equals(type)) {
|
||||
help = config.messages.help.player;
|
||||
} else if ("ip address".equals(type)) {
|
||||
help = config.messages.help.ip;
|
||||
} else {
|
||||
help = config.messages.help.generic;
|
||||
}
|
||||
return MiniMessage.miniMessage().deserialize(
|
||||
config.messages.kick
|
||||
.replaceAll("%help%", help)
|
||||
.replaceAll("%blocktype%", type)
|
||||
.replaceAll("%easyblocktype%", easytype)
|
||||
.replaceAll("%notallowed1%", notAllowed1)
|
||||
.replaceAll("%notallowed2%", notAllowed2)
|
||||
.replaceAll("%blocked%", value)
|
||||
.replaceAll("%host%", host));
|
||||
}
|
||||
|
||||
public static void webhook(IEaglerLoginConnection plr, String origin, String brand, String type) {
|
||||
String webhook = config.discord.webhook;
|
||||
if (webhook == null || webhook.isBlank())
|
||||
return;
|
||||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
String addr = getAddr(plr);
|
||||
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🏠 **IP:** %s\\n🌄 **PVN:** %s\\n🌐 **Origin:** %s\\n🔋 **Brand:** %s\\n🪑 **Host:** %s\\n🧊 **UA:** %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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String getAddr(IEaglerLoginConnection conn) {
|
||||
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;
|
||||
return addr2;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
ipblacklist = new IPBlacklist();
|
||||
}
|
||||
|
||||
public static void reloadConfig() {
|
||||
config = ConfigManager.loadConfig(adapter);
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
package dev.colbster937.originblacklist.base;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static dev.colbster937.originblacklist.base.Base.config;
|
||||
|
||||
public class Command {
|
||||
private static final String permission = "<red>You do not have permission to use this command.</red>";
|
||||
|
||||
public interface CommandContext {
|
||||
String getName();
|
||||
void reply(String message);
|
||||
boolean hasPermission(String permission);
|
||||
String[] getArgs();
|
||||
}
|
||||
|
||||
public static void usage(CommandContext ctx) {
|
||||
ctx.reply("<aqua>Commands:</aqua>");
|
||||
ctx.reply("<gray> - /originblacklist reload</gray>");
|
||||
ctx.reply("<gray> - /originblacklist add <brand/origin/name/ip> <value></gray>");
|
||||
ctx.reply("<gray> - /originblacklist remove <brand/origin/name/ip> <value></gray>");
|
||||
ctx.reply("<gray> - /originblacklist list</gray>");
|
||||
}
|
||||
|
||||
public static void handle(CommandContext ctx) {
|
||||
String[] args = ctx.getArgs();
|
||||
if (!ctx.hasPermission("originblacklist.command")) {
|
||||
ctx.reply(permission);
|
||||
return;
|
||||
} else if (args.length == 0) {
|
||||
usage(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
String sub = args[0].toLowerCase();
|
||||
String sub1 = args.length > 1 ? args[1].toLowerCase() : "";
|
||||
String sub2 = args.length > 2 ? args[2].toLowerCase() : "";
|
||||
|
||||
switch (sub) {
|
||||
case "reload" -> {
|
||||
if (ctx.hasPermission("originblacklist.reload")) {
|
||||
Base.reloadConfig();
|
||||
ctx.reply("<green>Reloaded.</green>");
|
||||
} else {
|
||||
ctx.reply(permission);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
case "add" -> {
|
||||
if (!ctx.hasPermission("originblacklist.add")) {
|
||||
ctx.reply(permission);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sub1.isEmpty() || sub2.isEmpty()) {
|
||||
usage(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> list = switch (sub1) {
|
||||
case "brand" -> Base.config.blacklist.brands;
|
||||
case "origin" -> Base.config.blacklist.origins;
|
||||
case "player" -> Base.config.blacklist.players;
|
||||
case "ip" -> Base.config.blacklist.ips;
|
||||
default -> null;
|
||||
};
|
||||
|
||||
if (list == null) {
|
||||
usage(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!list.contains(sub2)) {
|
||||
list.add(sub2);
|
||||
ctx.reply("<green>Added " + sub2 + " to " + sub1 + " blacklist.</green>");
|
||||
} else {
|
||||
ctx.reply("<yellow>Already blacklisted.</yellow>");
|
||||
}
|
||||
try {
|
||||
config.saveConfig(Base.config.toMap(), new File("plugins/originblacklist/config.yml"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Base.reloadConfig();
|
||||
}
|
||||
|
||||
case "remove" -> {
|
||||
if (!ctx.hasPermission("originblacklist.remove")) {
|
||||
ctx.reply(permission);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sub1.isEmpty() || sub2.isEmpty()) {
|
||||
usage(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> list = switch (sub1) {
|
||||
case "brand" -> Base.config.blacklist.brands;
|
||||
case "origin" -> Base.config.blacklist.origins;
|
||||
case "player" -> Base.config.blacklist.players;
|
||||
case "ip" -> Base.config.blacklist.ips;
|
||||
default -> null;
|
||||
};
|
||||
|
||||
if (list == null) {
|
||||
usage(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (list.remove(sub2)) {
|
||||
ctx.reply("<green>Removed " + sub2 + " from " + sub1 + " blacklist.</green>");
|
||||
} else {
|
||||
ctx.reply("<yellow>Entry not found in " + sub1 + ".</yellow>");
|
||||
}
|
||||
try {
|
||||
config.saveConfig(Base.config.toMap(), new File("plugins/originblacklist/config.yml"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Base.reloadConfig();
|
||||
}
|
||||
|
||||
case "list" -> {
|
||||
if (!ctx.hasPermission("originblacklist.view")) {
|
||||
ctx.reply(permission);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply("<aqua>Blacklist:</aqua>");
|
||||
|
||||
ctx.reply("<gray> Brands:</gray>");
|
||||
for (String s : Base.config.blacklist.brands) ctx.reply("<gray> - " + s + "</gray>");
|
||||
|
||||
ctx.reply("<gray> Origins:</gray>");
|
||||
for (String s : Base.config.blacklist.origins) ctx.reply("<gray> - " + s + "</gray>");
|
||||
|
||||
ctx.reply("<gray> Players:</gray>");
|
||||
for (String s : Base.config.blacklist.players) ctx.reply("<gray> - " + s + "</gray>");
|
||||
|
||||
ctx.reply("<gray> IPs:</gray>");
|
||||
for (String s : Base.config.blacklist.ips) ctx.reply("<gray> - " + s + "</gray>");
|
||||
}
|
||||
|
||||
default -> usage(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> suggest(CommandContext ctx) {
|
||||
String[] args = ctx.getArgs();
|
||||
|
||||
if (args.length == 1) {
|
||||
return List.of("reload", "add", "remove", "list");
|
||||
}
|
||||
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("add")) {
|
||||
return List.of("brand", "origin", "player", "ip");
|
||||
}
|
||||
|
||||
return List.of();
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Yaml yaml = new Yaml();
|
||||
return yaml.load(yaml.dump(this));
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package dev.colbster937.originblacklist.base;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
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;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import inet.ipaddr.IPAddress;
|
||||
|
||||
public class ConfigManager {
|
||||
public Messages messages = new Messages();
|
||||
//public List<String> subscriptions = List.of();
|
||||
public Blacklist blacklist = new Blacklist();
|
||||
public Discord discord = new Discord();
|
||||
|
||||
public static ConfigManager loadConfig(Base.LoggerAdapter logger) {
|
||||
File f = new File("plugins/originblacklist/config.yml");
|
||||
|
||||
try {
|
||||
if (!f.exists()) {
|
||||
f.getParentFile().mkdirs();
|
||||
try (InputStream in = ConfigManager.class.getResourceAsStream("/config.yml")) {
|
||||
if (in != null) Files.copy(in, f.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
|
||||
Constructor constructor = new Constructor(ConfigManager.class, new LoaderOptions());
|
||||
constructor.setPropertyUtils(new org.yaml.snakeyaml.introspector.PropertyUtils() {{
|
||||
setSkipMissingProperties(true);
|
||||
}});
|
||||
Yaml y = new Yaml(constructor);
|
||||
ConfigManager l = null;
|
||||
|
||||
try (InputStream in = new FileInputStream(f)) {
|
||||
l = y.load(in);
|
||||
} catch (Exception ex) {
|
||||
logger.warn("Error loading config: " + ex.getMessage());
|
||||
}
|
||||
|
||||
if (l == null) {
|
||||
l = new ConfigManager();
|
||||
}
|
||||
|
||||
try {
|
||||
Yaml raw = new Yaml();
|
||||
Map<String, Object> u = raw.load(new FileInputStream(f));
|
||||
Map<String, Object> d = raw.load(ConfigManager.class.getResourceAsStream("/config.yml"));
|
||||
if (mergeConfig(u, d)) saveConfig(u, f);
|
||||
} catch (Exception ex) {
|
||||
logger.warn("YAML merge error: " + ex.getMessage());
|
||||
}
|
||||
|
||||
l.blacklist.resolveIPS(logger);
|
||||
|
||||
return l;
|
||||
} catch (IOException e) {
|
||||
return new ConfigManager();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static boolean mergeConfig(Map<String, Object> u, Map<String, Object> 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<String, Object>) u.get(k), (Map<String, Object>) d.get(k));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public static void saveConfig(Map<String, Object> 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 Map<String, Object> toMap() {
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
options.setPrettyFlow(true);
|
||||
options.setAllowReadOnlyProperties(true);
|
||||
|
||||
Yaml yaml = new Yaml(options);
|
||||
String yaml1 = yaml.dumpAsMap(this);
|
||||
Yaml parser = new Yaml();
|
||||
Object yaml2 = parser.load(yaml1);
|
||||
|
||||
return (Map<String, Object>) yaml2;
|
||||
}
|
||||
|
||||
public static class Blacklist {
|
||||
public List<String> origins;
|
||||
public List<String> brands;
|
||||
public List<String> players;
|
||||
public List<String> ips = List.of();
|
||||
public transient Set<IPAddress> ips1 = new CopyOnWriteArraySet<>();
|
||||
public boolean missing_origin;
|
||||
//public String blacklist_redirect;
|
||||
|
||||
public void resolveIPS(Base.LoggerAdapter logger) {
|
||||
for (String line : ips) {
|
||||
try {
|
||||
ips1.add(new inet.ipaddr.IPAddressString(line).toAddress());
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Discord {
|
||||
public String webhook;
|
||||
}
|
||||
|
||||
public static class Messages {
|
||||
public String kick;
|
||||
public MOTD motd;
|
||||
public Help help;
|
||||
}
|
||||
|
||||
public static class MOTD {
|
||||
public boolean enabled;
|
||||
public String text;
|
||||
public String icon;
|
||||
}
|
||||
|
||||
public static class Help {
|
||||
public String generic;
|
||||
public String player;
|
||||
public String ip;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package dev.colbster937.originblacklist.base;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import inet.ipaddr.AddressStringException;
|
||||
import inet.ipaddr.IPAddress;
|
||||
import inet.ipaddr.IPAddressString;
|
||||
|
||||
import static dev.colbster937.originblacklist.base.Base.config;
|
||||
|
||||
public class IPBlacklist {
|
||||
private Logger logger = null;
|
||||
|
||||
public IPBlacklist() {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public boolean check(String addr) {
|
||||
IPAddress ip;
|
||||
String addr1 = addr;
|
||||
try {
|
||||
if (addr.startsWith("/")) {
|
||||
addr1 = addr.substring(1);
|
||||
}
|
||||
if (addr1.startsWith("[") && addr1.endsWith("]")) {
|
||||
addr1 = addr1.substring(1, addr1.length() - 1);
|
||||
}
|
||||
ip = new IPAddressString(addr1).toAddress();
|
||||
} catch (AddressStringException e) {
|
||||
throw new RuntimeException("Invalid IP address: " + addr, e);
|
||||
}
|
||||
|
||||
return config.blacklist.ips1.stream().anyMatch(s -> {
|
||||
try {
|
||||
return s.contains(ip);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package dev.colbster937.originblacklist.bukkit;
|
||||
|
||||
import dev.colbster937.originblacklist.base.Command.CommandContext;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CommandBukkit implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
|
||||
dev.colbster937.originblacklist.base.Command.handle(new CommandContext() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reply(String msg) {
|
||||
sender.sendMessage(LegacyComponentSerializer.legacySection()
|
||||
.serialize(MiniMessage.miniMessage().deserialize(msg)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
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.EaglercraftLoginEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftMOTDEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class OriginBlacklistBukkit extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin("EaglercraftXServer");
|
||||
if (plugin != null) {
|
||||
String version = plugin.getDescription().getVersion();
|
||||
if (!Base.checkVer(version, Base.pluginVer)) {
|
||||
getLogger().severe("EaglerXServer " + Base.pluginVer + " is required!");
|
||||
throw new RuntimeException("Incompatible plugin version");
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Missing EaglerXServer");
|
||||
}
|
||||
|
||||
|
||||
Base.setLogger(new Base.LoggerAdapter() {
|
||||
@Override public void info(String msg) { getLogger().info(msg); }
|
||||
@Override public void warn(String msg) { getLogger().warning(msg); }
|
||||
@Override public void error(String msg) { getLogger().severe(msg); }
|
||||
});
|
||||
|
||||
Base.setApi(EaglerXServerAPI.instance());
|
||||
Base.reloadConfig();
|
||||
Base.init();
|
||||
|
||||
getCommand("originblacklist").setExecutor(new CommandBukkit());
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
|
||||
getLogger().info("Loaded Bukkit plugin");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(EaglercraftLoginEvent event) {
|
||||
Base.handleConnection(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||
Base.handleMOTD(event);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package dev.colbster937.originblacklist.bungee;
|
||||
|
||||
import dev.colbster937.originblacklist.base.Command.CommandContext;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class CommandBungee extends net.md_5.bungee.api.plugin.Command {
|
||||
|
||||
public CommandBungee() {
|
||||
super("originblacklist", "originblacklist.use");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
dev.colbster937.originblacklist.base.Command.handle(new CommandContext() {
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
public void reply(String msg) {
|
||||
sender.sendMessage(TextComponent.fromLegacyText(msg));
|
||||
}
|
||||
|
||||
public boolean hasPermission(String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
public String[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
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.EaglercraftLoginEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.bungee.event.EaglercraftMOTDEvent;
|
||||
import net.md_5.bungee.api.event.PreLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
public class OriginBlacklistBungee extends Plugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Plugin plugin = getProxy().getPluginManager().getPlugin("EaglercraftXServer");
|
||||
if (plugin != null) {
|
||||
String version = plugin.getDescription().getVersion();
|
||||
if (!Base.checkVer(version, Base.pluginVer)) {
|
||||
getLogger().severe("EaglerXServer " + Base.pluginVer + " is required!");
|
||||
throw new RuntimeException("Incompatible plugin version");
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Missing EaglerXServer");
|
||||
}
|
||||
|
||||
|
||||
Base.setLogger(new Base.LoggerAdapter() {
|
||||
@Override public void info(String msg) { getLogger().info(msg); }
|
||||
@Override public void warn(String msg) { getLogger().warning(msg); }
|
||||
@Override public void error(String msg) { getLogger().severe(msg); }
|
||||
});
|
||||
|
||||
Base.setApi(EaglerXServerAPI.instance());
|
||||
Base.reloadConfig();
|
||||
Base.init();
|
||||
|
||||
getProxy().getPluginManager().registerCommand(this, new CommandBungee());
|
||||
getProxy().getPluginManager().registerListener(this, this);
|
||||
|
||||
getLogger().info("Loaded Bungee plugin");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(EaglercraftLoginEvent event) {
|
||||
Base.handleConnection(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||
Base.handleMOTD(event);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package dev.colbster937.originblacklist.velocity;
|
||||
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import dev.colbster937.originblacklist.base.Command;
|
||||
import dev.colbster937.originblacklist.base.Command.CommandContext;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandVelocity implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
Command.handle(new VelocityCommandContext(invocation));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(Invocation invocation) {
|
||||
return Command.suggest(new VelocityCommandContext(invocation));
|
||||
}
|
||||
|
||||
public static class VelocityCommandContext implements CommandContext {
|
||||
private final Invocation invocation;
|
||||
|
||||
public VelocityCommandContext(Invocation invocation) {
|
||||
this.invocation = invocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return invocation.source().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reply(String message) {
|
||||
invocation.source().sendMessage(MiniMessage.miniMessage().deserialize(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return invocation.source().hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getArgs() {
|
||||
return invocation.arguments();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package dev.colbster937.originblacklist.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import dev.colbster937.originblacklist.base.Base;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.EaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftLoginEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftMOTDEvent;
|
||||
import java.net.InetAddress;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class OriginBlacklistVelocity {
|
||||
|
||||
private final ProxyServer proxy;
|
||||
private final Base.LoggerAdapter logger;
|
||||
|
||||
@Inject
|
||||
public OriginBlacklistVelocity(ProxyServer proxy1, Logger logger1) {
|
||||
this.proxy = proxy1;
|
||||
this.logger = new Base.LoggerAdapter() {
|
||||
@Override public void info(String msg) { logger1.info(msg); }
|
||||
@Override public void warn(String msg) { logger1.warn(msg); }
|
||||
@Override public void error(String msg) { logger1.error(msg); }
|
||||
};
|
||||
Base.setLogger(this.logger);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
proxy.getPluginManager().getPlugin("eaglerxserver").ifPresentOrElse(plugin -> {
|
||||
if (!Base.checkVer(plugin.getDescription().getVersion().orElse("1.0.0"), Base.pluginVer)) {
|
||||
logger.error("EaglerXServer " + Base.pluginVer + " is required!");
|
||||
throw new RuntimeException("Incompatible plugin version");
|
||||
}
|
||||
}, () -> {
|
||||
throw new RuntimeException("Missing EaglerXServer");
|
||||
});
|
||||
Base.setApi(EaglerXServerAPI.instance());
|
||||
Base.reloadConfig();
|
||||
Base.init();
|
||||
proxy.getCommandManager().register("originblacklist", new CommandVelocity());
|
||||
logger.info("Loaded Velocity plugin");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onLogin(EaglercraftLoginEvent event) {
|
||||
Base.handleConnection(event);
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||
Base.handleMOTD(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package xyz.webmc.originblacklist.base;
|
||||
|
||||
import xyz.webmc.originblacklist.base.config.OriginBlacklistConfig;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumBlacklistType;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
import xyz.webmc.originblacklist.base.util.UpdateChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.semver4j.Semver;
|
||||
|
||||
import de.marhali.json5.Json5Array;
|
||||
import de.marhali.json5.Json5Element;
|
||||
|
||||
import inet.ipaddr.AddressStringException;
|
||||
import inet.ipaddr.IPAddressString;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
||||
|
||||
public final class OriginBlacklist {
|
||||
public static final Semver REQUIRED_API_VER = new Semver("1.0.2");
|
||||
public static final String GENERIC_STR = "generic";
|
||||
public static final String UNKNOWN_STR = "unknown";
|
||||
public static final String PLUGIN_REPO = "WebMCDevelopment/originblacklist";
|
||||
public static final int BSTATS_ID = 28776;
|
||||
|
||||
private final IOriginBlacklistPlugin plugin;
|
||||
private final OriginBlacklistConfig config;
|
||||
private boolean updateAvailable;
|
||||
|
||||
public OriginBlacklist(final IOriginBlacklistPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.config = new OriginBlacklistConfig(plugin);
|
||||
this.checkForUpdate();
|
||||
plugin.scheduleRepeat(() -> {
|
||||
this.checkForUpdate();
|
||||
}, 60, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
public final void handleLogin(final OriginBlacklistLoginEvent event) {
|
||||
final OPlayer player = event.getPlayer();
|
||||
final EnumBlacklistType blacklisted = this.testBlacklist(player);
|
||||
if (blacklisted != EnumBlacklistType.NONE) {
|
||||
final String blacklisted_value;
|
||||
if (blacklisted == EnumBlacklistType.ORIGIN) {
|
||||
blacklisted_value = player.getOrigin();
|
||||
} else if (blacklisted == EnumBlacklistType.BRAND) {
|
||||
blacklisted_value = player.getBrand();
|
||||
} else if (blacklisted == EnumBlacklistType.NAME) {
|
||||
blacklisted_value = player.getName();
|
||||
} else if (blacklisted == EnumBlacklistType.ADDR) {
|
||||
blacklisted_value = player.getAddr();
|
||||
} else {
|
||||
blacklisted_value = UNKNOWN_STR;
|
||||
}
|
||||
this.plugin.kickPlayer(this.getBlacklistedComponent("kick", blacklisted.getArrayString(),
|
||||
blacklisted.getAltString(), blacklisted.getString(), "not allowed", "not allowed on the server",
|
||||
blacklisted_value, blacklisted.getActionString()), event);
|
||||
final String name = player.getName();
|
||||
if (isNonNull(name)) {
|
||||
this.plugin.log(EnumLogLevel.INFO, "Prevented blacklisted player " + name + " from joining.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void handleMOTD(final OriginBlacklistMOTDEvent event) {
|
||||
final OPlayer player = event.getPlayer();
|
||||
final EnumBlacklistType blacklisted = this.testBlacklist(player);
|
||||
if (blacklisted != EnumBlacklistType.NONE) {
|
||||
final String blacklisted_value;
|
||||
if (blacklisted == EnumBlacklistType.ORIGIN) {
|
||||
blacklisted_value = player.getOrigin();
|
||||
} else if (blacklisted == EnumBlacklistType.ADDR) {
|
||||
blacklisted_value = player.getAddr();
|
||||
} else {
|
||||
blacklisted_value = UNKNOWN_STR;
|
||||
}
|
||||
this.plugin.setMOTD(this.getBlacklistedComponent("motd", blacklisted.getArrayString(), blacklisted.getAltString(),
|
||||
blacklisted.getString(), "blacklisted", "blacklisted from the server", blacklisted_value,
|
||||
blacklisted.getActionString()), event);
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean isDebugEnabled() {
|
||||
return this.config.get("debug").getAsBoolean();
|
||||
}
|
||||
|
||||
public final boolean isMetricsEnabled() {
|
||||
return this.config.get("bStats").getAsBoolean();
|
||||
}
|
||||
|
||||
public final OriginBlacklistConfig getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public final void setEaglerMOTD(final Component comp, final OriginBlacklistMOTDEvent event) {
|
||||
final IMOTDConnection conn = event.getEaglerEvent().getMOTDConnection();
|
||||
final List<String> lst = new ArrayList<>();
|
||||
for (String ln : getComponentString(comp).split("\n")) {
|
||||
lst.add(ln);
|
||||
}
|
||||
conn.setServerMOTD(lst);
|
||||
conn.setPlayerTotal(0);
|
||||
conn.setPlayerUnlimited();
|
||||
conn.setPlayerList(List.of());
|
||||
conn.setServerIcon(this.config.getIconBytes());
|
||||
conn.sendToUser();
|
||||
conn.disconnect();
|
||||
}
|
||||
|
||||
private final EnumBlacklistType testBlacklist(final OPlayer player) {
|
||||
final String name = player.getName();
|
||||
final String addr = player.getAddr();
|
||||
final String origin = player.getOrigin();
|
||||
final String brand = player.getBrand();
|
||||
|
||||
if (isNonNull(origin)) {
|
||||
for (final Json5Element element : this.config.get("blacklist.origins").getAsJson5Array()) {
|
||||
if (origin.matches(element.getAsString())) {
|
||||
return EnumBlacklistType.ORIGIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isNonNull(brand)) {
|
||||
for (final Json5Element element : this.config.get("blacklist.brands").getAsJson5Array()) {
|
||||
if (brand.matches(element.getAsString())) {
|
||||
return EnumBlacklistType.BRAND;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isNonNull(name)) {
|
||||
for (final Json5Element element : this.config.get("blacklist.player_names").getAsJson5Array()) {
|
||||
this.plugin.log(EnumLogLevel.DEBUG, element.getAsString());
|
||||
if (name.matches(element.getAsString())) {
|
||||
return EnumBlacklistType.NAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isNonNull(addr)) {
|
||||
for (final Json5Element element : this.config.get("blacklist.ip_addresses").getAsJson5Array()) {
|
||||
try {
|
||||
if ((new IPAddressString(element.getAsString()).toAddress())
|
||||
.contains((new IPAddressString(addr)).toAddress())) {
|
||||
return EnumBlacklistType.ADDR;
|
||||
}
|
||||
} catch (final AddressStringException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EnumBlacklistType.NONE;
|
||||
}
|
||||
|
||||
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 action) {
|
||||
final Json5Array arr = this.config.get("messages." + type).getAsJson5Array();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
if (i > 0)
|
||||
sb.append("\n");
|
||||
sb.append(arr.get(i).getAsString());
|
||||
}
|
||||
final String str = sb.toString()
|
||||
.replaceAll("%action%", this.config.get("messages.actions." + action).getAsString())
|
||||
.replaceAll("%block_type%", blockType)
|
||||
.replaceAll("%block_type%", blockType)
|
||||
.replaceAll("%not_allowed%", notAllowed)
|
||||
.replaceAll("%not_allowed_alt%", notAllowedAlt)
|
||||
.replaceAll("%blocked_value%", blockValue);
|
||||
return MiniMessage.miniMessage().deserialize(str);
|
||||
}
|
||||
|
||||
private final void checkForUpdate() {
|
||||
(new Thread(() -> {
|
||||
this.updateAvailable = UpdateChecker.checkForUpdate(PLUGIN_REPO, this.plugin.getPluginVersion(),
|
||||
this.config.get("update_checker.allow_snapshots").getAsBoolean());
|
||||
if (this.updateAvailable) {
|
||||
this.plugin.log(EnumLogLevel.INFO, "Update Available! Download at https://github.com/" + PLUGIN_REPO + ".git");
|
||||
}
|
||||
})).run();
|
||||
}
|
||||
|
||||
public static final String getComponentString(final Component comp) {
|
||||
return LegacyComponentSerializer.legacySection().serialize(comp);
|
||||
}
|
||||
|
||||
public static final String getLegacyFromMiniMessage(final String str) {
|
||||
return getComponentString(MiniMessage.miniMessage().deserialize(str));
|
||||
}
|
||||
|
||||
public static final String getPNGBase64FromBytes(final byte[] bytes) {
|
||||
return "data:image/png;base64," + Base64.getEncoder().encodeToString(bytes);
|
||||
}
|
||||
|
||||
public static final boolean isNonNull(final String str) {
|
||||
return str != null && !str.isEmpty() && !str.isBlank() && !str.equals("null");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package xyz.webmc.originblacklist.base.command;
|
||||
|
||||
public interface CommandContext {
|
||||
String getPlayerName();
|
||||
void reply(final String message);
|
||||
boolean hasPermission(final String permission);
|
||||
String[] getArgs();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package xyz.webmc.originblacklist.base.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ICommand {
|
||||
static final String NO_PERMISSION = "<red>You don't have permission to use this command.</red>";
|
||||
boolean execute(final CommandContext ctx);
|
||||
List<String> suggest(final CommandContext ctx);
|
||||
void usage(final CommandContext ctx);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package xyz.webmc.originblacklist.base.command;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.marhali.json5.Json5Element;
|
||||
|
||||
public class OriginBlacklistCommand implements ICommand {
|
||||
private final OriginBlacklist plugin;
|
||||
|
||||
public OriginBlacklistCommand(OriginBlacklist plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final CommandContext ctx) {
|
||||
final String[] args = ctx.getArgs();
|
||||
if (ctx.hasPermission("originblacklist.command")) {
|
||||
if (args.length > 0) {
|
||||
final String command = args[0].toLowerCase();
|
||||
if ("reload".equals(command)) {
|
||||
if (ctx.hasPermission("originblacklist.command.reload")) {
|
||||
this.plugin.getConfig().reloadConfig();
|
||||
ctx.reply("<green>Configuration Reloaded</green>");
|
||||
} else {
|
||||
ctx.reply(NO_PERMISSION);
|
||||
}
|
||||
} else if ("list".equals(command)) {
|
||||
if (ctx.hasPermission("originblacklist.command.reload")) {
|
||||
ctx.reply("<aqua>Blacklist:</aqua>");
|
||||
ctx.reply("<gold> - Origins:</gold>");
|
||||
for (final Json5Element element : this.plugin.getConfig().get("blacklist.origins").getAsJson5Array()) {
|
||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||
}
|
||||
ctx.reply("<gold> - Brands:</gold>");
|
||||
for (final Json5Element element : this.plugin.getConfig().get("blacklist.brands").getAsJson5Array()) {
|
||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||
}
|
||||
ctx.reply("<gold> - Players:</gold>");
|
||||
for (final Json5Element element : this.plugin.getConfig().get("blacklist.player_names").getAsJson5Array()) {
|
||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||
}
|
||||
ctx.reply("<gold> - IPs:</gold>");
|
||||
for (final Json5Element element : this.plugin.getConfig().get("blacklist.ip_addresses").getAsJson5Array()) {
|
||||
ctx.reply("<gray> - " + element.getAsString() + "</gray>");
|
||||
}
|
||||
} else {
|
||||
ctx.reply(NO_PERMISSION);
|
||||
}
|
||||
} else {
|
||||
this.usage(ctx);
|
||||
}
|
||||
} else {
|
||||
this.usage(ctx);
|
||||
}
|
||||
} else {
|
||||
ctx.reply("");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(final CommandContext ctx) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void usage(CommandContext ctx) {
|
||||
ctx.reply("<aqua>Commands:</aqua>");
|
||||
ctx.reply("<gray> - /originblacklist reload</gray>");
|
||||
//ctx.reply("<gray> - /originblacklist add <brand/origin/name/ip> <value></gray>");
|
||||
//ctx.reply("<gray> - /originblacklist remove <brand/origin/name/ip> <value></gray>");
|
||||
ctx.reply("<gray> - /originblacklist list</gray>");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
package xyz.webmc.originblacklist.base.config;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import de.marhali.json5.Json5;
|
||||
import de.marhali.json5.Json5Array;
|
||||
import de.marhali.json5.Json5Element;
|
||||
import de.marhali.json5.Json5Object;
|
||||
import de.marhali.json5.Json5Primitive;
|
||||
|
||||
public final class OriginBlacklistConfig {
|
||||
private final Json5 json5;
|
||||
private final File file;
|
||||
private final Path filePath;
|
||||
private final File iconFile;
|
||||
private final Path iconPath;
|
||||
private Json5Object config;
|
||||
private byte[] icon;
|
||||
private String icon64;
|
||||
|
||||
public OriginBlacklistConfig(IOriginBlacklistPlugin plugin) {
|
||||
this.json5 = Json5.builder(builder -> builder
|
||||
.quoteless()
|
||||
.quoteSingle()
|
||||
.parseComments()
|
||||
.writeComments()
|
||||
.prettyPrinting()
|
||||
.build());
|
||||
final String dir = "plugins/" + plugin.getPluginId();
|
||||
this.file = new File(dir + "/config.json5");
|
||||
this.filePath = file.toPath();
|
||||
this.iconFile = new File(dir + "/blacklisted.png");
|
||||
this.iconPath = iconFile.toPath();
|
||||
this.loadConfig();
|
||||
}
|
||||
|
||||
private final void loadConfig() {
|
||||
try {
|
||||
this.reloadConfigUnsafe();
|
||||
} catch (final IOException exception) {
|
||||
throw new RuntimeException("Failed to load config.", exception);
|
||||
}
|
||||
this.reloadIconImage();
|
||||
}
|
||||
|
||||
public final void reloadConfig() {
|
||||
try {
|
||||
this.reloadConfigUnsafe();
|
||||
} catch (final IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
this.reloadIconImage();
|
||||
}
|
||||
|
||||
private final void reloadConfigUnsafe() throws IOException {
|
||||
if (this.file.exists()) {
|
||||
String text = Files.readString(this.file.toPath(), StandardCharsets.UTF_8);
|
||||
Json5Element parsed = this.json5.parse(text);
|
||||
if (parsed instanceof Json5Object) {
|
||||
this.config = (Json5Object) parsed;
|
||||
if (merge(this.config, getDefaultConfig())) {
|
||||
this.saveConfig();
|
||||
}
|
||||
} else {
|
||||
throw new IOException("Config must be an object!");
|
||||
}
|
||||
} else {
|
||||
this.config = getDefaultConfig();
|
||||
this.saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
private final void reloadIconImage() {
|
||||
try {
|
||||
if (!this.iconFile.exists()) {
|
||||
this.iconFile.getParentFile().mkdirs();
|
||||
final InputStream in = OriginBlacklist.class.getResourceAsStream("/blacklisted.png");
|
||||
Files.copy(in, iconPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
in.close();
|
||||
}
|
||||
|
||||
final BufferedImage img = ImageIO.read(iconFile);
|
||||
|
||||
if (img.getWidth() == 64 && img.getHeight() == 64) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(img, "png", baos);
|
||||
this.icon64 = OriginBlacklist.getPNGBase64FromBytes(baos.toByteArray());
|
||||
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);
|
||||
}
|
||||
this.icon = bytes;
|
||||
}
|
||||
} else {
|
||||
throw new IOException("Icon must be 64x64!");
|
||||
}
|
||||
} catch (final IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public final void saveConfig() {
|
||||
try {
|
||||
this.file.getParentFile().mkdirs();
|
||||
Files.write(this.filePath, this.json5.serialize(this.config).getBytes(StandardCharsets.UTF_8));
|
||||
} catch (final IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public final Json5Element get(final String key) {
|
||||
Json5Element element = null;
|
||||
|
||||
if (this.config != null && OriginBlacklist.isNonNull(key)) {
|
||||
element = this.config;
|
||||
final String[] parts = key.split("\\.");
|
||||
|
||||
for (final String part : parts) {
|
||||
if (element instanceof Json5Object) {
|
||||
final Json5Object obj = (Json5Object) element;
|
||||
if (obj.has(part)) {
|
||||
element = obj.get(part);
|
||||
} else {
|
||||
element = null;
|
||||
}
|
||||
} else {
|
||||
element = null;
|
||||
}
|
||||
|
||||
if (element == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public final byte[] getIconBytes() {
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
public final String getIconBase64URI() {
|
||||
return this.icon64;
|
||||
}
|
||||
|
||||
private static final Json5Object getDefaultConfig() {
|
||||
final Json5Object obj = new Json5Object();
|
||||
addJSONObj(obj, "debug", Json5Primitive.fromBoolean(false), null);
|
||||
final Json5Object mobj = new Json5Object();
|
||||
final Json5Array kick = new Json5Array();
|
||||
kick.add("<red>This %block_type% is %not_allowed_alt%!</red>");
|
||||
kick.add("<dark_gray>»</dark_gray> <gray>%blocked_value%</gray> <dark_gray>«</dark_gray>");
|
||||
kick.add("");
|
||||
kick.add("%action%");
|
||||
kick.add("");
|
||||
kick.add("<aqua>Think this is a mistake? Join our discord:</aqua>");
|
||||
kick.add("<blue>discord.gg/changethisintheconfig</blue>");
|
||||
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();
|
||||
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("ip_address", Json5Primitive.fromString("<gold>Please contact staff for assistance.</gold>"));
|
||||
addJSONObj(mobj, "actions", actions, null);
|
||||
addJSONObj(obj, "messages", mobj, null);
|
||||
final Json5Object bobj = new Json5Object();
|
||||
final Json5Array origins = new Json5Array();
|
||||
origins.add(".*eaglerhackedclients\\.vercel\\.app.*");
|
||||
origins.add(".*eaglerhacks\\.github\\.io.*");
|
||||
origins.add(".*mcproject\\.vercel\\.app.*");
|
||||
origins.add(".*wurst-b2\\.vercel\\.app.*");
|
||||
origins.add(".*flqmedev\\.github\\.io.*");
|
||||
origins.add(".*wurst2\\.vercel\\.app.*");
|
||||
origins.add(".*dhyeybg7\\.vercel\\.app.*");
|
||||
origins.add(".*uec\\.vercel\\.app.*");
|
||||
origins.add(".*valux-game\\.github\\.io.*");
|
||||
origins.add(".*project516\\.dev.*");
|
||||
addJSONObj(bobj, "origins", origins, null);
|
||||
final Json5Array brands = new Json5Array();
|
||||
brands.add(".*dragonx.*");
|
||||
brands.add(".*piclient.*");
|
||||
brands.add(".*justin.*");
|
||||
brands.add(".*wurstx.*");
|
||||
brands.add(".*moonlight.*");
|
||||
addJSONObj(bobj, "brands", brands, null);
|
||||
final Json5Array players = new Json5Array();
|
||||
players.add("Admin");
|
||||
addJSONObj(bobj, "player_names", players, null);
|
||||
final Json5Array ips = new Json5Array();
|
||||
ips.add("192.0.2.0/24");
|
||||
addJSONObj(bobj, "ip_addresses", ips, null);
|
||||
addJSONObj(obj, "blacklist", bobj, null);
|
||||
final Json5Object dobj = new Json5Object();
|
||||
addJSONObj(dobj, "enabled", Json5Primitive.fromBoolean(false), null);
|
||||
addJSONObj(dobj, "webhook_urls", new Json5Array(), null);
|
||||
addJSONObj(obj, "discord", dobj, null);
|
||||
final Json5Object uobj = new Json5Object();
|
||||
addJSONObj(uobj, "enabled", Json5Primitive.fromBoolean(true), null);
|
||||
addJSONObj(uobj, "allow_snapshots", Json5Primitive.fromBoolean(false), null);
|
||||
addJSONObj(uobj, "auto_update", Json5Primitive.fromBoolean(false), null);
|
||||
addJSONObj(obj, "update_checker", uobj, null);
|
||||
addJSONObj(obj, "bStats", Json5Primitive.fromBoolean(true), null);
|
||||
return obj;
|
||||
}
|
||||
|
||||
private static final boolean merge(final Json5Object a, final Json5Object b) {
|
||||
boolean changed = false;
|
||||
|
||||
for (String key : b.keySet()) {
|
||||
Json5Element element = b.get(key);
|
||||
if (!a.has(key)) {
|
||||
a.add(key, element.deepCopy());
|
||||
changed = true;
|
||||
} else {
|
||||
final Json5Element _element = a.get(key);
|
||||
if (_element instanceof Json5Object objA && element instanceof Json5Object objB) {
|
||||
if (merge(objA, objB)) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static final void addJSONObj(final Json5Object obj, final String key, final Json5Element value,
|
||||
final String comment) {
|
||||
if (OriginBlacklist.isNonNull(comment)) {
|
||||
value.setComment(comment);
|
||||
}
|
||||
obj.add(key, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package xyz.webmc.originblacklist.base.enums;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
|
||||
public enum EnumBlacklistType {
|
||||
ORIGIN("origin", "website", "origins", null),
|
||||
BRAND("brand", "client", "brands", null),
|
||||
NAME("name", "username", "player_names", "player_name"),
|
||||
ADDR("addr", "ip address", "ip_addresses", "ip_address"),
|
||||
NONE(null, null, null, null);
|
||||
|
||||
private final String str;
|
||||
private final String alt;
|
||||
private final String arr;
|
||||
private final String act;
|
||||
|
||||
private EnumBlacklistType(final String str, final String alt, final String arr, final String act) {
|
||||
this.str = str;
|
||||
this.alt = alt;
|
||||
this.arr = arr;
|
||||
this.act = OriginBlacklist.isNonNull(act) ? act : OriginBlacklist.GENERIC_STR;
|
||||
}
|
||||
|
||||
public final String getString() {
|
||||
return this.str;
|
||||
}
|
||||
|
||||
public final String getAltString() {
|
||||
return this.alt;
|
||||
}
|
||||
|
||||
public final String getArrayString() {
|
||||
return this.arr;
|
||||
}
|
||||
|
||||
public final String getActionString() {
|
||||
return this.act;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package xyz.webmc.originblacklist.base.enums;
|
||||
|
||||
public enum EnumConnectionType {
|
||||
JAVA,
|
||||
EAGLER
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package xyz.webmc.originblacklist.base.enums;
|
||||
|
||||
public enum EnumLogLevel {
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR,
|
||||
DEBUG
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package xyz.webmc.originblacklist.base.events;
|
||||
|
||||
import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.api.event.IBaseServerEvent;
|
||||
|
||||
public abstract class OriginBlacklistEvent {
|
||||
private final EnumConnectionType connectionType;
|
||||
private final IBaseServerEvent eaglerEvent;
|
||||
private final Object javaEvent;
|
||||
private final OPlayer player;
|
||||
|
||||
protected OriginBlacklistEvent(final IBaseServerEvent eaglerEvent, final Object javaEvent, final EnumConnectionType connectionType, final OPlayer player) {
|
||||
this.eaglerEvent = eaglerEvent;
|
||||
this.javaEvent = javaEvent;
|
||||
this.connectionType = connectionType;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
protected IBaseServerEvent getEaglerEvent() {
|
||||
return this.eaglerEvent;
|
||||
}
|
||||
|
||||
public final Object getJavaEvent() {
|
||||
return this.javaEvent;
|
||||
}
|
||||
|
||||
public final EnumConnectionType getConnectionType() {
|
||||
return this.connectionType;
|
||||
}
|
||||
|
||||
public final OPlayer getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package xyz.webmc.originblacklist.base.events;
|
||||
|
||||
import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftLoginEvent;
|
||||
|
||||
public final class OriginBlacklistLoginEvent extends OriginBlacklistEvent {
|
||||
public OriginBlacklistLoginEvent(final IEaglercraftLoginEvent eaglerEvent, final Object javaEvent,
|
||||
final EnumConnectionType connectionType, final OPlayer player) {
|
||||
super(eaglerEvent, javaEvent, connectionType, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IEaglercraftLoginEvent getEaglerEvent() {
|
||||
return (IEaglercraftLoginEvent) super.getEaglerEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package xyz.webmc.originblacklist.base.events;
|
||||
|
||||
import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftMOTDEvent;
|
||||
|
||||
public final class OriginBlacklistMOTDEvent extends OriginBlacklistEvent {
|
||||
public OriginBlacklistMOTDEvent(final IEaglercraftMOTDEvent eaglerEvent, final Object javaEvent,
|
||||
final EnumConnectionType connectionType, final OPlayer player) {
|
||||
super(eaglerEvent, javaEvent, connectionType, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IEaglercraftMOTDEvent getEaglerEvent() {
|
||||
return (IEaglercraftMOTDEvent) super.getEaglerEvent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package xyz.webmc.originblacklist.base.util;
|
||||
|
||||
public final class ChatFormat {
|
||||
private static final String SYMBOL = "§";
|
||||
|
||||
public static final String BLACK = SYMBOL + "0";
|
||||
public static final String DARK_BLUE = SYMBOL + "1";
|
||||
public static final String DARK_GREEN = SYMBOL + "2";
|
||||
public static final String CYAN = SYMBOL + "3";
|
||||
public static final String DARK_RED = SYMBOL + "4";
|
||||
public static final String DARK_PURPLE = SYMBOL + "5";
|
||||
public static final String GOLD = SYMBOL + "6";
|
||||
public static final String GRAY = SYMBOL + "7";
|
||||
public static final String DARK_GRAY = SYMBOL + "8";
|
||||
public static final String BLUE = SYMBOL + "9";
|
||||
public static final String GREEN = SYMBOL + "a";
|
||||
public static final String AQUA = SYMBOL + "b";
|
||||
public static final String RED = SYMBOL + "c";
|
||||
public static final String LIGHT_PURPLE = SYMBOL + "d";
|
||||
public static final String YELLOW = SYMBOL + "e";
|
||||
public static final String WHITE = SYMBOL + "f";
|
||||
|
||||
public static final String OBFUSCATED = SYMBOL + "k";
|
||||
public static final String BOLD = SYMBOL + "l";
|
||||
public static final String STRIKETHROUGH = SYMBOL + "m";
|
||||
public static final String UNDERLINE = SYMBOL + "n";
|
||||
public static final String ITALIC = SYMBOL + "o";
|
||||
public static final String RESET = SYMBOL + "r";
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package xyz.webmc.originblacklist.base.util;
|
||||
|
||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.semver4j.Semver;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public interface IOriginBlacklistPlugin {
|
||||
public String getPluginId();
|
||||
public Semver getPluginVersion();
|
||||
public void log(final EnumLogLevel level, final String txt);
|
||||
public void kickPlayer(final Component txt, final OriginBlacklistLoginEvent event);
|
||||
public void setMOTD(final Component txt, final OriginBlacklistMOTDEvent event);
|
||||
public String parsePlaceholders(final OPlayer player, final String str);
|
||||
public void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit);
|
||||
public void shutdown();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package xyz.webmc.originblacklist.base.util;
|
||||
|
||||
import org.semver4j.Semver;
|
||||
|
||||
public final class IncompatibleDependencyException extends RuntimeException {
|
||||
public IncompatibleDependencyException(final String name, final Semver requiredVersion, final Semver currentVersion) {
|
||||
super("Incompatible version of " + name + " is present! Required " + requiredVersion + ", but found "
|
||||
+ currentVersion + ".");
|
||||
}
|
||||
|
||||
public IncompatibleDependencyException(final String name) {
|
||||
super("Missing dependency " + name + "!");
|
||||
}
|
||||
}
|
||||
100
src/main/java/xyz/webmc/originblacklist/base/util/OPlayer.java
Normal file
100
src/main/java/xyz/webmc/originblacklist/base/util/OPlayer.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package xyz.webmc.originblacklist.base.util;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.lax1dude.eaglercraft.backend.server.api.EnumWebSocketHeader;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerConnection;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerLoginConnection;
|
||||
|
||||
public final class OPlayer {
|
||||
private final String origin;
|
||||
private final String addr;
|
||||
private final String name;
|
||||
private final UUID uuid;
|
||||
private final String brand;
|
||||
|
||||
public OPlayer(final IEaglerConnection conn, final String name, final UUID uuid, final String addr,
|
||||
final String brand) {
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
if (conn != null) {
|
||||
this.origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||
this.addr = formatSocketAddress(conn.getSocketAddress());
|
||||
if (conn instanceof IEaglerLoginConnection) {
|
||||
this.brand = ((IEaglerLoginConnection) conn).getEaglerBrandString();
|
||||
} else {
|
||||
this.brand = OriginBlacklist.UNKNOWN_STR;
|
||||
}
|
||||
} else {
|
||||
this.origin = OriginBlacklist.UNKNOWN_STR;
|
||||
this.addr = formatIPAddress(addr);
|
||||
this.brand = brand;
|
||||
}
|
||||
}
|
||||
|
||||
public OPlayer(final IEaglerConnection conn, final String name, final UUID uuid) {
|
||||
this(conn, name, uuid, null, null);
|
||||
}
|
||||
|
||||
public final String getOrigin() {
|
||||
return this.origin;
|
||||
}
|
||||
|
||||
public final String getAddr() {
|
||||
return this.addr;
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public final UUID getUUID() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public final String getBrand() {
|
||||
return this.brand;
|
||||
}
|
||||
|
||||
private static final String formatIPAddress(String addr) {
|
||||
if (addr.startsWith("/")) {
|
||||
addr = addr.substring(1);
|
||||
}
|
||||
|
||||
int i = addr.lastIndexOf('/');
|
||||
if (i != -1) {
|
||||
addr = addr.substring(i + 1);
|
||||
}
|
||||
|
||||
if (addr.startsWith("[")) {
|
||||
i = addr.indexOf(']');
|
||||
if (i != -1)
|
||||
return addr.substring(1, i);
|
||||
return addr.substring(1);
|
||||
}
|
||||
|
||||
i = addr.lastIndexOf(':');
|
||||
if (i != -1) {
|
||||
addr = addr.substring(0, i);
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
private static final String formatSocketAddress(final SocketAddress saddr) {
|
||||
if (saddr instanceof InetSocketAddress) {
|
||||
final InetSocketAddress isa = (InetSocketAddress) saddr;
|
||||
if (isa.getAddress() != null) {
|
||||
return isa.getAddress().getHostAddress();
|
||||
} else {
|
||||
return isa.getHostString();
|
||||
}
|
||||
} else {
|
||||
return formatIPAddress(saddr.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package xyz.webmc.originblacklist.base.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import org.semver4j.Semver;
|
||||
|
||||
import de.marhali.json5.Json5;
|
||||
import de.marhali.json5.Json5Array;
|
||||
import de.marhali.json5.Json5Element;
|
||||
import de.marhali.json5.Json5Object;
|
||||
|
||||
public class UpdateChecker {
|
||||
private static final Json5 json5 = Json5.builder(builder -> builder.build());
|
||||
|
||||
public static final boolean checkForUpdate(final String repo, final Semver currentVersion, final boolean allowPreRelease) {
|
||||
try {
|
||||
final URL url = new URL("https://api.github.com/repos/" + repo + "/releases");
|
||||
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setReadTimeout(5000);
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
Json5Element element = json5.parse(reader);
|
||||
if (element instanceof Json5Array) {
|
||||
final Json5Array arr = element.getAsJson5Array();
|
||||
if (arr.size() > 0) {
|
||||
element = arr.get(0);
|
||||
if (element instanceof Json5Object) {
|
||||
final Json5Object obj = element.getAsJson5Object();
|
||||
final String tag = obj.get("tag_name").getAsString();
|
||||
final Semver ver = new Semver(tag.substring(1));
|
||||
if (ver.isGreaterThan(currentVersion)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (final Throwable t) {
|
||||
t.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package xyz.webmc.originblacklist.bukkit;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||
import xyz.webmc.originblacklist.bukkit.command.OriginBlacklistCommandBukkit;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.semver4j.Semver;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.AdvancedPie;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
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.EaglercraftMOTDEvent;
|
||||
|
||||
public final class OriginBlacklistBukkit extends JavaPlugin implements Listener, IOriginBlacklistPlugin {
|
||||
private boolean papiPlaceholdersEnabled;
|
||||
private Object papi;
|
||||
private OriginBlacklist blacklist;
|
||||
private IEaglerXServerAPI eaglerAPI;
|
||||
private Metrics metrics;
|
||||
|
||||
private CachedServerIcon iconCache;
|
||||
|
||||
@Override
|
||||
public final void onEnable() {
|
||||
final Plugin eagx = this.getServer().getPluginManager().getPlugin("EaglercraftXServer");
|
||||
if (eagx == null) {
|
||||
throw new IncompatibleDependencyException("EaglercraftXServer");
|
||||
} else {
|
||||
final Semver version = new Semver(eagx.getDescription().getVersion());
|
||||
if (version.isLowerThan(OriginBlacklist.REQUIRED_API_VER)) {
|
||||
throw new IncompatibleDependencyException("EaglerXServer", OriginBlacklist.REQUIRED_API_VER, version);
|
||||
}
|
||||
}
|
||||
this.papiPlaceholdersEnabled = this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||
if (this.papiPlaceholdersEnabled) {
|
||||
try {
|
||||
this.papi = Class.forName("me.clip.placeholderapi.PlaceholderAPI");
|
||||
} catch (final Throwable t) {
|
||||
this.papi = null;
|
||||
this.papiPlaceholdersEnabled = false;
|
||||
}
|
||||
} else {
|
||||
this.papi = null;
|
||||
}
|
||||
this.blacklist = new OriginBlacklist(this);
|
||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
||||
this.getCommand("originblacklist").setExecutor(new OriginBlacklistCommandBukkit(this.blacklist));
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
this.log(EnumLogLevel.INFO, "Initialized Plugin");
|
||||
if (this.blacklist.isMetricsEnabled()) {
|
||||
this.metrics = new Metrics(this, OriginBlacklist.BSTATS_ID);
|
||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||
final Map<String, Integer> playerMap = new HashMap<>();
|
||||
|
||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
final boolean eagler = eaglerAPI.isEaglerPlayerByUUID(player.getUniqueId());
|
||||
final String key = eagler ? "Eagler" : "Java";
|
||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||
}
|
||||
|
||||
return playerMap;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public final void onJavaLogin(final AsyncPlayerPreLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(null, event.getName(), event.getUniqueId(),
|
||||
event.getAddress() != null ? event.getAddress().toString() : null, null);
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onJavaMOTD(final ServerListPingEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null,
|
||||
event.getAddress() != null ? event.getAddress().toString() : null, null);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getPluginId() {
|
||||
return this.getDescription().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Semver getPluginVersion() {
|
||||
return new Semver(this.getDescription().getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void log(final EnumLogLevel level, final String txt) {
|
||||
if (level == EnumLogLevel.WARN) {
|
||||
this.getLogger().warning(txt);
|
||||
} else if (level == EnumLogLevel.ERROR) {
|
||||
this.getLogger().severe(txt);
|
||||
} else if (level == EnumLogLevel.DEBUG) {
|
||||
if (this.blacklist != null && this.blacklist.isDebugEnabled()) {
|
||||
this.getLogger().info(txt);
|
||||
}
|
||||
} else {
|
||||
this.getLogger().info(txt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void kickPlayer(final Component comp, final OriginBlacklistLoginEvent event) {
|
||||
if (event.getConnectionType() == EnumConnectionType.EAGLER) {
|
||||
event.getEaglerEvent().setKickMessage(OriginBlacklist.getComponentString(comp));
|
||||
} else {
|
||||
final Object javaEvent = event.getJavaEvent();
|
||||
final String msg = OriginBlacklist.getComponentString(comp);
|
||||
if (javaEvent instanceof AsyncPlayerPreLoginEvent pre) {
|
||||
pre.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, msg);
|
||||
} else if (javaEvent instanceof PlayerJoinEvent join) {
|
||||
join.getPlayer().kickPlayer(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setMOTD(final Component comp, final OriginBlacklistMOTDEvent event) {
|
||||
if (event.getConnectionType() == EnumConnectionType.EAGLER) {
|
||||
this.blacklist.setEaglerMOTD(comp, event);
|
||||
} else {
|
||||
final ServerListPingEvent javaEvent = (ServerListPingEvent) event.getJavaEvent();
|
||||
javaEvent.setMotd(OriginBlacklist.getComponentString(comp));
|
||||
javaEvent.setMaxPlayers(0);
|
||||
final CachedServerIcon icon = this.loadIcon();
|
||||
if (icon != null) {
|
||||
try {
|
||||
javaEvent.setServerIcon(icon);
|
||||
} catch (final Throwable t) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final CachedServerIcon loadIcon() {
|
||||
if (this.iconCache != null)
|
||||
return this.iconCache;
|
||||
final String uri = this.blacklist.getConfig().getIconBase64URI();
|
||||
if (uri == null || uri.isEmpty())
|
||||
return null;
|
||||
try {
|
||||
String b64 = uri;
|
||||
final int i = b64.indexOf("base64,");
|
||||
if (i != -1)
|
||||
b64 = b64.substring(i + "base64,".length());
|
||||
final byte[] png = Base64.getDecoder().decode(b64);
|
||||
final BufferedImage img = javax.imageio.ImageIO.read(new ByteArrayInputStream(png));
|
||||
if (img != null) {
|
||||
try {
|
||||
this.iconCache = Bukkit.loadServerIcon(img);
|
||||
} catch (final Throwable t) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.iconCache;
|
||||
} catch (final Throwable t) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String parsePlaceholders(final OPlayer player, final String txt) {
|
||||
if (this.papiPlaceholdersEnabled) {
|
||||
try {
|
||||
final UUID uuid = player.getUUID();
|
||||
final Player bp = uuid != null ? (Player) Bukkit.getPlayer(uuid) : null;
|
||||
if (bp != null) {
|
||||
return (String) ((Class<?>) this.papi)
|
||||
.getMethod("setPlaceholders", org.bukkit.entity.Player.class, String.class).invoke(null, bp, txt);
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
}
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
||||
long ms = unit.toMillis((long) period);
|
||||
long ticks = Math.max(1L, ms / 50L);
|
||||
Bukkit.getScheduler().runTaskTimer(this, task, ticks, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void shutdown() {
|
||||
this.metrics.shutdown();
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package xyz.webmc.originblacklist.bukkit.command;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.command.CommandContext;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class BKTCommandContext implements CommandContext {
|
||||
private final CommandSender sender;
|
||||
private final String[] args;
|
||||
|
||||
public BKTCommandContext(final CommandSender sender, final String[] args) {
|
||||
this.sender = sender;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName() {
|
||||
return this.sender.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reply(final String message) {
|
||||
this.sender.sendMessage(OriginBlacklist.getLegacyFromMiniMessage(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String permission) {
|
||||
return this.sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getArgs() {
|
||||
return this.args;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package xyz.webmc.originblacklist.bukkit.command;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.command.OriginBlacklistCommand;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
||||
public class OriginBlacklistCommandBukkit extends OriginBlacklistCommand implements TabExecutor {
|
||||
public OriginBlacklistCommandBukkit(OriginBlacklist plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||
return super.execute(new BKTCommandContext(sender, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||
return super.suggest(new BKTCommandContext(sender, args));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package xyz.webmc.originblacklist.bungee;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
import xyz.webmc.originblacklist.bungee.command.OriginBlacklistCommandBungee;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
import org.bstats.charts.AdvancedPie;
|
||||
import org.semver4j.Semver;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.bungee.EaglerXServerAPI;
|
||||
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.ProxyServer;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.event.PreLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
@SuppressWarnings({ "deprecation" })
|
||||
public final class OriginBlacklistBungee extends Plugin implements Listener, IOriginBlacklistPlugin {
|
||||
private ProxyServer proxy;
|
||||
private boolean papiPlaceholdersEnabled;
|
||||
private Object papi;
|
||||
private OriginBlacklist blacklist;
|
||||
private IEaglerXServerAPI eaglerAPI;
|
||||
private Metrics metrics;
|
||||
|
||||
@Override
|
||||
public final void onEnable() {
|
||||
this.proxy = ProxyServer.getInstance();
|
||||
final Plugin eagx = this.getProxy().getPluginManager().getPlugin("EaglercraftXServer");
|
||||
if (eagx == null) {
|
||||
throw new IncompatibleDependencyException("EaglercraftXServer");
|
||||
} else {
|
||||
final Semver version = new Semver(eagx.getDescription().getVersion());
|
||||
if (version.isLowerThan(OriginBlacklist.REQUIRED_API_VER)) {
|
||||
throw new IncompatibleDependencyException("EaglerXServer", OriginBlacklist.REQUIRED_API_VER, version);
|
||||
}
|
||||
}
|
||||
this.papiPlaceholdersEnabled = this.getProxy().getPluginManager().getPlugin("PAPIProxyBridge") != null;
|
||||
if (this.papiPlaceholdersEnabled) {
|
||||
try {
|
||||
this.papi = Class.forName("net.william278.papiproxybridge.api.PlaceholderAPI").getMethod("createInstance")
|
||||
.invoke(null);
|
||||
} catch (final Throwable t) {
|
||||
this.papi = null;
|
||||
this.papiPlaceholdersEnabled = false;
|
||||
}
|
||||
} else {
|
||||
this.papi = null;
|
||||
}
|
||||
this.blacklist = new OriginBlacklist(this);
|
||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
||||
this.getProxy().getPluginManager().registerCommand(this, new OriginBlacklistCommandBungee(this, this.blacklist, "originblacklist"));
|
||||
this.getProxy().getPluginManager().registerListener(this, this);
|
||||
this.log(EnumLogLevel.INFO, "Initialized Plugin");
|
||||
if (this.blacklist.isMetricsEnabled()) {
|
||||
this.metrics = new Metrics(this, OriginBlacklist.BSTATS_ID);
|
||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||
final Map<String, Integer> playerMap = new HashMap<>();
|
||||
|
||||
for (final ProxiedPlayer player : this.proxy.getPlayers()) {
|
||||
final boolean eagler = eaglerAPI.isEaglerPlayerByUUID(player.getUniqueId());
|
||||
final String key = eagler ? "Eagler" : "Java";
|
||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||
}
|
||||
|
||||
return playerMap;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onJavaLogin(final PostLoginEvent event) {
|
||||
final ProxiedPlayer aPlayer = event.getPlayer();
|
||||
final OPlayer bPlayer = new OPlayer(null, aPlayer.getName(), aPlayer.getUniqueId(),
|
||||
aPlayer.getAddress().toString(), aPlayer.getClientBrand());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onJavaHandshake(final PreLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getAddress().toString(), null);
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getAddress().toString(), null);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getPluginId() {
|
||||
return this.getDescription().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Semver getPluginVersion() {
|
||||
return new Semver(this.getDescription().getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void log(final EnumLogLevel level, final String txt) {
|
||||
if (level == EnumLogLevel.WARN) {
|
||||
this.getLogger().warning(txt);
|
||||
} else if (level == EnumLogLevel.ERROR) {
|
||||
this.getLogger().severe(txt);
|
||||
} else if (level == EnumLogLevel.DEBUG) {
|
||||
if (this.blacklist != null && this.blacklist.isDebugEnabled()) {
|
||||
this.getLogger().info(txt);
|
||||
}
|
||||
} else {
|
||||
this.getLogger().info(txt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void kickPlayer(final Component comp, final OriginBlacklistLoginEvent event) {
|
||||
final String str = OriginBlacklist.getComponentString(comp);
|
||||
if (event.getConnectionType() == EnumConnectionType.EAGLER) {
|
||||
event.getEaglerEvent().setKickMessage(str);
|
||||
} else {
|
||||
final Object javaEvent = event.getJavaEvent();
|
||||
if (javaEvent instanceof PreLoginEvent preLoginEvent) {
|
||||
preLoginEvent.getConnection().disconnect(str);
|
||||
} else if (javaEvent instanceof PostLoginEvent postLoginEvent) {
|
||||
postLoginEvent.getPlayer().disconnect(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setMOTD(final Component comp, final OriginBlacklistMOTDEvent event) {
|
||||
if (event.getConnectionType() == EnumConnectionType.EAGLER) {
|
||||
this.blacklist.setEaglerMOTD(comp, event);
|
||||
} else {
|
||||
final ProxyPingEvent javaEvent = (ProxyPingEvent) event.getJavaEvent();
|
||||
final ServerPing ping = javaEvent.getResponse();
|
||||
ping.setDescription(OriginBlacklist.getComponentString(comp));
|
||||
ping.setFavicon(this.blacklist.getConfig().getIconBase64URI());
|
||||
ping.getPlayers().setOnline(0);
|
||||
ping.getPlayers().setMax(0);
|
||||
javaEvent.setResponse(ping);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String parsePlaceholders(final OPlayer player, final String txt) {
|
||||
if (this.papiPlaceholdersEnabled && this.papi != null) {
|
||||
try {
|
||||
return (String) this.papi.getClass().getMethod("formatPlaceholders", String.class, java.util.UUID.class)
|
||||
.invoke(this.papi, txt, player.getUUID());
|
||||
} catch (final Throwable t) {
|
||||
}
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
||||
this.proxy.getScheduler().schedule(this, task, period, period, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void shutdown() {
|
||||
this.metrics.shutdown();
|
||||
this.proxy.getScheduler().cancel(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package xyz.webmc.originblacklist.bungee.command;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.command.CommandContext;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class BNGCommandContext implements CommandContext {
|
||||
private final CommandSender sender;
|
||||
private final String[] args;
|
||||
|
||||
public BNGCommandContext(final CommandSender sender, final String[] args) {
|
||||
this.sender = sender;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName() {
|
||||
return this.sender.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reply(final String message) {
|
||||
this.sender.sendMessage(TextComponent.fromLegacy(OriginBlacklist.getLegacyFromMiniMessage(message)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String permission) {
|
||||
return this.sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getArgs() {
|
||||
return this.args;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package xyz.webmc.originblacklist.bungee.command;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.command.OriginBlacklistCommand;
|
||||
import xyz.webmc.originblacklist.bungee.OriginBlacklistBungee;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
|
||||
public class OriginBlacklistCommandBungee extends Command implements TabExecutor {
|
||||
private final OriginBlacklistCommand cmd;
|
||||
|
||||
public OriginBlacklistCommandBungee(final OriginBlacklistBungee plugin, final OriginBlacklist blacklist, final String command) {
|
||||
super(command);
|
||||
this.cmd = new OriginBlacklistCommand(blacklist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
this.cmd.execute(new BNGCommandContext(sender, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(final CommandSender sender, final String[] args) {
|
||||
return this.cmd.suggest(new BNGCommandContext(sender, args));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
package xyz.webmc.originblacklist.velocity;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||
import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
import xyz.webmc.originblacklist.base.util.IncompatibleDependencyException;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
import xyz.webmc.originblacklist.velocity.command.OriginBlacklistCommandVelocity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bstats.charts.AdvancedPie;
|
||||
import org.bstats.velocity.Metrics;
|
||||
import org.bstats.velocity.Metrics.Factory;
|
||||
import org.semver4j.Semver;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerClientBrandEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import com.velocitypowered.api.util.Favicon;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftMOTDEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.EaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftLoginEvent;
|
||||
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
private final PluginContainer plugin;
|
||||
private final Factory metricsFactory;
|
||||
private final ProxyServer proxy;
|
||||
private final Logger logger;
|
||||
|
||||
private boolean papiPlaceholdersEnabled;
|
||||
private Object papi;
|
||||
private OriginBlacklist blacklist;
|
||||
private IEaglerXServerAPI eaglerAPI;
|
||||
private Metrics metrics;
|
||||
|
||||
@Inject
|
||||
public OriginBlacklistVelocity(final PluginContainer plugin, Factory metricsFactory, final ProxyServer proxy,
|
||||
final Logger logger) {
|
||||
this.plugin = plugin;
|
||||
this.metricsFactory = metricsFactory;
|
||||
this.proxy = proxy;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
this.proxy.getPluginManager().getPlugin("eaglerxserver").ifPresentOrElse(plugin -> {
|
||||
final Semver version = new Semver(plugin.getDescription().getVersion().orElse("1.0.0"));
|
||||
if (version.isLowerThan(OriginBlacklist.REQUIRED_API_VER)) {
|
||||
throw new IncompatibleDependencyException("EaglerXServer", OriginBlacklist.REQUIRED_API_VER, version);
|
||||
}
|
||||
}, () -> {
|
||||
throw new IncompatibleDependencyException("EaglerXServer");
|
||||
});
|
||||
this.papiPlaceholdersEnabled = this.proxy.getPluginManager().getPlugin("papiproxybridge").isPresent();
|
||||
if (this.papiPlaceholdersEnabled) {
|
||||
try {
|
||||
this.papi = Class.forName("net.william278.papiproxybridge.api.PlaceholderAPI").getMethod("createInstance")
|
||||
.invoke(null);
|
||||
} catch (final Throwable t) {
|
||||
this.papi = null;
|
||||
this.papiPlaceholdersEnabled = false;
|
||||
}
|
||||
} else {
|
||||
this.papi = null;
|
||||
}
|
||||
this.blacklist = new OriginBlacklist(this);
|
||||
this.eaglerAPI = EaglerXServerAPI.instance();
|
||||
this.proxy.getCommandManager().register("originblacklist", new OriginBlacklistCommandVelocity(this.blacklist));
|
||||
this.log(EnumLogLevel.INFO, "Initialized Plugin");
|
||||
if (this.blacklist.isMetricsEnabled()) {
|
||||
this.metrics = this.metricsFactory.make(this, OriginBlacklist.BSTATS_ID);
|
||||
this.metrics.addCustomChart(new AdvancedPie("player_types", () -> {
|
||||
final Map<String, Integer> playerMap = new HashMap<>();
|
||||
|
||||
for (final Player player : this.proxy.getAllPlayers()) {
|
||||
final boolean eagler = eaglerAPI.isEaglerPlayerByUUID(player.getUniqueId());
|
||||
final String key = eagler ? "Eagler" : "Java";
|
||||
playerMap.put(key, playerMap.getOrDefault(key, 0) + 1);
|
||||
}
|
||||
|
||||
return playerMap;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public final void onEaglerLogin(final EaglercraftLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getLoginConnection(), event.getProfileUsername(), event.getProfileUUID());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public final void onEaglerMOTD(final EaglercraftMOTDEvent event) {
|
||||
final OPlayer player = new OPlayer(event.getMOTDConnection(), null, null);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(event, null, EnumConnectionType.EAGLER, player));
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public final void onJavaLogin(final PreLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(null, event.getUsername(), event.getUniqueId(),
|
||||
event.getConnection().getRemoteAddress().toString(), null);
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public final void onJavaHandshake(final PlayerClientBrandEvent event) {
|
||||
final Player aPlayer = (Player) event.getPlayer();
|
||||
final OPlayer bPlayer = new OPlayer(null, aPlayer.getUsername(), aPlayer.getUniqueId(),
|
||||
aPlayer.getRemoteAddress().getAddress().toString(), event.getBrand());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getRemoteAddress().getHostString(),
|
||||
null);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getPluginId() {
|
||||
return this.plugin.getDescription().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Semver getPluginVersion() {
|
||||
return new Semver(this.plugin.getDescription().getVersion().get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void log(final EnumLogLevel level, final String txt) {
|
||||
if (level == EnumLogLevel.WARN) {
|
||||
this.logger.warn(txt);
|
||||
} else if (level == EnumLogLevel.ERROR) {
|
||||
this.logger.error(txt);
|
||||
} else if (level == EnumLogLevel.DEBUG) {
|
||||
if (this.blacklist.isDebugEnabled()) {
|
||||
this.logger.debug(txt);
|
||||
}
|
||||
} else {
|
||||
this.logger.info(txt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void kickPlayer(final Component comp, final OriginBlacklistLoginEvent event) {
|
||||
if (event.getConnectionType() == EnumConnectionType.EAGLER) {
|
||||
event.getEaglerEvent().setKickMessage(comp);
|
||||
} else {
|
||||
final Object javaEvent = event.getJavaEvent();
|
||||
if (javaEvent instanceof PreLoginEvent loginEvent) {
|
||||
loginEvent.setResult(PreLoginEvent.PreLoginComponentResult.denied(comp));
|
||||
} else if (javaEvent instanceof PlayerClientBrandEvent brandEvent) {
|
||||
brandEvent.getPlayer().disconnect(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setMOTD(final Component comp, final OriginBlacklistMOTDEvent event) {
|
||||
if (event.getConnectionType() == EnumConnectionType.EAGLER) {
|
||||
blacklist.setEaglerMOTD(comp, event);
|
||||
} else {
|
||||
final ProxyPingEvent javaEvent = (ProxyPingEvent) event.getJavaEvent();
|
||||
ServerPing ping = ServerPing.builder()
|
||||
.description(comp)
|
||||
.version(new ServerPing.Version(0, ""))
|
||||
.samplePlayers(List.of())
|
||||
.onlinePlayers(0)
|
||||
.maximumPlayers(0)
|
||||
.favicon(new Favicon(this.blacklist.getConfig().getIconBase64URI()))
|
||||
.build();
|
||||
javaEvent.setPing(ping);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String parsePlaceholders(final OPlayer player, final String txt) {
|
||||
if (this.papiPlaceholdersEnabled && this.papi != null) {
|
||||
try {
|
||||
return (String) this.papi.getClass().getMethod("formatPlaceholders", String.class, java.util.UUID.class)
|
||||
.invoke(this.papi, txt, player.getUUID());
|
||||
} catch (final Throwable t) {
|
||||
}
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void scheduleRepeat(final Runnable task, final int period, final TimeUnit unit) {
|
||||
this.proxy.getScheduler()
|
||||
.buildTask(this, task)
|
||||
.repeat(period, unit)
|
||||
.schedule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void shutdown() {
|
||||
this.metrics.shutdown();
|
||||
for (ScheduledTask task : this.proxy.getScheduler().tasksByPlugin(this.plugin)) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package xyz.webmc.originblacklist.velocity.command;
|
||||
|
||||
import xyz.webmc.originblacklist.base.OriginBlacklist;
|
||||
import xyz.webmc.originblacklist.base.command.OriginBlacklistCommand;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
|
||||
public class OriginBlacklistCommandVelocity extends OriginBlacklistCommand implements SimpleCommand {
|
||||
public OriginBlacklistCommandVelocity(OriginBlacklist plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final Invocation invocation) {
|
||||
super.execute(new VCommandContext(invocation));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(final Invocation invocation) {
|
||||
return super.suggest(new VCommandContext(invocation));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package xyz.webmc.originblacklist.velocity.command;
|
||||
|
||||
import xyz.webmc.originblacklist.base.command.CommandContext;
|
||||
|
||||
import com.velocitypowered.api.command.SimpleCommand.Invocation;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
public class VCommandContext implements CommandContext {
|
||||
private final Invocation invocation;
|
||||
|
||||
public VCommandContext(final Invocation invocation) {
|
||||
this.invocation = invocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName() {
|
||||
return this.invocation.source().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reply(final String message) {
|
||||
this.invocation.source().sendMessage(MiniMessage.miniMessage().deserialize(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String permission) {
|
||||
return this.invocation.source().hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getArgs() {
|
||||
return this.invocation.arguments();
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
@@ -1,7 +1,10 @@
|
||||
name: OriginBlacklist
|
||||
version: ${version}
|
||||
main: dev.colbster937.originblacklist.bungee.OriginBlacklistBungee
|
||||
description: ${description}
|
||||
author: Colbster937
|
||||
depends:
|
||||
- EaglercraftXServer
|
||||
name: ${plugin_name}
|
||||
version: ${plugin_vers}
|
||||
main: xyz.webmc.${plugin_iden}.bungee.${plugin_name}Bungee
|
||||
description: ${plugin_desc}
|
||||
website: ${plugin_site}
|
||||
author: [${plugin_athr}]
|
||||
contributors: [${plugin_ctbr}]
|
||||
depends: [${plugin_depb}]
|
||||
provides: [${plugin_prov}]
|
||||
softdepend: [${plugin_sdpb}]
|
||||
@@ -1,69 +0,0 @@
|
||||
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
|
||||
# - %notallowed1% - Longer "not allowed" message
|
||||
# - %notallowed2% - Shorter "not allowed" message
|
||||
# - %host% - The IP the player pinged
|
||||
# - %help% - The configured help message for the block type
|
||||
|
||||
kick: |
|
||||
<red>This %easyblocktype% is %notallowed1%!</red>
|
||||
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
|
||||
|
||||
%help%
|
||||
|
||||
<gray>Think this is a mistake? Join our discord:</gray>
|
||||
<blue>discord.gg/changethisintheconfig</blue>
|
||||
|
||||
# Please note that help is only supported in the kick message, not the MOTD
|
||||
help:
|
||||
generic: "<gray>Please switch to a different %easyblocktype%.</gray>"
|
||||
player: "<gray>Please change your %easyblocktype%.</gray>"
|
||||
ip: "<gray>Please contact staff for assistance.</gray>"
|
||||
|
||||
motd:
|
||||
enabled: true
|
||||
text: |
|
||||
<red>This %easyblocktype% is %notallowed2%!</red>
|
||||
<dark_gray>»</dark_gray> <gray>%blocked%</gray>
|
||||
icon: "blacklisted.png"
|
||||
|
||||
# Origin + Brand blacklist supports wildcards
|
||||
# Everything should be lowercase
|
||||
blacklist:
|
||||
origins:
|
||||
- "*eagler-clients.vercel.app*"
|
||||
- "*eaglerhackedclients.vercel.app*"
|
||||
- "*eaglerhacks.github.io*"
|
||||
brands:
|
||||
- "*dragonx*"
|
||||
- "*piclient*"
|
||||
players:
|
||||
- "Admin"
|
||||
ips:
|
||||
- "192.0.2.0/24"
|
||||
|
||||
discord:
|
||||
webhook: ""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# :>
|
||||
@@ -1,9 +1,12 @@
|
||||
name: OriginBlacklist
|
||||
version: ${version}
|
||||
main: dev.colbster937.originblacklist.bukkit.OriginBlacklistBukkit
|
||||
description: ${description}
|
||||
author: Colbster937
|
||||
depend:
|
||||
- EaglercraftXServer
|
||||
name: ${plugin_name}
|
||||
version: ${plugin_vers}
|
||||
main: xyz.webmc.${plugin_iden}.bukkit.${plugin_name}Bukkit
|
||||
description: ${plugin_desc}
|
||||
website: ${plugin_site}
|
||||
authors: [${plugin_athr}]
|
||||
contributors: [${plugin_ctbr}]
|
||||
depend: [${plugin_depa}]
|
||||
provides: [${plugin_prov}]
|
||||
softdepend: [${plugin_sdpa}]
|
||||
commands:
|
||||
originblacklist:
|
||||
@@ -1,14 +1,10 @@
|
||||
{
|
||||
"id": "originblacklist",
|
||||
"name": "OriginBlacklist",
|
||||
"version": "${version}",
|
||||
"description": "${description}",
|
||||
"main": "dev.colbster937.originblacklist.velocity.OriginBlacklistVelocity",
|
||||
"authors": ["Colbster937"],
|
||||
"dependencies": [
|
||||
{
|
||||
"id": "eaglerxserver",
|
||||
"optional": false
|
||||
}
|
||||
]
|
||||
}
|
||||
"id": "${plugin_iden}",
|
||||
"name": "${plugin_name}",
|
||||
"version": "${plugin_vers}",
|
||||
"description": "${plugin_desc}",
|
||||
"website": "${plugin_site}",
|
||||
"main": "xyz.webmc.${plugin_iden}.velocity.${plugin_name}Velocity",
|
||||
"authors": [${plugin_athr}],
|
||||
"dependencies": [${plugin_depc}]
|
||||
}
|
||||
Reference in New Issue
Block a user