forked from SteamWar/SteamWar
Keep global chat readable after writing into it on fight servers
Writing /global <text> on a fight server shows the global chat until the player leaves the server or runs /chat global leave, without changing the default channel.
This commit is contained in:
@@ -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_USAGE = §8/§7chat §7arenas §8[§ejoin§8|§eleave§8]
|
||||||
CHAT_ARENAS_JOINED = §7You now read the chats of all fights.
|
CHAT_ARENAS_JOINED = §7You now read the chats of all fights.
|
||||||
CHAT_ARENAS_LEFT = §7You no longer 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_UNKNOWN = §cUnknown chat channel.
|
||||||
CHAT_CHANNEL_JOINED = §7You are reading §e{0} §7again.
|
CHAT_CHANNEL_JOINED = §7You are reading §e{0} §7again.
|
||||||
CHAT_CHANNEL_LEFT = §7You no longer read §e{0}§7.
|
CHAT_CHANNEL_LEFT = §7You no longer read §e{0}§7.
|
||||||
|
|||||||
@@ -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_USAGE = §8/§7chat §7arenas §8[§ejoin§8|§eleave§8]
|
||||||
CHAT_ARENAS_JOINED = §7Du liest jetzt die Chats aller Fights mit.
|
CHAT_ARENAS_JOINED = §7Du liest jetzt die Chats aller Fights mit.
|
||||||
CHAT_ARENAS_LEFT = §7Du liest die Chats aller Fights nicht mehr 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_UNKNOWN = §cUnbekannter Chatkanal.
|
||||||
CHAT_CHANNEL_JOINED = §7Du liest §e{0} §7wieder mit.
|
CHAT_CHANNEL_JOINED = §7Du liest §e{0} §7wieder mit.
|
||||||
CHAT_CHANNEL_LEFT = §7Du liest §e{0} §7nicht mehr mit.
|
CHAT_CHANNEL_LEFT = §7Du liest §e{0} §7nicht mehr mit.
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ public class ChatManager extends BasicListener {
|
|||||||
private static final Map<UUID, ChatChannel> defaults = new ConcurrentHashMap<>();
|
private static final Map<UUID, ChatChannel> defaults = new ConcurrentHashMap<>();
|
||||||
private static final Map<UUID, String> persisted = new ConcurrentHashMap<>();
|
private static final Map<UUID, String> persisted = new ConcurrentHashMap<>();
|
||||||
private static final Set<UUID> globalOnArena = ConcurrentHashMap.newKeySet();
|
private static final Set<UUID> 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<UUID> globalAfterWriting = ConcurrentHashMap.newKeySet();
|
||||||
private static final Set<UUID> announced = ConcurrentHashMap.newKeySet();
|
private static final Set<UUID> announced = ConcurrentHashMap.newKeySet();
|
||||||
private static final Map<UUID, Set<RegisteredServer>> spies = new ConcurrentHashMap<>();
|
private static final Map<UUID, Set<RegisteredServer>> spies = new ConcurrentHashMap<>();
|
||||||
private static final Map<UUID, Boolean> allArenas = new ConcurrentHashMap<>();
|
private static final Map<UUID, Boolean> allArenas = new ConcurrentHashMap<>();
|
||||||
@@ -159,7 +161,20 @@ public class ChatManager extends BasicListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean readsGlobal(Player player) {
|
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;
|
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)) {
|
if (hidden(uuid).add(id)) {
|
||||||
saveHidden(uuid);
|
saveHidden(uuid);
|
||||||
}
|
}
|
||||||
@@ -457,6 +478,7 @@ public class ChatManager extends BasicListener {
|
|||||||
|
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
globalOnArena.remove(uuid);
|
globalOnArena.remove(uuid);
|
||||||
|
globalAfterWriting.remove(uuid);
|
||||||
|
|
||||||
ChatChannel current = defaults.get(uuid);
|
ChatChannel current = defaults.get(uuid);
|
||||||
ChatChannel next;
|
ChatChannel next;
|
||||||
@@ -477,6 +499,7 @@ public class ChatManager extends BasicListener {
|
|||||||
defaults.remove(uuid);
|
defaults.remove(uuid);
|
||||||
persisted.remove(uuid);
|
persisted.remove(uuid);
|
||||||
globalOnArena.remove(uuid);
|
globalOnArena.remove(uuid);
|
||||||
|
globalAfterWriting.remove(uuid);
|
||||||
announced.remove(uuid);
|
announced.remove(uuid);
|
||||||
spies.remove(uuid);
|
spies.remove(uuid);
|
||||||
allArenas.remove(uuid);
|
allArenas.remove(uuid);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ package de.steamwar.velocitycore.commands;
|
|||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.messages.Chatter;
|
import de.steamwar.messages.Chatter;
|
||||||
|
import de.steamwar.messages.PlayerChatter;
|
||||||
import de.steamwar.velocitycore.chat.ChatManager;
|
import de.steamwar.velocitycore.chat.ChatManager;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
@@ -35,5 +36,8 @@ public class GlobalCommand extends SWCommand {
|
|||||||
@Register(description = "GLOBAL_USAGE")
|
@Register(description = "GLOBAL_USAGE")
|
||||||
public void genericCommand(Chatter sender, String... message) {
|
public void genericCommand(Chatter sender, String... message) {
|
||||||
ChatManager.sendOrSwitch(sender, ChatManager.getGlobal(), message, "GLOBAL_USAGE");
|
ChatManager.sendOrSwitch(sender, ChatManager.getGlobal(), message, "GLOBAL_USAGE");
|
||||||
|
if (message.length > 0 && sender instanceof PlayerChatter player) {
|
||||||
|
ChatManager.readGlobalAfterWriting(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user