2 Commits
Author SHA1 Message Date
asminme 8731c80227 Fix ban modal and clean console output
Build Plugin / build-and-release (push) Successful in 5m26s
2026-11-08 01:10:55 +01:00
asminme 5d42b48c8b Fix hex rank prefixes in player list
Build Plugin / build-and-release (push) Successful in 5m37s
2026-11-08 00:34:18 +01:00
@@ -60,6 +60,8 @@ import com.sun.net.httpserver.HttpServer;
public final class AsminDiscordBridge extends JavaPlugin { public final class AsminDiscordBridge extends JavaPlugin {
private static final Pattern LEGACY_COLOR = Pattern.compile("(?i)§[0-9A-FK-OR]"); private static final Pattern LEGACY_COLOR = Pattern.compile("(?i)§[0-9A-FK-OR]");
private static final Pattern HEX_COLOR = Pattern.compile("(?i)&#[0-9A-F]{6}");
private static final Pattern ANSI_COLOR = Pattern.compile("(?:\\u001B\\[|\\[)[0-9;]*m");
private JDA jda; private JDA jda;
private LuckPerms luckPerms; private LuckPerms luckPerms;
@@ -278,7 +280,7 @@ public final class AsminDiscordBridge extends JavaPlugin {
} }
private void openKickModal(StringSelectInteractionEvent event, String playerName) { private void openKickModal(StringSelectInteractionEvent event, String playerName) {
TextInput reason = TextInput.create("reason", "Powód", TextInputStyle.SHORT) TextInput reason = TextInput.create("reason", "Wpisz powód kicka", TextInputStyle.SHORT)
.setPlaceholder("Podaj powód kicka") .setPlaceholder("Podaj powód kicka")
.setRequired(true) .setRequired(true)
.setMaxLength(200) .setMaxLength(200)
@@ -289,18 +291,18 @@ public final class AsminDiscordBridge extends JavaPlugin {
} }
private void openBanModal(StringSelectInteractionEvent event, String playerName) { private void openBanModal(StringSelectInteractionEvent event, String playerName) {
TextInput reason = TextInput.create("reason", "Powód", TextInputStyle.SHORT) TextInput reason = TextInput.create("reason", "Wpisz powód bana", TextInputStyle.SHORT)
.setPlaceholder("Podaj powód bana") .setPlaceholder("Podaj powód bana")
.setRequired(true) .setRequired(true)
.setMaxLength(200) .setMaxLength(200)
.build(); .build();
TextInput banIp = TextInput.create("ban-ip", "Ban IP? (tak/nie)", TextInputStyle.SHORT) TextInput banIp = TextInput.create("ban-ip", "Czy chcesz też bana na IP? (tak/nie)", TextInputStyle.SHORT)
.setPlaceholder("tak lub nie") .setPlaceholder("tak lub nie")
.setRequired(true) .setRequired(true)
.setMaxLength(3) .setMaxLength(3)
.build(); .build();
event.replyModal(Modal.create("admin:ban-modal:" + playerName, "Ban Player: " + playerName) event.replyModal(Modal.create("admin:ban-modal:" + playerName, "Ban Player: " + playerName)
.addComponents(ActionRow.of(reason, banIp)) .addComponents(ActionRow.of(reason), ActionRow.of(banIp))
.build()).queue(); .build()).queue();
} }
@@ -498,9 +500,11 @@ public final class AsminDiscordBridge extends JavaPlugin {
} }
private String formatPrefix(String prefix) { private String formatPrefix(String prefix) {
String translated = ChatColor.translateAlternateColorCodes('&', prefix); if (prefix == null) return "";
String plain = ChatColor.stripColor(translated); String translated = HEX_COLOR.matcher(prefix).replaceAll("");
if (plain == null || plain.isEmpty()) return ""; translated = ChatColor.translateAlternateColorCodes('&', translated);
String plain = ChatColor.stripColor(translated).trim();
if (plain.isEmpty()) return "";
return LEGACY_COLOR.matcher(translated).find() && translated.matches("(?s).*§[lL].*") return LEGACY_COLOR.matcher(translated).find() && translated.matches("(?s).*§[lL].*")
? "**" + plain + "** " : plain + " "; ? "**" + plain + "** " : plain + " ";
} }
@@ -675,7 +679,9 @@ public final class AsminDiscordBridge extends JavaPlugin {
public void append(LogEvent event) { public void append(LogEvent event) {
String message = event.getMessage() == null ? null : event.getMessage().getFormattedMessage(); String message = event.getMessage() == null ? null : event.getMessage().getFormattedMessage();
if (message == null || message.isBlank()) return; if (message == null || message.isBlank()) return;
add(ChatColor.stripColor(message)); message = ANSI_COLOR.matcher(ChatColor.stripColor(message)).replaceAll("").trim();
if (message.isEmpty() || message.startsWith("CONSOLE issued server command:")) return;
add(message);
} }
private void add(String line) { private void add(String line) {