Allow PAPI placeholders in color option

This commit is contained in:
Draycia committed 2020-08-13 04:20:19 -07:00
1 parent e69a9fb2a4
commit 8d77995250
7 files changed
+22 -13

No files matched your search

@@ -15,7 +15,7 @@ public abstract class ChatChannel implements ForwardingAudience {
/** /**
* @return The color that represents this channel. Optionally used in formatting. * @return The color that represents this channel. Optionally used in formatting.
*/ */
public abstract TextColor getColor(); public abstract TextColor getChannelColor(ChatUser user);
/** /**
* @return The MiniMessage styled format for the group in this channel. * @return The MiniMessage styled format for the group in this channel.
@@ -1,5 +1,6 @@
package net.draycia.carbon.channels.impls; package net.draycia.carbon.channels.impls;
import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.CarbonChat; import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel; import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.events.ChatComponentEvent; import net.draycia.carbon.events.ChatComponentEvent;
@@ -79,7 +80,7 @@ public class CarbonChatChannel extends ChatChannel {
if (userColor != null) { if (userColor != null) {
return userColor; return userColor;
} else { } else {
return getColor(); return getChannelColor(user);
} }
} }
@@ -134,7 +135,7 @@ public class CarbonChatChannel extends ChatChannel {
TextComponent consoleMessage = (TextComponent) carbonChat.getAdventureManager().processMessage(preFormatEvent.getFormat(), TextComponent consoleMessage = (TextComponent) carbonChat.getAdventureManager().processMessage(preFormatEvent.getFormat(),
"br", "\n", "br", "\n",
"color", "<" + getColor().asHexString() + ">", "color", "<" + getColor(user).asHexString() + ">",
"phase", Long.toString(System.currentTimeMillis() % 25), "phase", Long.toString(System.currentTimeMillis() % 25),
"server", carbonChat.getConfig().getString("server-name", "Server"), "server", carbonChat.getConfig().getString("server-name", "Server"),
"message", preFormatEvent.getMessage()); "message", preFormatEvent.getMessage());
@@ -289,8 +290,14 @@ public class CarbonChatChannel extends ChatChannel {
} }
@Override @Override
public TextColor getColor() { public TextColor getChannelColor(ChatUser user) {
return TextColor.fromHexString(getString("color")); String color = getString("color");
if (user.isOnline()) {
return TextColor.fromHexString(PlaceholderAPI.setPlaceholders(user.asPlayer(), color));
}
return TextColor.fromHexString(color);
} }
private String getDefaultFormatName() { private String getDefaultFormatName() {
@@ -34,7 +34,7 @@ public class AliasedChannelCommand extends BaseCommand {
user.setSelectedChannel(getChatChannel()); user.setSelectedChannel(getChatChannel());
user.sendMessage(carbonChat.getAdventureManager().processMessage(getChatChannel().getSwitchMessage(), user.sendMessage(carbonChat.getAdventureManager().processMessage(getChatChannel().getSwitchMessage(),
"color", "<" + getChatChannel().getColor().toString() + ">", "color", "<" + getChatChannel().getChannelColor(user).toString() + ">",
"channel", getChatChannel().getName())); "channel", getChatChannel().getName()));
} else { } else {
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> { Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
@@ -26,7 +26,7 @@ public class ChannelCommand extends BaseCommand {
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getSwitchMessage(), user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getSwitchMessage(),
"br", "\n", "br", "\n",
"color", "<" + channel.getColor().toString() + ">", "color", "<" + channel.getChannelColor(user).toString() + ">",
"channel", channel.getName())); "channel", channel.getName()));
} else { } else {
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> { Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
@@ -45,10 +45,10 @@ public class ChannelCommand extends BaseCommand {
String otherMessage = channel.getSwitchOtherMessage(); String otherMessage = channel.getSwitchOtherMessage();
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n", user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
"color", "<color:" + channel.getColor().toString() + ">", "channel", channel.getName())); "color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n", carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n",
"color", "<color:" + channel.getColor().toString() + ">", "channel", channel.getName(), "color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName(),
"player", user.asOfflinePlayer().getName())); "player", user.asOfflinePlayer().getName()));
} }
@@ -33,7 +33,7 @@ public class SpyChannelCommand extends BaseCommand {
} }
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n", user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
"color", "<color:" + channel.getColor().toString() + ">", "channel", channel.getName())); "color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
} }
@Subcommand("whispers") @Subcommand("whispers")
@@ -34,7 +34,7 @@ public class ToggleCommand extends BaseCommand {
} }
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n", user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
"color", "<color:" + channel.getColor().toString() + ">", "channel", channel.getName())); "color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
} }
@CommandPermission("carbonchat.toggle.others") @CommandPermission("carbonchat.toggle.others")
@@ -57,10 +57,10 @@ public class ToggleCommand extends BaseCommand {
} }
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n", user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
"color", "<color:" + channel.getColor().toString() + ">", "channel", channel.getName())); "color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage,
"br", "\n", "color", "<color:" + channel.getColor().toString() + ">", "br", "\n", "color", "<color:" + channel.getChannelColor(user).toString() + ">",
"channel", channel.getName(), "player", user.asOfflinePlayer().getName())); "channel", channel.getName(), "player", user.asOfflinePlayer().getName()));
} }
} }
+2
View File
@@ -33,6 +33,8 @@ default:
# filter only works when CarbonChatModeration is installed. # filter only works when CarbonChatModeration is installed.
# Modifies / prevents messages depending on how filters are setup. # Modifies / prevents messages depending on how filters are setup.
filter: true filter: true
# The <color> placeholder in channel formats (and other formats).
# This option does support PlaceholderAPI placeholders, however the resulting string must be a valid color!
color: '#FFFFFF' color: '#FFFFFF'
# Can players /toggle this channel and hide its messages? # Can players /toggle this channel and hide its messages?
ignorable: true ignorable: true