From 47557d7bb812986d97d991b9178f53f06dcdef9d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 16 Oct 2026 11:17:10 +0200 Subject: [PATCH] Keep global chat readable after writing into it on fight servers Writing /global on a fight server shows the global chat until the player leaves the server or runs /chat global leave, without changing the default channel. --- .../steamwar/messages/BungeeCore.properties | 1 + .../messages/BungeeCore_de.properties | 1 + .../velocitycore/chat/ChatManager.java | 25 ++++++++++++++++++- .../velocitycore/commands/GlobalCommand.java | 4 +++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index dc41683f..4f988ef1 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -621,6 +621,7 @@ CHAT_MSG_USAGE = §8/§7chat §8[§echannel§8] §7msg §8[§emessage§8] CHAT_ARENAS_USAGE = §8/§7chat §7arenas §8[§ejoin§8|§eleave§8] CHAT_ARENAS_JOINED = §7You now read the chats of all fights. CHAT_ARENAS_LEFT = §7You no longer read the chats of all fights. +CHAT_GLOBAL_AFTER_WRITING = §7You read §e{0} §7on this server until you leave it. CHAT_CHANNEL_UNKNOWN = §cUnknown chat channel. CHAT_CHANNEL_JOINED = §7You are reading §e{0} §7again. CHAT_CHANNEL_LEFT = §7You no longer read §e{0}§7. diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index b0c70a21..d352cdf3 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -586,6 +586,7 @@ CHAT_MSG_USAGE = §8/§7chat §8[§eKanal§8] §7msg §8[§eNachricht§8] CHAT_ARENAS_USAGE = §8/§7chat §7arenas §8[§ejoin§8|§eleave§8] CHAT_ARENAS_JOINED = §7Du liest jetzt die Chats aller Fights mit. CHAT_ARENAS_LEFT = §7Du liest die Chats aller Fights nicht mehr mit. +CHAT_GLOBAL_AFTER_WRITING = §7Du liest §e{0} §7auf diesem Server mit, bis du ihn verlässt. CHAT_CHANNEL_UNKNOWN = §cUnbekannter Chatkanal. CHAT_CHANNEL_JOINED = §7Du liest §e{0} §7wieder mit. CHAT_CHANNEL_LEFT = §7Du liest §e{0} §7nicht mehr mit. diff --git a/VelocityCore/src/de/steamwar/velocitycore/chat/ChatManager.java b/VelocityCore/src/de/steamwar/velocitycore/chat/ChatManager.java index 76d75844..753ef201 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/chat/ChatManager.java +++ b/VelocityCore/src/de/steamwar/velocitycore/chat/ChatManager.java @@ -75,6 +75,8 @@ public class ChatManager extends BasicListener { private static final Map defaults = new ConcurrentHashMap<>(); private static final Map persisted = new ConcurrentHashMap<>(); private static final Set globalOnArena = ConcurrentHashMap.newKeySet(); + // Players who wrote into the global chat on their current fight server and read it until they leave the server + private static final Set globalAfterWriting = ConcurrentHashMap.newKeySet(); private static final Set announced = ConcurrentHashMap.newKeySet(); private static final Map> spies = new ConcurrentHashMap<>(); private static final Map allArenas = new ConcurrentHashMap<>(); @@ -159,7 +161,20 @@ public class ChatManager extends BasicListener { } static boolean readsGlobal(Player player) { - return !currentServer(player).map(ChatManager::isArena).orElse(false) || globalOnArena.contains(player.getUniqueId()); + UUID uuid = player.getUniqueId(); + return !currentServer(player).map(ChatManager::isArena).orElse(false) || globalOnArena.contains(uuid) || globalAfterWriting.contains(uuid); + } + + /** + * Shows the global chat to a player who wrote into it on a fight server until they leave the server. + */ + public static void readGlobalAfterWriting(PlayerChatter player) { + if (!currentServer(player.getPlayer()).map(ChatManager::isArena).orElse(false)) return; + if (!reads(player, global.persistId())) return; + + if (globalAfterWriting.add(player.user().getUUID())) { + player.system("CHAT_GLOBAL_AFTER_WRITING", global.tag(player)); + } } /** @@ -283,6 +298,12 @@ public class ChatManager extends BasicListener { return; } + // Leaving the global chat read after writing into it only ends that, it does not leave the global chat everywhere + if (channel == global && globalAfterWriting.remove(uuid)) { + player.system("CHAT_CHANNEL_LEFT", channel.tag(player)); + return; + } + if (hidden(uuid).add(id)) { saveHidden(uuid); } @@ -457,6 +478,7 @@ public class ChatManager extends BasicListener { UUID uuid = player.getUniqueId(); globalOnArena.remove(uuid); + globalAfterWriting.remove(uuid); ChatChannel current = defaults.get(uuid); ChatChannel next; @@ -477,6 +499,7 @@ public class ChatManager extends BasicListener { defaults.remove(uuid); persisted.remove(uuid); globalOnArena.remove(uuid); + globalAfterWriting.remove(uuid); announced.remove(uuid); spies.remove(uuid); allArenas.remove(uuid); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/GlobalCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/GlobalCommand.java index 489fa83b..96f7eb2b 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/GlobalCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/GlobalCommand.java @@ -23,6 +23,7 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.velocitycore.chat.ChatManager; @Linked @@ -35,5 +36,8 @@ public class GlobalCommand extends SWCommand { @Register(description = "GLOBAL_USAGE") public void genericCommand(Chatter sender, String... message) { ChatManager.sendOrSwitch(sender, ChatManager.getGlobal(), message, "GLOBAL_USAGE"); + if (message.length > 0 && sender instanceof PlayerChatter player) { + ChatManager.readGlobalAfterWriting(player); + } } }