|
|
|
|
@@ -18,10 +18,12 @@ import net.md_5.bungee.api.event.ServerSwitchEvent;
|
|
|
|
|
import net.md_5.bungee.api.plugin.Command;
|
|
|
|
|
import net.md_5.bungee.api.plugin.Listener;
|
|
|
|
|
import net.md_5.bungee.api.plugin.Plugin;
|
|
|
|
|
import net.md_5.bungee.chat.ComponentSerializer; // Wichtig für JSON
|
|
|
|
|
import net.md_5.bungee.event.EventHandler;
|
|
|
|
|
import net.viper.status.module.Module;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
@@ -31,10 +33,12 @@ import java.util.regex.Pattern;
|
|
|
|
|
/**
|
|
|
|
|
* GlobalChatModule - Integriert Global Chat, Filter, Logs und Support in die StatusAPI.
|
|
|
|
|
* Nutzt die zentrale verify.properties für Chat- und Server-Einstellungen.
|
|
|
|
|
* Sendet Nachrichten via Plugin Channel an Backend-Server, um Signatur-Probleme zu vermeiden.
|
|
|
|
|
*/
|
|
|
|
|
public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
|
|
|
|
|
private static final String CHANNEL_CONTROL = "global:control";
|
|
|
|
|
private static final String CHANNEL_CHAT = "global:chat"; // NEU: Kanal für Chat-Relay
|
|
|
|
|
|
|
|
|
|
private Plugin plugin;
|
|
|
|
|
|
|
|
|
|
@@ -46,6 +50,8 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
private final Map<UUID, Boolean> playerIsOp = new ConcurrentHashMap<>();
|
|
|
|
|
private final Map<UUID, UUID> lastSupportContact = new ConcurrentHashMap<>();
|
|
|
|
|
private final Set<UUID> suppressJoinQuit = ConcurrentHashMap.newKeySet();
|
|
|
|
|
private final Set<UUID> chatLockPlayers = ConcurrentHashMap.newKeySet(); // Toggle Chat List
|
|
|
|
|
|
|
|
|
|
private List<String> welcomeMessages = new ArrayList<>();
|
|
|
|
|
private Map<String, String> serverDisplayNames = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
@@ -58,21 +64,19 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
public void onEnable(Plugin plugin) {
|
|
|
|
|
this.plugin = plugin;
|
|
|
|
|
|
|
|
|
|
// Konfigurationen laden (Zuerst prüfen wir, ob der Chat überhaupt aktiv ist)
|
|
|
|
|
loadConfig();
|
|
|
|
|
|
|
|
|
|
// WICHTIG: Wenn der Chat deaktiviert ist, machen wir sofort gar nichts mehr.
|
|
|
|
|
// Keine Listener, keine Commands, keine Logs. Andere Plugins können ungestört laufen.
|
|
|
|
|
if (!isChatEnabled) {
|
|
|
|
|
plugin.getLogger().info("§eGlobalChat ist in der verify.properties DEAKTIVIERT.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Plugin channel registrieren
|
|
|
|
|
// Channels registrieren
|
|
|
|
|
try {
|
|
|
|
|
plugin.getProxy().registerChannel(CHANNEL_CONTROL);
|
|
|
|
|
plugin.getProxy().registerChannel(CHANNEL_CHAT);
|
|
|
|
|
} catch (Throwable ignored) {
|
|
|
|
|
plugin.getLogger().warning("Konnte Kanal " + CHANNEL_CONTROL + " nicht registrieren.");
|
|
|
|
|
plugin.getLogger().warning("Konnte Channels nicht registrieren.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plugin.getProxy().getPluginManager().registerListener(plugin, this);
|
|
|
|
|
@@ -90,8 +94,9 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
plugin.getProxy().getPluginManager().registerCommand(plugin, new SupportCommand());
|
|
|
|
|
plugin.getProxy().getPluginManager().registerCommand(plugin, new ReplyCommand());
|
|
|
|
|
plugin.getProxy().getPluginManager().registerCommand(plugin, new InfoCommand());
|
|
|
|
|
plugin.getProxy().getPluginManager().registerCommand(plugin, new ChatToggleCommand());
|
|
|
|
|
|
|
|
|
|
plugin.getLogger().info("§aGlobalChatModule aktiviert (Zensur, Logs, Mute, Support, CustomNames)!");
|
|
|
|
|
plugin.getLogger().info("§aGlobalChatModule aktiviert (Relay-Mode aktiv)!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@@ -99,18 +104,17 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
plugin.getLogger().info("§cGlobalChatModule deaktiviert!");
|
|
|
|
|
try {
|
|
|
|
|
plugin.getProxy().unregisterChannel(CHANNEL_CONTROL);
|
|
|
|
|
plugin.getProxy().unregisterChannel(CHANNEL_CHAT);
|
|
|
|
|
} catch (Throwable ignored) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================
|
|
|
|
|
// Konfiguration laden (Aktivierungsstatus & Namen aus verify.properties)
|
|
|
|
|
// Konfiguration laden
|
|
|
|
|
// ===========================
|
|
|
|
|
private void loadConfig() {
|
|
|
|
|
// ÄNDERUNG: Wir lesen jetzt die 'verify.properties'
|
|
|
|
|
String fileName = "verify.properties";
|
|
|
|
|
File file = new File(plugin.getDataFolder(), fileName);
|
|
|
|
|
|
|
|
|
|
// Datei aus Ressourcen kopieren, falls nicht vorhanden
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
plugin.getDataFolder().mkdirs();
|
|
|
|
|
try (InputStream in = plugin.getResourceAsStream(fileName);
|
|
|
|
|
@@ -132,23 +136,18 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Einlesen
|
|
|
|
|
try {
|
|
|
|
|
Properties props = new Properties();
|
|
|
|
|
try (InputStream in = new FileInputStream(file)) {
|
|
|
|
|
props.load(in);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Aktivierung prüfen
|
|
|
|
|
isChatEnabled = Boolean.parseBoolean(props.getProperty("chat.enabled", "true"));
|
|
|
|
|
|
|
|
|
|
serverDisplayNames.clear();
|
|
|
|
|
for (String key : props.stringPropertyNames()) {
|
|
|
|
|
if (key.startsWith("server.")) {
|
|
|
|
|
String[] parts = key.split("\\.");
|
|
|
|
|
|
|
|
|
|
// WICHTIG: Wir ignorieren Keys mit Unterpunkten (z.B. server.lobby.id oder .secret)
|
|
|
|
|
// Wir wollen nur Keys wie "server.lobby" (parts.length == 2)
|
|
|
|
|
if (parts.length == 2) {
|
|
|
|
|
String serverName = parts[1];
|
|
|
|
|
String displayName = props.getProperty(key);
|
|
|
|
|
@@ -219,7 +218,7 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===========================
|
|
|
|
|
// Chatfilter & Global-Chat
|
|
|
|
|
// Chatfilter & Global-Chat (RELAY MODE)
|
|
|
|
|
// ===========================
|
|
|
|
|
@EventHandler
|
|
|
|
|
public void onChat(ChatEvent e) {
|
|
|
|
|
@@ -227,6 +226,13 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
if (e.isCommand()) return;
|
|
|
|
|
|
|
|
|
|
ProxiedPlayer player = (ProxiedPlayer) e.getSender();
|
|
|
|
|
|
|
|
|
|
// ==================== CHAT LOCK / TOGGLE CHECK ====================
|
|
|
|
|
if (chatLockPlayers.contains(player.getUniqueId())) {
|
|
|
|
|
return; // Nachricht geht direkt zum Server (z.B. für Lands/Quests)
|
|
|
|
|
}
|
|
|
|
|
// ========================================================================
|
|
|
|
|
|
|
|
|
|
String originalMsg = e.getMessage();
|
|
|
|
|
|
|
|
|
|
if (suppressJoinQuit.contains(player.getUniqueId()) &&
|
|
|
|
|
@@ -250,6 +256,7 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
censoredMsg = censoredMsg.replaceAll("(?i)" + Pattern.quote(bad), repeat("*", bad.length()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Event canceln (Wichtig, damit nicht doppelt angezeigt wird)
|
|
|
|
|
e.setCancelled(true);
|
|
|
|
|
|
|
|
|
|
String serverName = player.getServer().getInfo().getName();
|
|
|
|
|
@@ -276,11 +283,22 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
|
|
|
|
|
String chatOut = out.toString();
|
|
|
|
|
|
|
|
|
|
for (ProxiedPlayer p : plugin.getProxy().getPlayers()) {
|
|
|
|
|
p.sendMessage(new TextComponent(chatOut));
|
|
|
|
|
// NEU: Nachricht erstellen und an alle Server senden
|
|
|
|
|
TextComponent chatComponent = new TextComponent(chatOut);
|
|
|
|
|
String jsonMessage = ComponentSerializer.toString(chatComponent);
|
|
|
|
|
|
|
|
|
|
for (ServerInfo server : plugin.getProxy().getServers().values()) {
|
|
|
|
|
// Wir senden nur an Server, die Spieler haben (Performance)
|
|
|
|
|
if (server.getPlayers().isEmpty()) continue;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
server.sendData(CHANNEL_CHAT, jsonMessage.getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
plugin.getLogger().warning("Konnte Chat-Nachricht nicht an Server " + server.getName() + " senden.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Log unzensiert (Originalnamen für saubere Logs)
|
|
|
|
|
// Loggen (lokal auf Bungee)
|
|
|
|
|
String logEntry = "[" + serverName + "] " +
|
|
|
|
|
(displayTag.isEmpty() ? "" : stripColor(displayTag) + " ") +
|
|
|
|
|
player.getName() +
|
|
|
|
|
@@ -358,11 +376,19 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
|
|
|
|
|
String finalMsg = msg.toString();
|
|
|
|
|
|
|
|
|
|
for (ProxiedPlayer p : plugin.getProxy().getPlayers()) {
|
|
|
|
|
p.sendMessage(new TextComponent(finalMsg));
|
|
|
|
|
// NEU: Switch Nachricht auch über Relay senden
|
|
|
|
|
TextComponent switchComponent = new TextComponent(finalMsg);
|
|
|
|
|
String jsonMessage = ComponentSerializer.toString(switchComponent);
|
|
|
|
|
|
|
|
|
|
for (ServerInfo server : plugin.getProxy().getServers().values()) {
|
|
|
|
|
if (server.getPlayers().isEmpty()) continue;
|
|
|
|
|
try {
|
|
|
|
|
server.sendData(CHANNEL_CHAT, jsonMessage.getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
plugin.getLogger().warning("Konnte Switch-Nachricht nicht senden.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Log unzensiert (Originalnamen)
|
|
|
|
|
String logEntry = "[" + toName + "] " +
|
|
|
|
|
(displayTag.isEmpty() ? "" : stripColor(displayTag) + " ") +
|
|
|
|
|
player.getName() + " hat den Server gewechselt: " + fromName + " -> " + toName + ".";
|
|
|
|
|
@@ -418,7 +444,6 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Throwable ignored) {
|
|
|
|
|
// Kein LuckPerms oder Fehler
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prefix != null && !prefix.isEmpty()) prefix = ChatColor.translateAlternateColorCodes('&', prefix);
|
|
|
|
|
@@ -535,7 +560,7 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
@Override
|
|
|
|
|
public void execute(CommandSender sender, String[] args) {
|
|
|
|
|
loadFilter();
|
|
|
|
|
loadConfig(); // Konfiguration neu laden
|
|
|
|
|
loadConfig();
|
|
|
|
|
sender.sendMessage(new TextComponent("§aFilter und Chat-Konfiguration wurden neu geladen!"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -569,11 +594,10 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String msg = String.join(" ", args);
|
|
|
|
|
|
|
|
|
|
// WICHTIG: Server Name umwandeln in Display Name
|
|
|
|
|
String serverRaw = player.getServer().getInfo().getName();
|
|
|
|
|
String serverDisplay = getDisplayName(serverRaw);
|
|
|
|
|
|
|
|
|
|
// Support-Nachricht geht nur ans Team, nicht über den Global Chat Relay
|
|
|
|
|
TextComponent supportMsg = new TextComponent("§7[Support] §b" + player.getName() + " §7vom Server §e" + serverDisplay + " §7: §f" + msg);
|
|
|
|
|
supportMsg.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder("Klicke, um /reply " + player.getName() + " zu schreiben").create()));
|
|
|
|
|
supportMsg.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.SUGGEST_COMMAND, "/reply " + player.getName() + " "));
|
|
|
|
|
@@ -627,9 +651,35 @@ public class GlobalChatModule implements Module, Listener {
|
|
|
|
|
sender.sendMessage(new TextComponent("§8§m------------------------------"));
|
|
|
|
|
sender.sendMessage(new TextComponent("§6§lGlobalChat Info"));
|
|
|
|
|
sender.sendMessage(new TextComponent("§ePlugin-Name: §bStatusAPI (GlobalChat Module)"));
|
|
|
|
|
sender.sendMessage(new TextComponent("§eVersion: §b1.4"));
|
|
|
|
|
sender.sendMessage(new TextComponent("§eVersion: §b2.0 (Relay)"));
|
|
|
|
|
sender.sendMessage(new TextComponent("§eErsteller: §bM_Viper"));
|
|
|
|
|
sender.sendMessage(new TextComponent("§8§m------------------------------"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ChatToggleCommand extends Command {
|
|
|
|
|
public ChatToggleCommand() { super("togglechat"); }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void execute(CommandSender sender, String[] args) {
|
|
|
|
|
if (!(sender instanceof ProxiedPlayer)) {
|
|
|
|
|
sender.sendMessage(new TextComponent("§cNur Spieler können den Chat-Modus ändern."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProxiedPlayer player = (ProxiedPlayer) sender;
|
|
|
|
|
UUID uuid = player.getUniqueId();
|
|
|
|
|
|
|
|
|
|
if (chatLockPlayers.contains(uuid)) {
|
|
|
|
|
chatLockPlayers.remove(uuid);
|
|
|
|
|
player.sendMessage(new TextComponent("§aGlobalChat aktiviert."));
|
|
|
|
|
player.sendMessage(new TextComponent("§7Deine Nachrichten werden nun wieder global gesendet."));
|
|
|
|
|
} else {
|
|
|
|
|
chatLockPlayers.add(uuid);
|
|
|
|
|
player.sendMessage(new TextComponent("§cGlobalChat deaktiviert."));
|
|
|
|
|
player.sendMessage(new TextComponent("§7Deine Nachrichten gehen nur noch an den Server (z.B. für Lands oder Quests)."));
|
|
|
|
|
player.sendMessage(new TextComponent("§7Nutze erneut /togglechat, um den globalen Chat zu aktivieren."));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|