forked from SteamWar/SteamWar
Show default channel notice with its icon
The notice on join, on every default change and for /chat is now "<icon> is your default channel" in green without the SteamWar prefix; hovering the icon shows the channel name.
This commit is contained in:
@@ -612,8 +612,7 @@ CHAT_CHANNEL_SERVERTEAM = §eSTC
|
||||
CHAT_CHANNEL_MSG = §eMSG §7{0}
|
||||
CHAT_CHANNEL_ALERT = §cAlert
|
||||
CHAT_CHANNEL_LOCAL = §eLocal
|
||||
CHAT_CHANNEL_CURRENT = §7You are writing into §e{0}§7.
|
||||
CHAT_CHANNEL_SWITCHED = §7You are now writing into §e{0}§7.
|
||||
CHAT_CHANNEL_DEFAULT = §ais your default channel
|
||||
CHAT_CHANNEL_NOT_SWITCHABLE = §cYou cannot write into this channel by default.
|
||||
CHAT_NO_WRITE = §cYou cannot write into this channel.
|
||||
CHAT_FIGHT_NO_TEAM = §cYou are not in a fight team.
|
||||
|
||||
@@ -577,8 +577,7 @@ CHAT_CHANNEL_SERVERTEAM = §eSTC
|
||||
CHAT_CHANNEL_MSG = §eMSG §7{0}
|
||||
CHAT_CHANNEL_ALERT = §cAlert
|
||||
CHAT_CHANNEL_LOCAL = §eLokal
|
||||
CHAT_CHANNEL_CURRENT = §7Du schreibst in §e{0}§7.
|
||||
CHAT_CHANNEL_SWITCHED = §7Du schreibst jetzt in §e{0}§7.
|
||||
CHAT_CHANNEL_DEFAULT = §aist dein Standardkanal
|
||||
CHAT_CHANNEL_NOT_SWITCHABLE = §cIn diesen Kanal kannst du nicht standardmäßig schreiben.
|
||||
CHAT_NO_WRITE = §cDu kannst nicht in diesen Kanal schreiben.
|
||||
CHAT_FIGHT_NO_TEAM = §cDu bist in keinem Kampfteam.
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.messages.Chatter;
|
||||
import de.steamwar.messages.Message;
|
||||
import de.steamwar.messages.PlayerChatter;
|
||||
import de.steamwar.network.packets.common.FightInfoPacket;
|
||||
import de.steamwar.persistent.Subserver;
|
||||
@@ -41,6 +42,8 @@ import de.steamwar.velocitycore.EventStarter;
|
||||
import de.steamwar.velocitycore.VelocityCore;
|
||||
import de.steamwar.velocitycore.listeners.BasicListener;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -313,7 +316,7 @@ public class ChatManager extends BasicListener {
|
||||
}
|
||||
|
||||
defaults.put(uuid, channel);
|
||||
player.system("CHAT_CHANNEL_SWITCHED", channel.tag(player));
|
||||
notifyDefault(player, channel);
|
||||
}
|
||||
|
||||
private static void setDefault(PlayerChatter player, ChatChannel channel) {
|
||||
@@ -322,12 +325,25 @@ public class ChatManager extends BasicListener {
|
||||
|
||||
ChatChannel previous = defaults.put(uuid, channel);
|
||||
if (announced.add(uuid)) {
|
||||
player.system("CHAT_CHANNEL_CURRENT", channel.tag(player));
|
||||
notifyDefault(player, channel);
|
||||
} else if (previous != channel && !player.parseToPlain(previous.tag(player)).equals(player.parseToPlain(channel.tag(player)))) {
|
||||
player.system("CHAT_CHANNEL_SWITCHED", channel.tag(player));
|
||||
notifyDefault(player, channel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the player which channel they write into, showing the channel icon with its name on hover.
|
||||
*/
|
||||
public static void notifyDefault(PlayerChatter player, ChatChannel channel) {
|
||||
Message icon = channel.icon(player);
|
||||
Component iconComponent = icon == null ? player.parse(channel.tag(player)) : player.parse(new Message("CHAT_ICON", "§a", icon));
|
||||
player.sendMessage(Component.text()
|
||||
.append(iconComponent.hoverEvent(HoverEvent.showText(player.parse(channel.tag(player)))))
|
||||
.append(Component.text(" "))
|
||||
.append(player.parse(new Message("CHAT_CHANNEL_DEFAULT")))
|
||||
.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a chat message the player typed without a command.
|
||||
*/
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ChatCommand extends SWCommand {
|
||||
|
||||
@Register(description = "CHAT_USAGE")
|
||||
public void current(PlayerChatter sender) {
|
||||
sender.system("CHAT_CHANNEL_CURRENT", ChatManager.getDefault(sender).tag(sender));
|
||||
ChatManager.notifyDefault(sender, ChatManager.getDefault(sender));
|
||||
}
|
||||
|
||||
@Register
|
||||
|
||||
Reference in New Issue
Block a user