Dateien nach "src/main/java/net/viper/status/modules/globalchat" hochladen
This commit is contained in:
@@ -0,0 +1,635 @@
|
||||
package net.viper.status.modules.globalchat;
|
||||
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.cacheddata.CachedMetaData;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent.Action;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
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.event.EventHandler;
|
||||
import net.viper.status.module.Module;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
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.
|
||||
*/
|
||||
public class GlobalChatModule implements Module, Listener {
|
||||
|
||||
private static final String CHANNEL_CONTROL = "global:control";
|
||||
|
||||
private Plugin plugin;
|
||||
|
||||
private List<String> badWords = new ArrayList<>();
|
||||
private File logFolder;
|
||||
private boolean chatMuted = false;
|
||||
private boolean isChatEnabled = true; // Status ob der Chat aktiv ist
|
||||
|
||||
private final Map<UUID, Boolean> playerIsOp = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, UUID> lastSupportContact = new ConcurrentHashMap<>();
|
||||
private final Set<UUID> suppressJoinQuit = ConcurrentHashMap.newKeySet();
|
||||
private List<String> welcomeMessages = new ArrayList<>();
|
||||
private Map<String, String> serverDisplayNames = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "GlobalChatModule";
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
try {
|
||||
plugin.getProxy().registerChannel(CHANNEL_CONTROL);
|
||||
} catch (Throwable ignored) {
|
||||
plugin.getLogger().warning("Konnte Kanal " + CHANNEL_CONTROL + " nicht registrieren.");
|
||||
}
|
||||
|
||||
plugin.getProxy().getPluginManager().registerListener(plugin, this);
|
||||
|
||||
loadFilter();
|
||||
loadWelcomeMessages();
|
||||
|
||||
logFolder = new File(plugin.getDataFolder(), "logs");
|
||||
if (!logFolder.exists()) logFolder.mkdirs();
|
||||
cleanupOldLogs();
|
||||
|
||||
// Befehle registrieren
|
||||
plugin.getProxy().getPluginManager().registerCommand(plugin, new ReloadCommand());
|
||||
plugin.getProxy().getPluginManager().registerCommand(plugin, new MuteCommand());
|
||||
plugin.getProxy().getPluginManager().registerCommand(plugin, new SupportCommand());
|
||||
plugin.getProxy().getPluginManager().registerCommand(plugin, new ReplyCommand());
|
||||
plugin.getProxy().getPluginManager().registerCommand(plugin, new InfoCommand());
|
||||
|
||||
plugin.getLogger().info("§aGlobalChatModule aktiviert (Zensur, Logs, Mute, Support, CustomNames)!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(Plugin plugin) {
|
||||
plugin.getLogger().info("§cGlobalChatModule deaktiviert!");
|
||||
try {
|
||||
plugin.getProxy().unregisterChannel(CHANNEL_CONTROL);
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Konfiguration laden (Aktivierungsstatus & Namen aus verify.properties)
|
||||
// ===========================
|
||||
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);
|
||||
OutputStream out = new FileOutputStream(file)) {
|
||||
if (in == null) {
|
||||
plugin.getLogger().warning("Standard-config '" + fileName + "' nicht in JAR gefunden.");
|
||||
file.createNewFile();
|
||||
return;
|
||||
}
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
plugin.getLogger().info("Konfigurationsdatei '" + fileName + "' erstellt.");
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().severe("Fehler beim Erstellen der Standard-Konfiguration: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
serverDisplayNames.put(serverName, displayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
plugin.getLogger().info("§eGeladene Server-Displaynames: " + serverDisplayNames.size() + " (Chat aktiv: " + isChatEnabled + ")");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String getDisplayName(String serverName) {
|
||||
String displayName = serverDisplayNames.getOrDefault(serverName, serverName);
|
||||
return ChatColor.translateAlternateColorCodes('&', displayName);
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Willkommensnachrichten
|
||||
// ===========================
|
||||
private void loadWelcomeMessages() {
|
||||
String fileName = "welcome.yml";
|
||||
File file = new File(plugin.getDataFolder(), fileName);
|
||||
|
||||
if (!file.exists()) {
|
||||
plugin.getDataFolder().mkdirs();
|
||||
try (InputStream in = plugin.getResourceAsStream(fileName);
|
||||
OutputStream out = new FileOutputStream(file)) {
|
||||
if (in == null) {
|
||||
plugin.getLogger().warning("Standard 'welcome.yml' nicht in JAR gefunden.");
|
||||
file.createNewFile();
|
||||
return;
|
||||
}
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
plugin.getLogger().info("Standard welcome.yml erstellt.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> lines = Files.readAllLines(file.toPath());
|
||||
welcomeMessages.clear();
|
||||
for (String line : lines) {
|
||||
line = line.trim();
|
||||
if (line.startsWith("-")) welcomeMessages.add(line.substring(1).trim());
|
||||
}
|
||||
plugin.getLogger().info("§eGeladene Welcome-Nachrichten: " + welcomeMessages.size());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendRandomWelcomeMessage(ProxiedPlayer player) {
|
||||
if (welcomeMessages.isEmpty()) return;
|
||||
|
||||
Random rand = new Random();
|
||||
String message = welcomeMessages.get(rand.nextInt(welcomeMessages.size()));
|
||||
message = message.replace("%player%", player.getName());
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
|
||||
player.sendMessage(new TextComponent(message));
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Chatfilter & Global-Chat
|
||||
// ===========================
|
||||
@EventHandler
|
||||
public void onChat(ChatEvent e) {
|
||||
if (!(e.getSender() instanceof ProxiedPlayer)) return;
|
||||
if (e.isCommand()) return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) e.getSender();
|
||||
String originalMsg = e.getMessage();
|
||||
|
||||
if (suppressJoinQuit.contains(player.getUniqueId()) &&
|
||||
(originalMsg.contains("joined the Game") || originalMsg.contains("left the Game"))) {
|
||||
plugin.getLogger().info("Unterdrücke Join-/Quit-Nachricht für " + player.getName());
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Globaler Mute
|
||||
if (chatMuted && !player.hasPermission("globalchat.bypass")) {
|
||||
player.sendMessage(new TextComponent("§cDer globale Chat ist derzeit deaktiviert!"));
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Badword-Zensur
|
||||
String censoredMsg = originalMsg;
|
||||
for (String bad : badWords) {
|
||||
if (bad == null || bad.trim().isEmpty()) continue;
|
||||
censoredMsg = censoredMsg.replaceAll("(?i)" + Pattern.quote(bad), repeat("*", bad.length()));
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
String serverName = player.getServer().getInfo().getName();
|
||||
String serverDisplay = getDisplayName(serverName);
|
||||
|
||||
String[] ps = getPrefixSuffix(player);
|
||||
String prefix = ps[0] == null ? "" : ps[0].trim();
|
||||
String suffix = ps[1] == null ? "" : ps[1].trim();
|
||||
|
||||
String displayTag = "";
|
||||
if (!prefix.isEmpty()) {
|
||||
displayTag = prefix;
|
||||
} else if (!suffix.isEmpty()) {
|
||||
displayTag = suffix;
|
||||
}
|
||||
|
||||
if (!displayTag.isEmpty() && !displayTag.endsWith(" ")) displayTag = displayTag + " ";
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
out.append("§7[").append(serverDisplay).append("] ");
|
||||
if (!displayTag.isEmpty()) out.append(displayTag);
|
||||
out.append(player.getName());
|
||||
out.append("§f: ").append(censoredMsg);
|
||||
|
||||
String chatOut = out.toString();
|
||||
|
||||
for (ProxiedPlayer p : plugin.getProxy().getPlayers()) {
|
||||
p.sendMessage(new TextComponent(chatOut));
|
||||
}
|
||||
|
||||
// Log unzensiert (Originalnamen für saubere Logs)
|
||||
String logEntry = "[" + serverName + "] " +
|
||||
(displayTag.isEmpty() ? "" : stripColor(displayTag) + " ") +
|
||||
player.getName() +
|
||||
": " + originalMsg;
|
||||
logMessage(logEntry);
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Server Connect & Switch
|
||||
// ===========================
|
||||
@EventHandler
|
||||
public void onServerConnect(ServerConnectEvent e) {
|
||||
if (e.isCancelled()) return;
|
||||
|
||||
ProxiedPlayer player = e.getPlayer();
|
||||
ServerInfo target = e.getTarget();
|
||||
ServerInfo from = player.getServer() != null ? player.getServer().getInfo() : null;
|
||||
|
||||
if (from == null || from.equals(target)) return;
|
||||
|
||||
suppressJoinQuit.add(player.getUniqueId());
|
||||
plugin.getLogger().info("Markiert " + player.getName() + " für Join-/Quit-Unterdrückung");
|
||||
|
||||
try {
|
||||
sendSuppressJoinQuit(from, player.getUniqueId());
|
||||
plugin.getLogger().info("Sent suppress quit message for " + player.getName() + " to server " + from.getName());
|
||||
} catch (Throwable ex) {
|
||||
plugin.getLogger().warning("Fehler beim Senden der Quit-Unterdrückung: " + ex.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
sendSuppressJoinQuit(target, player.getUniqueId());
|
||||
plugin.getLogger().info("Sent suppress join message for " + player.getName() + " to server " + target.getName());
|
||||
} catch (Throwable ex) {
|
||||
plugin.getLogger().warning("Fehler beim Senden der Join-Unterdrückung: " + ex.getMessage());
|
||||
}
|
||||
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
suppressJoinQuit.remove(player.getUniqueId());
|
||||
plugin.getLogger().info("Entfernte Unterdrückung für " + player.getName());
|
||||
}, 2, java.util.concurrent.TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerSwitch(ServerSwitchEvent e) {
|
||||
ProxiedPlayer player = e.getPlayer();
|
||||
ServerInfo from = e.getFrom();
|
||||
ServerInfo to = player.getServer() != null ? player.getServer().getInfo() : null;
|
||||
|
||||
if (to == null || from == null) return;
|
||||
if (from.getName().equalsIgnoreCase(to.getName())) return;
|
||||
|
||||
String fromName = from.getName();
|
||||
String fromDisplay = getDisplayName(fromName);
|
||||
|
||||
String toName = to.getName();
|
||||
String toDisplay = getDisplayName(toName);
|
||||
|
||||
String[] ps = getPrefixSuffix(player);
|
||||
String prefix = ps[0] == null ? "" : ps[0].trim();
|
||||
String suffix = ps[1] == null ? "" : ps[1].trim();
|
||||
|
||||
String displayTag = "";
|
||||
if (!prefix.isEmpty()) displayTag = prefix;
|
||||
else if (!suffix.isEmpty()) displayTag = suffix;
|
||||
|
||||
if (!displayTag.isEmpty() && !displayTag.endsWith(" ")) displayTag = displayTag + " ";
|
||||
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("§7[").append(toDisplay).append("] ");
|
||||
if (!displayTag.isEmpty()) msg.append(displayTag);
|
||||
msg.append(player.getName());
|
||||
msg.append(" §7hat den Server gewechselt: §e")
|
||||
.append(fromDisplay).append(" §7→ §e").append(toDisplay).append("§7.");
|
||||
|
||||
String finalMsg = msg.toString();
|
||||
|
||||
for (ProxiedPlayer p : plugin.getProxy().getPlayers()) {
|
||||
p.sendMessage(new TextComponent(finalMsg));
|
||||
}
|
||||
|
||||
// Log unzensiert (Originalnamen)
|
||||
String logEntry = "[" + toName + "] " +
|
||||
(displayTag.isEmpty() ? "" : stripColor(displayTag) + " ") +
|
||||
player.getName() + " hat den Server gewechselt: " + fromName + " -> " + toName + ".";
|
||||
logMessage(logEntry);
|
||||
}
|
||||
|
||||
private void sendSuppressJoinQuit(ServerInfo server, UUID playerId) {
|
||||
if (server == null) return;
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(baos)) {
|
||||
out.writeUTF("suppress");
|
||||
out.writeUTF(playerId.toString());
|
||||
server.sendData(CHANNEL_CONTROL, baos.toByteArray());
|
||||
} catch (IOException ex) {
|
||||
plugin.getLogger().warning("Fehler beim Senden der suppress-Nachricht: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String repeat(String str, int count) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < count; i++) sb.append(str);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Prefix/Suffix via LuckPerms
|
||||
// ===========================
|
||||
private String[] getPrefixSuffix(ProxiedPlayer player) {
|
||||
String prefix = "";
|
||||
String suffix = "";
|
||||
|
||||
try {
|
||||
LuckPerms lp = LuckPermsProvider.get();
|
||||
if (lp != null) {
|
||||
User user = lp.getUserManager().getUser(player.getUniqueId());
|
||||
|
||||
if (user == null) {
|
||||
try {
|
||||
user = lp.getUserManager().loadUser(player.getUniqueId()).join();
|
||||
} catch (Exception ignored) {
|
||||
user = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (user != null) {
|
||||
CachedMetaData meta = user.getCachedData().getMetaData();
|
||||
if (meta != null) {
|
||||
String p = meta.getPrefix();
|
||||
String s = meta.getSuffix();
|
||||
if (p != null) prefix = p;
|
||||
if (s != null) suffix = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
// Kein LuckPerms oder Fehler
|
||||
}
|
||||
|
||||
if (prefix != null && !prefix.isEmpty()) prefix = ChatColor.translateAlternateColorCodes('&', prefix);
|
||||
if (suffix != null && !suffix.isEmpty()) suffix = ChatColor.translateAlternateColorCodes('&', suffix);
|
||||
|
||||
if (prefix == null) prefix = "";
|
||||
if (suffix == null) suffix = "";
|
||||
|
||||
return new String[]{prefix, suffix};
|
||||
}
|
||||
|
||||
private String stripColor(String s) {
|
||||
if (s == null) return "";
|
||||
return ChatColor.stripColor(s);
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Filter einlesen
|
||||
// ===========================
|
||||
private void loadFilter() {
|
||||
String fileName = "filter.yml";
|
||||
File file = new File(plugin.getDataFolder(), fileName);
|
||||
|
||||
if (!file.exists()) {
|
||||
plugin.getDataFolder().mkdirs();
|
||||
try (InputStream in = plugin.getResourceAsStream(fileName);
|
||||
OutputStream out = new FileOutputStream(file)) {
|
||||
if (in == null) {
|
||||
plugin.getLogger().warning("Standard 'filter.yml' nicht in JAR gefunden.");
|
||||
file.createNewFile();
|
||||
return;
|
||||
}
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
plugin.getLogger().info("Standard filter.yml erstellt.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> lines = Files.readAllLines(file.toPath());
|
||||
badWords.clear();
|
||||
for (String line : lines) {
|
||||
line = line.trim();
|
||||
if (line.startsWith("-")) badWords.add(line.substring(1).trim());
|
||||
}
|
||||
plugin.getLogger().info("§eGeladene Filter-Wörter: " + badWords.size());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Logs aufräumen / schreiben
|
||||
// ===========================
|
||||
private void cleanupOldLogs() {
|
||||
File[] files = logFolder.listFiles();
|
||||
if (files == null) return;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long sevenDays = 1000L * 60 * 60 * 24 * 7;
|
||||
|
||||
for (File f : files) {
|
||||
if (now - f.lastModified() > sevenDays) {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void logMessage(String message) {
|
||||
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
File logFile = new File(logFolder, date + ".log");
|
||||
|
||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(logFile, true))) {
|
||||
String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
|
||||
bw.write("[" + time + "] " + message);
|
||||
bw.newLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Staff-Check
|
||||
// ===========================
|
||||
private boolean isStaff(ProxiedPlayer p) {
|
||||
if (p == null) return false;
|
||||
Boolean reportedOp = playerIsOp.get(p.getUniqueId());
|
||||
if (reportedOp != null && reportedOp) return true;
|
||||
|
||||
if (p.hasPermission("team")) return true;
|
||||
if (p.hasPermission("bungeecord.admin")) return true;
|
||||
if (p.hasPermission("globalchat.op")) return true;
|
||||
if (p.hasPermission("*")) return true;
|
||||
|
||||
if (p.hasPermission("bungeecord.command.alert")) return true;
|
||||
if (p.hasPermission("bungeecord.command.reload")) return true;
|
||||
if (p.hasPermission("bungeecord.command.kick")) return true;
|
||||
if (p.hasPermission("bungeecord.command.send")) return true;
|
||||
if (p.hasPermission("bungeecord.command.perms")) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Commands (Inner Classes)
|
||||
// ===========================
|
||||
public class ReloadCommand extends Command {
|
||||
public ReloadCommand() { super("globalreload", "globalchat.reload"); }
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
loadFilter();
|
||||
loadConfig(); // Konfiguration neu laden
|
||||
sender.sendMessage(new TextComponent("§aFilter und Chat-Konfiguration wurden neu geladen!"));
|
||||
}
|
||||
}
|
||||
|
||||
public class MuteCommand extends Command {
|
||||
public MuteCommand() { super("globalmute", "globalchat.mute"); }
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
chatMuted = !chatMuted;
|
||||
String status = chatMuted ? "§caktiviert" : "§aaufgehoben";
|
||||
for (ProxiedPlayer p : plugin.getProxy().getPlayers()) {
|
||||
p.sendMessage(new TextComponent("§7[GlobalChat] §eDer globale Chat Mute wurde " + status + "§e!"));
|
||||
}
|
||||
plugin.getLogger().info("GlobalMute wurde " + (chatMuted ? "aktiviert" : "deaktiviert") + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public class SupportCommand extends Command {
|
||||
public SupportCommand() { super("support"); }
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof ProxiedPlayer)) {
|
||||
sender.sendMessage(new TextComponent("§cNur Spieler können Support-Nachrichten senden."));
|
||||
return;
|
||||
}
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(new TextComponent("§cBitte eine Nachricht angeben: /support <Nachricht>"));
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = String.join(" ", args);
|
||||
|
||||
// WICHTIG: Server Name umwandeln in Display Name
|
||||
String serverRaw = player.getServer().getInfo().getName();
|
||||
String serverDisplay = getDisplayName(serverRaw);
|
||||
|
||||
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() + " "));
|
||||
|
||||
for (ProxiedPlayer p : plugin.getProxy().getPlayers()) {
|
||||
if (isStaff(p)) {
|
||||
p.sendMessage(supportMsg);
|
||||
lastSupportContact.put(p.getUniqueId(), player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(new TextComponent("§aDeine Support-Nachricht wurde gesendet."));
|
||||
logMessage("[Support][" + serverRaw + "] " + player.getName() + ": " + msg);
|
||||
}
|
||||
}
|
||||
|
||||
public class ReplyCommand extends Command {
|
||||
public ReplyCommand() { super("reply"); }
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof ProxiedPlayer)) return;
|
||||
|
||||
ProxiedPlayer staff = (ProxiedPlayer) sender;
|
||||
UUID targetId = lastSupportContact.get(staff.getUniqueId());
|
||||
if (targetId == null) {
|
||||
staff.sendMessage(new TextComponent("§cKein Spieler zum Antworten gefunden."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
staff.sendMessage(new TextComponent("§cBitte eine Nachricht angeben."));
|
||||
return;
|
||||
}
|
||||
|
||||
ProxiedPlayer target = plugin.getProxy().getPlayer(targetId);
|
||||
if (target == null) {
|
||||
staff.sendMessage(new TextComponent("§cSpieler ist nicht online."));
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = String.join(" ", args);
|
||||
target.sendMessage(new TextComponent("§7[Reply von §b" + staff.getName() + "§7]: §f" + msg));
|
||||
staff.sendMessage(new TextComponent("§aDeine Nachricht wurde an §b" + target.getName() + "§a gesendet."));
|
||||
}
|
||||
}
|
||||
|
||||
public class InfoCommand extends Command {
|
||||
public InfoCommand() { super("info"); }
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
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("§eErsteller: §bM_Viper"));
|
||||
sender.sendMessage(new TextComponent("§8§m------------------------------"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user