mirror of
https://git.webmc.xyz/Colbster937/originblacklist
synced 2025-07-22 05:31:18 -09:00
Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6e1d5d132c | ||
![]() |
1a22788630 | ||
![]() |
cf0481fb58 | ||
![]() |
f8ea6d5bfd | ||
![]() |
8d5e5d688b | ||
![]() |
2648377276 | ||
![]() |
16953bc708 | ||
![]() |
0f80dded63 | ||
![]() |
af478adb3b | ||
![]() |
8dbd01f016 | ||
![]() |
71ad3059cc | ||
![]() |
c5a2b1002f | ||
![]() |
4d0f0542ca | ||
![]() |
5453ed0280 | ||
![]() |
47ab6554c4 | ||
![]() |
c076d48e06 | ||
![]() |
a0ab221ff7 | ||
![]() |
ec6f618971 | ||
![]() |
a417fa7281 | ||
![]() |
c62cdb8a7e |
27
.github/workflows/build.yml
vendored
27
.github/workflows/build.yml
vendored
@ -36,16 +36,29 @@ jobs:
|
|||||||
name: OriginBlacklist
|
name: OriginBlacklist
|
||||||
path: build/libs/OriginBlacklist.jar
|
path: build/libs/OriginBlacklist.jar
|
||||||
|
|
||||||
|
- name: Extract Version
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
VERSION=$(grep "^version" build.gradle | head -n 1 | cut -d\' -f2)
|
||||||
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Remove Existing Release
|
||||||
|
run: |
|
||||||
|
gh release delete v${{ steps.version.outputs.version }} -y || true
|
||||||
|
git push origin :refs/tags/v${{ steps.version.outputs.version }} || true
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
tag_name: v${{ steps.version.outputs.version }}
|
||||||
|
name: ${{ steps.version.outputs.version }}
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
|
||||||
tag_name: dev
|
|
||||||
release_name: dev
|
|
||||||
draft: true
|
|
||||||
prerelease: true
|
|
||||||
|
|
||||||
- uses: actions/upload-release-asset@v1.0.1
|
- uses: actions/upload-release-asset@v1.0.1
|
||||||
env:
|
env:
|
||||||
@ -53,7 +66,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
asset_path: ./build/libs/OriginBlacklist.jar
|
asset_path: ./build/libs/OriginBlacklist.jar
|
||||||
asset_name: OriginBlacklist.jar
|
asset_name: OriginBlacklist_${{ steps.version.outputs.version }}.jar
|
||||||
asset_content_type: application/java-archive
|
asset_content_type: application/java-archive
|
||||||
|
|
||||||
- uses: eregon/publish-release@v1
|
- uses: eregon/publish-release@v1
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,5 +4,6 @@
|
|||||||
gradle
|
gradle
|
||||||
build
|
build
|
||||||
run
|
run
|
||||||
|
bin
|
||||||
gradlew
|
gradlew
|
||||||
gradlew.bat
|
gradlew.bat
|
11
README.md
11
README.md
@ -8,19 +8,20 @@ basically just a reimplementation of originblacklist but for eaglerxserver
|
|||||||
### Features
|
### Features
|
||||||
- [x] Origin Blacklisting
|
- [x] Origin Blacklisting
|
||||||
- [x] Brand Blacklisting
|
- [x] Brand Blacklisting
|
||||||
|
- [x] Username blacklisting
|
||||||
|
- [x] IP blacklisting
|
||||||
- [x] Custom kick message
|
- [x] Custom kick message
|
||||||
- [x] Custom blacklist MOTD
|
- [x] Custom blacklist MOTD
|
||||||
- [x] MiniMessage formatting for messages
|
- [x] MiniMessage formatting for messages
|
||||||
- [x] Velocity, *Bungee, and *Bukkit support
|
- [x] Velocity, Bungee, and Bukkit support
|
||||||
<br>_<sub><span style="color:gray">Bungee and Bukkit are should work, but have bugs.</span></sub>_
|
|
||||||
- [x] Send blacklists to a discord webhook
|
- [x] Send blacklists to a discord webhook
|
||||||
|
- [x] Simple blacklist command
|
||||||
- [ ] Blacklist subscription URLs
|
- [ ] Blacklist subscription URLs
|
||||||
- [ ] Simple blacklist command
|
|
||||||
- [ ] Blacklist -> Whitelist
|
- [ ] Blacklist -> Whitelist
|
||||||
- [ ] IP blacklisting
|
- [ ] Update system
|
||||||
|
|
||||||
### Download
|
### Download
|
||||||
**https://nightly.link/colbster937/originblacklist/workflows/build/main/OriginBlacklist.zip](https://nightly.link/colbster937/originblacklist/workflows/build/main/OriginBlacklist.zip)**
|
**[https://github.com/colbster937/originblacklist/releases/latest/](https://github.com/colbster937/originblacklist/releases/latest/)**
|
||||||
|
|
||||||
### Building
|
### Building
|
||||||
```
|
```
|
||||||
|
@ -8,7 +8,7 @@ plugins {
|
|||||||
|
|
||||||
|
|
||||||
group = 'dev.colbster937'
|
group = 'dev.colbster937'
|
||||||
version = '1.0.2'
|
version = '1.1.0'
|
||||||
description = 'A reimplementation of OriginBlacklist for EaglerXServer'
|
description = 'A reimplementation of OriginBlacklist for EaglerXServer'
|
||||||
def targetJavaVersion = 17
|
def targetJavaVersion = 17
|
||||||
|
|
||||||
@ -51,6 +51,7 @@ dependencies {
|
|||||||
implementation("org.yaml:snakeyaml:2.2")
|
implementation("org.yaml:snakeyaml:2.2")
|
||||||
implementation("net.kyori:adventure-text-serializer-legacy:4.20.0")
|
implementation("net.kyori:adventure-text-serializer-legacy:4.20.0")
|
||||||
implementation("net.kyori:adventure-text-minimessage:4.20.0")
|
implementation("net.kyori:adventure-text-minimessage:4.20.0")
|
||||||
|
implementation("com.github.seancfoley:ipaddress:5.3.4")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
@ -64,7 +65,7 @@ java {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
filesMatching(['plugin.yml', 'bungee.yml', 'velocity-plugin.json']) {
|
filesMatching(['plugin.yml', 'bungee.yml', 'velocity-plugin.json', 'Base.java']) {
|
||||||
expand(
|
expand(
|
||||||
version: project.version,
|
version: project.version,
|
||||||
description: project.description
|
description: project.description
|
||||||
@ -74,6 +75,7 @@ processResources {
|
|||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
relocate 'org.yaml.snakeyaml', 'dev.colbster937.shaded.snakeyaml'
|
relocate 'org.yaml.snakeyaml', 'dev.colbster937.shaded.snakeyaml'
|
||||||
|
relocate 'inet.ipaddr', 'dev.colbster937.shaded.ipaddr'
|
||||||
archiveVersion.set('')
|
archiveVersion.set('')
|
||||||
archiveClassifier.set('')
|
archiveClassifier.set('')
|
||||||
}
|
}
|
||||||
|
@ -8,23 +8,21 @@ 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.event.IEaglercraftMOTDEvent;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Base {
|
public class Base {
|
||||||
private static LoggerAdapter adapter;
|
private static LoggerAdapter adapter;
|
||||||
private static IEaglerXServerAPI api;
|
private static IEaglerXServerAPI api;
|
||||||
private static ConfigManager config;
|
private static IPBlacklist ipblacklist;
|
||||||
|
|
||||||
public static void setLogger(LoggerAdapter log) {
|
public static void setLogger(LoggerAdapter log) {
|
||||||
adapter = log;
|
adapter = log;
|
||||||
@ -34,14 +32,35 @@ public class Base {
|
|||||||
api = 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() {
|
public static LoggerAdapter getLogger() {
|
||||||
if (adapter == null) throw new IllegalStateException("Logger not initialized!");
|
if (adapter == null)
|
||||||
|
throw new IllegalStateException("Logger not initialized!");
|
||||||
return adapter;
|
return adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface LoggerAdapter {
|
public interface LoggerAdapter {
|
||||||
void info(String msg);
|
void info(String msg);
|
||||||
|
|
||||||
void warn(String msg);
|
void warn(String msg);
|
||||||
|
|
||||||
void error(String msg);
|
void error(String msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,30 +68,49 @@ public class Base {
|
|||||||
IEaglerLoginConnection conn = e.getLoginConnection();
|
IEaglerLoginConnection conn = e.getLoginConnection();
|
||||||
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||||
String brand = conn.getEaglerBrandString();
|
String brand = conn.getEaglerBrandString();
|
||||||
if ((origin != "null" || origin != null) && !config.blacklist.missing_origin) {
|
String name = conn.getUsername();
|
||||||
|
String notAllowed1 = "not allowed on the server";
|
||||||
|
String notAllowed2 = "not allowed";
|
||||||
|
|
||||||
|
if (origin != null && !origin.equals("null")) {
|
||||||
for (String origin1 : config.blacklist.origins) {
|
for (String origin1 : config.blacklist.origins) {
|
||||||
if (matches(origin, origin1)) {
|
if (matches(origin, origin1)) {
|
||||||
e.setKickMessage(kick("origin", "website", origin));
|
setKick(e, formatKickMessage("origin", "website", notAllowed1, notAllowed2, origin, conn.getWebSocketHost()));
|
||||||
webhook(conn, origin, brand, "origin");
|
webhook(conn, origin, brand, "origin");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (origin != "null" || origin != null) {
|
|
||||||
e.setKickMessage(kick("origin", "website", origin));
|
|
||||||
webhook(conn, "null", brand, "origin");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (brand != "null" && brand != null) {
|
|
||||||
|
if (brand != null && !brand.equals("null")) {
|
||||||
for (String brand1 : config.blacklist.brands) {
|
for (String brand1 : config.blacklist.brands) {
|
||||||
if (matches(brand, brand1)) {
|
if (matches(brand, brand1)) {
|
||||||
e.setKickMessage(kick("brand", "client", brand));
|
setKick(e, formatKickMessage("brand", "client", notAllowed1, notAllowed2, brand, conn.getWebSocketHost()));
|
||||||
webhook(conn, origin, brand, "brand");
|
webhook(conn, origin, brand, "brand");
|
||||||
return;
|
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, name, "player");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
public static void handleMOTD(IEaglercraftMOTDEvent e) {
|
||||||
@ -81,25 +119,23 @@ public class Base {
|
|||||||
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||||
List<String> m = List.of(config.messages.motd.text.split("\n")).stream()
|
List<String> m = List.of(config.messages.motd.text.split("\n")).stream()
|
||||||
.map(line -> line
|
.map(line -> line
|
||||||
.replace("%blocktype%", "origin")
|
.replaceAll("%blocktype%", "origin")
|
||||||
.replace("%easyblocktype%", "website")
|
.replaceAll("%easyblocktype%", "website")
|
||||||
.replace("%blocked%", origin))
|
.replaceAll("%notallowed1%", "blacklisted")
|
||||||
|
.replaceAll("%notallowed2%", "blacklisted")
|
||||||
|
.replaceAll("%blocked%", origin)
|
||||||
|
.replaceAll("%host%", conn.getWebSocketHost()))
|
||||||
.map(line -> LegacyComponentSerializer.legacySection().serialize(
|
.map(line -> LegacyComponentSerializer.legacySection().serialize(
|
||||||
MiniMessage.miniMessage().deserialize(
|
MiniMessage.miniMessage().deserialize(line)))
|
||||||
line
|
.collect(Collectors.toList());
|
||||||
)
|
|
||||||
)).collect(Collectors.toList());
|
if (origin != null && !origin.equals("null")) {
|
||||||
if ((origin != "null" || origin != null) && !config.blacklist.missing_origin) {
|
|
||||||
for (String origin1 : config.blacklist.origins) {
|
for (String origin1 : config.blacklist.origins) {
|
||||||
if (matches(origin, origin1)) {
|
if (matches(origin, origin1)) {
|
||||||
setMOTD(conn, m);
|
setMOTD(conn, m);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (origin != "null" || origin != null) {
|
|
||||||
setMOTD(conn, m);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,13 +145,15 @@ public class Base {
|
|||||||
conn.setPlayerTotal(0);
|
conn.setPlayerTotal(0);
|
||||||
conn.setPlayerMax(0);
|
conn.setPlayerMax(0);
|
||||||
conn.setPlayerList(List.of());
|
conn.setPlayerList(List.of());
|
||||||
if (config.messages.motd.icon != null && !config.messages.motd.icon.isEmpty())
|
|
||||||
|
if (config.messages.motd.icon != null && !config.messages.motd.icon.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
BufferedImage img = ImageIO.read(new File(config.messages.motd.icon));
|
BufferedImage img = ImageIO.read(new File(config.messages.motd.icon));
|
||||||
if (img.getWidth() != 64 || img.getHeight() != 64) {
|
if (img.getWidth() != 64 || img.getHeight() != 64) {
|
||||||
getLogger().warn("Icon must be 64x64");
|
getLogger().warn("Icon must be 64x64");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] bytes = new byte[64 * 64 * 4];
|
byte[] bytes = new byte[64 * 64 * 4];
|
||||||
for (int y = 0; y < 64; y++) {
|
for (int y = 0; y < 64; y++) {
|
||||||
for (int x = 0; x < 64; x++) {
|
for (int x = 0; x < 64; x++) {
|
||||||
@ -131,61 +169,94 @@ public class Base {
|
|||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
getLogger().error(ex.toString());
|
getLogger().error(ex.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String handlePre(String ip, String name) {
|
||||||
|
if (ip != null && !ip.equalsIgnoreCase("null")) {
|
||||||
|
for (String ip1 : Base.config.blacklist.ips) {
|
||||||
|
if (ipblacklist.check(ip)) {
|
||||||
|
Component kick = formatKickMessage("ip address", "ip", "blacklisted", "blacklisted", ip, "");
|
||||||
|
return LegacyComponentSerializer.legacySection().serialize(kick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean matches(String text1, String text2) {
|
public static boolean matches(String text1, String text2) {
|
||||||
return text1.toLowerCase().matches(text2.replace(".", "\\.").replaceAll("\\*", ".*").toLowerCase());
|
return text1.toLowerCase().matches(text2.replace(".", "\\.").replaceAll("\\*", ".*").toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component kick(String type, String easytype, String value) {
|
public static Component formatKickMessage(String type, String easytype, String notAllowed1, String notAllowed2, String value, String host) {
|
||||||
|
String help = "";
|
||||||
|
if (type != "player") {
|
||||||
|
help = config.messages.help.generic;
|
||||||
|
} else if (type == "ip") {
|
||||||
|
help = config.messages.help.ip;
|
||||||
|
} else {
|
||||||
|
help = config.messages.help.player;
|
||||||
|
}
|
||||||
return MiniMessage.miniMessage().deserialize(
|
return MiniMessage.miniMessage().deserialize(
|
||||||
config.messages.kick
|
config.messages.kick
|
||||||
.replace("%blocktype%", type)
|
.replaceAll("%help%", help)
|
||||||
.replace("%easyblocktype%", easytype)
|
.replaceAll("%blocktype%", type)
|
||||||
.replace("%blocked%", value)
|
.replaceAll("%easyblocktype%", easytype)
|
||||||
);
|
.replaceAll("%notallowed1%", notAllowed1)
|
||||||
|
.replaceAll("%notallowed2%", notAllowed2)
|
||||||
|
.replaceAll("%blocked%", value)
|
||||||
|
.replaceAll("%host%", host));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void webhook(IEaglerPendingConnection plr, String origin, String brand, String type) {
|
public static void webhook(IEaglerLoginConnection plr, String origin, String brand, String type) {
|
||||||
String webhook = config.discord.webhook;
|
String webhook = config.discord.webhook;
|
||||||
if (webhook == null || webhook.isBlank()) return;
|
if (webhook == null || webhook.isBlank())
|
||||||
|
return;
|
||||||
|
|
||||||
String addr = plr.getPlayerAddress() != null ? plr.getPlayerAddress().toString().substring(1) : "undefined";
|
CompletableFuture.runAsync(() -> {
|
||||||
String protocol = plr.isEaglerXRewindPlayer()
|
String addr = getAddr(plr);
|
||||||
? (String.valueOf(plr.getRewindProtocolVersion()) != null ? String.valueOf(plr.getRewindProtocolVersion()) : "undefined")
|
int protocol = !plr.isEaglerXRewindPlayer() ? plr.getMinecraftProtocol() : plr.getRewindProtocolVersion();
|
||||||
: (String.valueOf(plr.getMinecraftProtocol()) != null ? String.valueOf(plr.getMinecraftProtocol()) : "undefined");
|
String host = plr.getWebSocketHost();
|
||||||
String rewind = plr.isEaglerXRewindPlayer() ? "Yes" : "No";
|
String userAgent = plr.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT);
|
||||||
String userAgent = plr.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT);
|
Boolean rewind = plr.isEaglerXRewindPlayer();
|
||||||
if (userAgent == null || userAgent.isEmpty()) userAgent = "undefined";
|
if (userAgent == null || userAgent.isEmpty())
|
||||||
|
userAgent = "undefined";
|
||||||
|
|
||||||
String payload = String.format("""
|
String payload = String.format(
|
||||||
{
|
"""
|
||||||
"content": "Blocked a blacklisted %s from joining",
|
{
|
||||||
"embeds": [
|
"content": "Blocked a blacklisted %s from joining",
|
||||||
{
|
"embeds": [
|
||||||
"title": "Player Information",
|
{
|
||||||
"description": "🎮 **Name:** %s\\n🏠 **Address:** %s\\n🌄 **PVN:** %s\\n🌐 **Origin:** %s\\n🔋 **Brand:** %s\\n🧊 **User Agent:** %s\\n⏪ **Rewind:** %s"
|
"title": "Player Information",
|
||||||
|
"description": "🎮 **Name:** %s\\n🏠 **IP:** %s\\n🌄 **PVN:** %s\\n🌐 **Origin:** %s\\n🔋 **Brand:** %s\\n🪑 **Host:** %s\\n🧊 **User Agent:** %s\\n⏪ **Rewind:** %s"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""",
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
]
|
});
|
||||||
}
|
}
|
||||||
""", type, plr.getAuthUsername(), addr, protocol, origin, brand, userAgent, rewind);
|
|
||||||
|
|
||||||
try {
|
public static String getAddr(IEaglerLoginConnection plr) {
|
||||||
HttpURLConnection conn = (HttpURLConnection) new URL(webhook).openConnection();
|
return (plr.getPlayerAddress() != null ? plr.getPlayerAddress().toString().substring(1) : "undefined:undefined").split(":")[0];
|
||||||
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 void init() {
|
public static void init() {
|
||||||
@ -199,6 +270,7 @@ public class Base {
|
|||||||
getLogger().warn(e.toString());
|
getLogger().warn(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ipblacklist = new IPBlacklist();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadConfig() {
|
public static void reloadConfig() {
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
package dev.colbster937.originblacklist.base;
|
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 {
|
public class Command {
|
||||||
|
private static final String permission = "<red>You do not have permission to use this command.</red>";
|
||||||
|
|
||||||
public interface CommandContext {
|
public interface CommandContext {
|
||||||
String getName();
|
String getName();
|
||||||
@ -9,16 +19,18 @@ public class Command {
|
|||||||
String[] getArgs();
|
String[] getArgs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void usage(CommandContext ctx) {
|
public static void usage(CommandContext ctx) {
|
||||||
ctx.reply("<aqua>Commands:</aqua>");
|
ctx.reply("<aqua>Commands:</aqua>");
|
||||||
ctx.reply("<gray> - /originblacklist reload</gray>");
|
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) {
|
public static void handle(CommandContext ctx) {
|
||||||
String[] args = ctx.getArgs();
|
String[] args = ctx.getArgs();
|
||||||
if (!ctx.hasPermission("originblacklist.reload")) {
|
if (!ctx.hasPermission("originblacklist.command")) {
|
||||||
ctx.reply("<red>You do not have permission to use this command.</red>");
|
ctx.reply(permission);
|
||||||
return;
|
return;
|
||||||
} else if (args.length == 0) {
|
} else if (args.length == 0) {
|
||||||
usage(ctx);
|
usage(ctx);
|
||||||
@ -26,14 +38,136 @@ public class Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String sub = args[0].toLowerCase();
|
String sub = args[0].toLowerCase();
|
||||||
|
String sub1 = args.length > 1 ? args[1].toLowerCase() : "";
|
||||||
|
String sub2 = args.length > 2 ? args[2].toLowerCase() : "";
|
||||||
|
|
||||||
switch (sub) {
|
switch (sub) {
|
||||||
case "reload" -> {
|
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();
|
Base.reloadConfig();
|
||||||
ctx.reply("<green>Reloaded.</green>");
|
}
|
||||||
|
|
||||||
|
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);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,47 +3,117 @@ package dev.colbster937.originblacklist.base;
|
|||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import org.yaml.snakeyaml.LoaderOptions;
|
import org.yaml.snakeyaml.LoaderOptions;
|
||||||
import org.yaml.snakeyaml.constructor.Constructor;
|
import org.yaml.snakeyaml.constructor.Constructor;
|
||||||
import java.io.File;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
import java.io.InputStream;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.List;
|
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 class ConfigManager {
|
||||||
public Messages messages = new Messages();
|
public Messages messages = new Messages();
|
||||||
public List<String> subscriptions;
|
//public List<String> subscriptions = List.of();
|
||||||
public Blacklist blacklist = new Blacklist();
|
public Blacklist blacklist = new Blacklist();
|
||||||
public Discord discord = new Discord();
|
public Discord discord = new Discord();
|
||||||
|
|
||||||
public static ConfigManager loadConfig(Base.LoggerAdapter logger) {
|
public static ConfigManager loadConfig(Base.LoggerAdapter logger) {
|
||||||
File conf = new File("plugins/originblacklist/config.yml");
|
File f = new File("plugins/originblacklist/config.yml");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!conf.exists()) {
|
if (!f.exists()) {
|
||||||
conf.getParentFile().mkdirs();
|
f.getParentFile().mkdirs();
|
||||||
try (InputStream in = ConfigManager.class.getResourceAsStream("/config.yml")) {
|
try (InputStream in = ConfigManager.class.getResourceAsStream("/config.yml")) {
|
||||||
if (in != null) {
|
if (in != null) Files.copy(in, f.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
Files.copy(in, conf.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LoaderOptions options = new LoaderOptions();
|
Constructor constructor = new Constructor(ConfigManager.class, new LoaderOptions());
|
||||||
Constructor constructor = new Constructor(ConfigManager.class, options);
|
constructor.setPropertyUtils(new org.yaml.snakeyaml.introspector.PropertyUtils() {{
|
||||||
Yaml yaml = new Yaml(constructor);
|
setSkipMissingProperties(true);
|
||||||
return yaml.load(new FileInputStream(conf));
|
}});
|
||||||
|
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) {
|
} catch (IOException e) {
|
||||||
return new ConfigManager();
|
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 static class Blacklist {
|
||||||
public List<String> origins;
|
public List<String> origins;
|
||||||
public List<String> brands;
|
public List<String> brands;
|
||||||
public List<String> players;
|
public List<String> players;
|
||||||
|
public List<String> ips = List.of();
|
||||||
|
public transient Set<IPAddress> ips1 = new CopyOnWriteArraySet<>();
|
||||||
public boolean missing_origin;
|
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 static class Discord {
|
||||||
@ -53,6 +123,7 @@ public class ConfigManager {
|
|||||||
public static class Messages {
|
public static class Messages {
|
||||||
public String kick;
|
public String kick;
|
||||||
public MOTD motd;
|
public MOTD motd;
|
||||||
|
public Help help;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MOTD {
|
public static class MOTD {
|
||||||
@ -60,4 +131,10 @@ public class ConfigManager {
|
|||||||
public String text;
|
public String text;
|
||||||
public String icon;
|
public String icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Help {
|
||||||
|
public String generic;
|
||||||
|
public String player;
|
||||||
|
public String ip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
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,24 +1,37 @@
|
|||||||
package dev.colbster937.originblacklist.bukkit;
|
package dev.colbster937.originblacklist.bukkit;
|
||||||
|
|
||||||
import dev.colbster937.originblacklist.base.Command;
|
|
||||||
import dev.colbster937.originblacklist.base.Command.CommandContext;
|
import dev.colbster937.originblacklist.base.Command.CommandContext;
|
||||||
import org.bukkit.command.CommandSender;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class CommandBukkit implements CommandExecutor {
|
public class CommandBukkit implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
|
||||||
Command.handle(new CommandContext() {
|
dev.colbster937.originblacklist.base.Command.handle(new CommandContext() {
|
||||||
public String getName() { return sender.getName(); }
|
@Override
|
||||||
public void reply(String msg) { sender.sendMessage(msg); }
|
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) {
|
public boolean hasPermission(String permission) {
|
||||||
return sender.hasPermission(permission);
|
return sender.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getArgs() {
|
public String[] getArgs() {
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,12 +6,26 @@ import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftLogin
|
|||||||
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftMOTDEvent;
|
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftMOTDEvent;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class OriginBlacklistBukkit extends JavaPlugin implements Listener {
|
public class OriginBlacklistBukkit extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
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() {
|
Base.setLogger(new Base.LoggerAdapter() {
|
||||||
@Override public void info(String msg) { getLogger().info(msg); }
|
@Override public void info(String msg) { getLogger().info(msg); }
|
||||||
@Override public void warn(String msg) { getLogger().warning(msg); }
|
@Override public void warn(String msg) { getLogger().warning(msg); }
|
||||||
@ -37,4 +51,14 @@ public class OriginBlacklistBukkit extends JavaPlugin implements Listener {
|
|||||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||||
Base.handleMOTD(event);
|
Base.handleMOTD(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
|
||||||
|
String ip = event.getAddress().getHostAddress();
|
||||||
|
String name = event.getName();
|
||||||
|
String blacklisted = Base.handlePre(ip, name);
|
||||||
|
if (!blacklisted.equals("false")) {
|
||||||
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, blacklisted);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package dev.colbster937.originblacklist.bungee;
|
package dev.colbster937.originblacklist.bungee;
|
||||||
|
|
||||||
import dev.colbster937.originblacklist.base.Command;
|
|
||||||
import dev.colbster937.originblacklist.base.Command.CommandContext;
|
import dev.colbster937.originblacklist.base.Command.CommandContext;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
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 class CommandBungee extends net.md_5.bungee.api.plugin.Command {
|
||||||
|
|
||||||
@ -12,15 +12,22 @@ public class CommandBungee extends net.md_5.bungee.api.plugin.Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
Command.handle(new CommandContext() {
|
dev.colbster937.originblacklist.base.Command.handle(new CommandContext() {
|
||||||
public String getName() { return sender.getName(); }
|
public String getName() {
|
||||||
public void reply(String msg) { sender.sendMessage(msg); }
|
return sender.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reply(String msg) {
|
||||||
|
sender.sendMessage(TextComponent.fromLegacyText(msg));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPermission(String permission) {
|
public boolean hasPermission(String permission) {
|
||||||
return sender.hasPermission(permission);
|
return sender.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getArgs() {
|
public String[] getArgs() {
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import dev.colbster937.originblacklist.base.Base;
|
|||||||
import net.lax1dude.eaglercraft.backend.server.api.bungee.EaglerXServerAPI;
|
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.EaglercraftLoginEvent;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.bungee.event.EaglercraftMOTDEvent;
|
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.Plugin;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
@ -12,6 +13,18 @@ public class OriginBlacklistBungee extends Plugin implements Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
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() {
|
Base.setLogger(new Base.LoggerAdapter() {
|
||||||
@Override public void info(String msg) { getLogger().info(msg); }
|
@Override public void info(String msg) { getLogger().info(msg); }
|
||||||
@Override public void warn(String msg) { getLogger().warning(msg); }
|
@Override public void warn(String msg) { getLogger().warning(msg); }
|
||||||
@ -37,4 +50,15 @@ public class OriginBlacklistBungee extends Plugin implements Listener {
|
|||||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||||
Base.handleMOTD(event);
|
Base.handleMOTD(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPreLogin(PreLoginEvent event) {
|
||||||
|
String ip = event.getConnection().getAddress().getAddress().getHostAddress();
|
||||||
|
String name = event.getConnection().getName();
|
||||||
|
String blacklisted = Base.handlePre(ip, name);
|
||||||
|
if (!blacklisted.equals("false")) {
|
||||||
|
event.setCancelReason(blacklisted);
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,49 @@
|
|||||||
package dev.colbster937.originblacklist.velocity;
|
package dev.colbster937.originblacklist.velocity;
|
||||||
|
|
||||||
import com.velocitypowered.api.command.SimpleCommand;
|
import com.velocitypowered.api.command.SimpleCommand;
|
||||||
|
import dev.colbster937.originblacklist.base.Command;
|
||||||
import dev.colbster937.originblacklist.base.Command.CommandContext;
|
import dev.colbster937.originblacklist.base.Command.CommandContext;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandVelocity implements SimpleCommand {
|
public class CommandVelocity implements SimpleCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Invocation invocation) {
|
public void execute(Invocation invocation) {
|
||||||
CommandSource source = invocation.source();
|
Command.handle(new VelocityCommandContext(invocation));
|
||||||
dev.colbster937.originblacklist.base.Command.handle(new CommandContext() {
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return source.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reply(String msg) {
|
|
||||||
source.sendMessage(MiniMessage.miniMessage().deserialize(msg));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(String permission) {
|
|
||||||
return source.hasPermission(permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getArgs() {
|
|
||||||
return invocation.arguments();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@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,13 +1,16 @@
|
|||||||
package dev.colbster937.originblacklist.velocity;
|
package dev.colbster937.originblacklist.velocity;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import dev.colbster937.originblacklist.base.Base;
|
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.EaglerXServerAPI;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftLoginEvent;
|
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftLoginEvent;
|
||||||
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftMOTDEvent;
|
import net.lax1dude.eaglercraft.backend.server.api.velocity.event.EaglercraftMOTDEvent;
|
||||||
|
import java.net.InetAddress;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
public class OriginBlacklistVelocity {
|
public class OriginBlacklistVelocity {
|
||||||
@ -28,6 +31,14 @@ public class OriginBlacklistVelocity {
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
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.setApi(EaglerXServerAPI.instance());
|
||||||
Base.reloadConfig();
|
Base.reloadConfig();
|
||||||
Base.init();
|
Base.init();
|
||||||
@ -44,4 +55,14 @@ public class OriginBlacklistVelocity {
|
|||||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||||
Base.handleMOTD(event);
|
Base.handleMOTD(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onPreLogin(PreLoginEvent event) {
|
||||||
|
String ip = event.getConnection().getRemoteAddress().getAddress().toString();
|
||||||
|
String name = event.getUsername();
|
||||||
|
String blacklisted = Base.handlePre(ip, name);
|
||||||
|
if (!blacklisted.equals("false")) {
|
||||||
|
event.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(blacklisted)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,30 @@ messages:
|
|||||||
# - %blocked% - The player's origin/brand that was blocked
|
# - %blocked% - The player's origin/brand that was blocked
|
||||||
# - %blocktype% - Shows what the player was blocked for
|
# - %blocktype% - Shows what the player was blocked for
|
||||||
# - %easyblocktype% - Shows what the player was blocked for in an eagler-kid readable form
|
# - %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: |
|
kick: |
|
||||||
<red>This %easyblocktype% is not allowed on the server!</red>
|
<red>This %easyblocktype% is %notallowed1%!</red>
|
||||||
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
|
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
|
||||||
|
|
||||||
|
%help%
|
||||||
|
|
||||||
<gray>Think this is a mistake? Join our discord:</gray>
|
<gray>Think this is a mistake? Join our discord:</gray>
|
||||||
<blue>discord.gg/changethisintheconfig</blue>
|
<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:
|
motd:
|
||||||
enabled: true
|
enabled: true
|
||||||
text: |
|
text: |
|
||||||
<red>This %easyblocktype% is not allowed!</red>
|
<red>This %easyblocktype% is %notallowed2%!</red>
|
||||||
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
|
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
|
||||||
icon: "blacklisted.png"
|
icon: "blacklisted.png"
|
||||||
|
|
||||||
@ -22,11 +34,16 @@ messages:
|
|||||||
# Everything should be lowercase
|
# Everything should be lowercase
|
||||||
blacklist:
|
blacklist:
|
||||||
origins:
|
origins:
|
||||||
- "hack.example.com"
|
- "*eagler-clients.vercel.app*"
|
||||||
|
- "*eaglerhackedclients.vercel.app*"
|
||||||
|
- "*eaglerhacks.github.io*"
|
||||||
brands:
|
brands:
|
||||||
- "*dragonx*"
|
- "*dragonx*"
|
||||||
- "*piclient*"
|
- "*piclient*"
|
||||||
missing_origin: false
|
players:
|
||||||
|
- "Admin"
|
||||||
|
ips:
|
||||||
|
- "192.0.2.0/24"
|
||||||
|
|
||||||
discord:
|
discord:
|
||||||
webhook: ""
|
webhook: ""
|
||||||
@ -45,23 +62,6 @@ discord:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user