Attempt to add prefixes to adminchat

This commit is contained in:
Telesphoreo 2023-08-29 16:06:16 -05:00
parent 2c7440804c
commit 2a2152603b
5 changed files with 23 additions and 9 deletions

View File

@ -10,6 +10,7 @@ import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage; import dev.plex.util.minimessage.SafeMiniMessage;
import dev.plex.util.redis.MessageUtil; import dev.plex.util.redis.MessageUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -26,20 +27,31 @@ public class AdminChatCMD extends PlexCommand
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{ {
PlexPlayer player;
if (args.length == 0) if (args.length == 0)
{ {
if (playerSender != null) if (playerSender != null)
{ {
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId()); player = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
player.setStaffChat(!player.isStaffChat()); player.setStaffChat(!player.isStaffChat());
return messageComponent("adminChatToggled", BooleanUtils.toStringOnOff(player.isStaffChat())); return messageComponent("adminChatToggled", BooleanUtils.toStringOnOff(player.isStaffChat()));
} }
return usage(); return usage();
} }
String prefix;
if (playerSender != null)
{
player = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
prefix = player.getPrefix();
}
else
{
prefix = messageString(LegacyComponentSerializer.legacyAmpersand().serialize(mmString("<dark_gray>[<dark_purple>Console<dark_gray]")));
}
String message = StringUtils.join(args, " "); String message = StringUtils.join(args, " ");
plugin.getServer().getConsoleSender().sendMessage(messageComponent("adminChatFormat", sender.getName(), message)); plugin.getServer().getConsoleSender().sendMessage(messageComponent("adminChatFormat", sender.getName(), prefix, message));
MessageUtil.sendStaffChat(sender, SafeMiniMessage.mmDeserialize(message), PlexUtils.adminChat(sender.getName(), message).toArray(UUID[]::new)); MessageUtil.sendStaffChat(sender, SafeMiniMessage.mmDeserialize(message), PlexUtils.adminChat(sender.getName(), prefix, message).toArray(UUID[]::new));
return null; return null;
} }
} }

View File

@ -43,7 +43,7 @@ public class ChatListener extends PlexListener
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId()); PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId());
if (plexPlayer.isStaffChat()) if (plexPlayer.isStaffChat())
{ {
MessageUtil.sendStaffChat(event.getPlayer(), event.message(), PlexUtils.adminChat(event.getPlayer().getName(), SafeMiniMessage.mmSerialize(event.message())).toArray(UUID[]::new)); MessageUtil.sendStaffChat(event.getPlayer(), event.message(), PlexUtils.adminChat(event.getPlayer().getName(), plexPlayer.getPrefix(), SafeMiniMessage.mmSerialize(event.message())).toArray(UUID[]::new));
plugin.getServer().getConsoleSender().sendMessage(PlexUtils.messageComponent("adminChatFormat", event.getPlayer().getName(), SafeMiniMessage.mmSerialize(event.message())).replaceText(URL_REPLACEMENT_CONFIG)); plugin.getServer().getConsoleSender().sendMessage(PlexUtils.messageComponent("adminChatFormat", event.getPlayer().getName(), SafeMiniMessage.mmSerialize(event.message())).replaceText(URL_REPLACEMENT_CONFIG));
event.setCancelled(true); event.setCancelled(true);
return; return;

View File

@ -284,7 +284,7 @@ public class PlexUtils implements PlexBase
}); });
} }
public static List<UUID> adminChat(String senderName, String message, UUID... ignore) public static List<UUID> adminChat(String senderName, String prefix, String message, UUID... ignore)
{ {
List<UUID> sent = Lists.newArrayList(); List<UUID> sent = Lists.newArrayList();
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
@ -295,7 +295,7 @@ public class PlexUtils implements PlexBase
} }
if (player.hasPermission("plex.adminchat")) if (player.hasPermission("plex.adminchat"))
{ {
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", senderName, message).replaceText(ChatListener.URL_REPLACEMENT_CONFIG)); player.sendMessage(PlexUtils.messageComponent("adminChatFormat", senderName, prefix, message).replaceText(ChatListener.URL_REPLACEMENT_CONFIG));
sent.add(player.getUniqueId()); sent.add(player.getUniqueId());
} }
} }

View File

@ -16,6 +16,7 @@ import redis.clients.jedis.JedisPubSub;
import java.util.UUID; import java.util.UUID;
import static dev.plex.PlexBase.plugin;
import static dev.plex.util.PlexUtils.messageComponent; import static dev.plex.util.PlexUtils.messageComponent;
public class MessageUtil public class MessageUtil
@ -40,7 +41,7 @@ public class MessageUtil
{ {
}.getType()); }.getType());
String sender = object.getString("sender").isEmpty() ? "CONSOLE" : object.getString("sender"); String sender = object.getString("sender").isEmpty() ? "CONSOLE" : object.getString("sender");
PlexUtils.adminChat(sender, object.getString("message"), ignore); PlexUtils.adminChat(sender, plugin.getPlayerCache().getPlexPlayer(Bukkit.getPlayer(sender).getUniqueId()).getPrefix(), object.getString("message"), ignore);
String[] server = object.getString("server").split(":"); String[] server = object.getString("server").split(":");
if (!Bukkit.getServer().getIp().equalsIgnoreCase(server[0]) || Bukkit.getServer().getPort() != Integer.parseInt(server[1])) if (!Bukkit.getServer().getIp().equalsIgnoreCase(server[0]) || Bukkit.getServer().getPort() != Integer.parseInt(server[1]))
{ {

View File

@ -130,8 +130,9 @@ toggleCommandSpy: "<gray>CommandSpy has been"
enabled: "<gray>enabled." enabled: "<gray>enabled."
disabled: "<gray>disabled." disabled: "<gray>disabled."
# 0 - The admin / staff member # 0 - The admin / staff member
# 1 - The message # 1 - The player's prefix
adminChatFormat: '<dark_gray>[<blue>AdminChat<dark_gray>] <dark_red>{0} <gray>» <gold>{1}' # 2 - The message
adminChatFormat: '<dark_gray>[<blue>AdminChat<dark_gray>] <dark_red>{0} {1} <gray>» <gold>{2}'
# 0 - Whether it was toggled on or off # 0 - Whether it was toggled on or off
adminChatToggled: '<gray>AdminChat was toggled {0}' adminChatToggled: '<gray>AdminChat was toggled {0}'
# 0 - Maximum length, configured in config.yml # 0 - Maximum length, configured in config.yml