diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ChannelOptions.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ChannelOptions.java index dfa3753b..5172f20b 100644 --- a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ChannelOptions.java +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ChannelOptions.java @@ -1,5 +1,6 @@ package net.draycia.carbon.api.config; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import net.draycia.carbon.api.CarbonChatProvider; import net.draycia.carbon.api.Context; @@ -123,6 +124,15 @@ public final class ChannelOptions { @Setting @Comment("The message that's sent when you attempt to ignore a channel but are unable to do so") private String cannotIgnoreMessage; + + @Setting + @Comment("The order in which colors are chosen for the tag.\n" + + "Options:\n" + + " PLAYER: The color the player has set with /setcolor\n" + + " CUSTOM: The color the player has set with /setchannelcolor\n" + + " CHANNEL: The color the channel has set in its settings") + private List<@NonNull ColorPriority> colorPriorities = ImmutableList.of( + ColorPriority.PLAYER, ColorPriority.CUSTOM, ColorPriority.CHANNEL); private @NonNull SharedChannelOptions defaultOptions() { return CarbonChatProvider.carbonChat().channelSettings().defaultChannelOptions(); @@ -406,6 +416,14 @@ public final class ChannelOptions { return this.shouldCancelChatEvent; } + public List colorPriorities() { + if (this.colorPriorities == null) { + return this.defaultOptions().colorPriorities(); + } + + return this.colorPriorities; + } + public @Nullable List aliases() { return this.aliases; } diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ColorPriority.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ColorPriority.java new file mode 100644 index 00000000..5736466a --- /dev/null +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ColorPriority.java @@ -0,0 +1,7 @@ +package net.draycia.carbon.api.config; + +public enum ColorPriority { + PLAYER, + CUSTOM, + CHANNEL +} diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/SharedChannelOptions.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/SharedChannelOptions.java index 4dc7653a..b6a1392f 100644 --- a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/SharedChannelOptions.java +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/SharedChannelOptions.java @@ -36,6 +36,7 @@ public final class SharedChannelOptions { @Setting private @NonNull String toggleOtherOffMessage = " can no longer see chat!"; @Setting private @NonNull String cannotUseMessage = "You cannot use that channel!"; @Setting private @NonNull String cannotIgnoreMessage = "You cannot ignore that channel!"; + @Setting private @NonNull List<@NonNull ColorPriority> colorPriorities = new ArrayList<>(); public @NonNull String color() { return this.color; @@ -117,4 +118,7 @@ public final class SharedChannelOptions { return this.shouldCancelChatEvent; } + public @NonNull List<@NonNull ColorPriority> colorPriorities() { + return this.colorPriorities; + } } diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/PlayerUser.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/PlayerUser.java index 4335a470..883ede3c 100644 --- a/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/PlayerUser.java +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/PlayerUser.java @@ -1,6 +1,7 @@ package net.draycia.carbon.api.users; import net.draycia.carbon.api.channels.ChatChannel; +import net.kyori.adventure.text.format.TextColor; import net.luckperms.api.model.group.Group; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -29,6 +30,10 @@ public interface PlayerUser extends CarbonUser { @NonNull String name(); + @Nullable TextColor customChatColor(); + + void customChatColor(@Nullable TextColor customChatColor); + @NonNull String parsePlaceholders(@NonNull String input); @NonNull UserChannelSettings channelSettings(@NonNull ChatChannel channel); @@ -107,15 +112,15 @@ public interface PlayerUser extends CarbonUser { @NonNull Iterable ignoredUsers(); - boolean hasGroup(final @NonNull String group); + boolean hasGroup(@NonNull String group); - boolean hasGroup(final @NonNull Group group); + boolean hasGroup(@NonNull Group group); @NonNull Collection<@NonNull Group> groups(); @Nullable Group primaryGroup(); - void sendMessage(final @NonNull PlayerUser sender, @NonNull String message); + void sendMessage(@NonNull PlayerUser sender, @NonNull String message); @Nullable ChatChannel selectedChannel(); diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/channels/CarbonChatChannel.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/channels/CarbonChatChannel.java index 0bc3765c..a2259215 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/channels/CarbonChatChannel.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/channels/CarbonChatChannel.java @@ -3,6 +3,7 @@ package net.draycia.carbon.common.channels; import net.draycia.carbon.api.CarbonChat; import net.draycia.carbon.api.channels.TextChannel; import net.draycia.carbon.api.config.ChannelOptions; +import net.draycia.carbon.api.config.ColorPriority; import net.draycia.carbon.api.users.ConsoleUser; import net.draycia.carbon.api.users.PlayerUser; import net.draycia.carbon.common.utils.ColorUtils; @@ -140,11 +141,34 @@ public class CarbonChatChannel implements TextChannel { continue; } - final TextColor targetColor = this.channelColor(target); + final TextColor channelColor = this.channelColor(target); + final TextColor userColor = user.customChatColor(); + final TextColor userChannelColor = user.channelSettings(this).color(); + + TextColor colorBuffer = null; + + for (final ColorPriority colorPriority : this.options().colorPriorities()) { + if (colorPriority == ColorPriority.CHANNEL && channelColor != null) { + colorBuffer = channelColor; + } else if (colorPriority == ColorPriority.PLAYER && userColor != null) { + colorBuffer = userColor; + } else if (colorPriority == ColorPriority.CUSTOM && userChannelColor != null) { + colorBuffer = userChannelColor; + } + } + + final TextColor chosenColor; + + if (colorBuffer == null) { + chosenColor = NamedTextColor.WHITE; + } else { + chosenColor = colorBuffer; + } TextComponent formatComponent = (TextComponent) this.carbonChat.messageProcessor().processMessage(formatEvent.format(), "displayname", displayName, - "color", "<" + targetColor.asHexString() + ">", + "color", "<" + chosenColor.asHexString() + ">", + "playercolor", "<" + user.customChatColor(), "phase", Long.toString(System.currentTimeMillis() % 25), "message", formatEvent.message()); @@ -152,7 +176,7 @@ public class CarbonChatChannel implements TextChannel { final String prefix = this.carbonChat.carbonSettings().spyPrefix(); formatComponent = (TextComponent) MiniMessage.get().parse(prefix, "color", - targetColor.asHexString()).append(formatComponent); + chosenColor.asHexString()).append(formatComponent); } final ChatComponentEvent newEvent = new ChatComponentEvent(user, target, this, formatComponent, @@ -173,11 +197,19 @@ public class CarbonChatChannel implements TextChannel { CarbonEvents.post(consoleFormatEvent); - final TextColor targetColor = this.channelColor(user); + final TextColor channelColor = this.channelColor(user); + final TextColor targetColor; + + if (channelColor != null) { + targetColor = channelColor; + } else { + targetColor = NamedTextColor.WHITE; + } final TextComponent consoleFormat = (TextComponent) this.carbonChat.messageProcessor().processMessage(consoleFormatEvent.format(), "displayname", displayName, "color", "<" + targetColor.asHexString() + ">", + "playercolor", "<" + user.customChatColor(), "phase", Long.toString(System.currentTimeMillis() % 25), "message", consoleFormatEvent.message()); @@ -377,29 +409,14 @@ public class CarbonChatChannel implements TextChannel { @Override public @NonNull TextColor channelColor(final @NonNull CarbonUser user) { - if (user instanceof PlayerUser) { - final TextColor userColor = ((PlayerUser) user).channelSettings(this).color(); - - if (userColor != null) { - return userColor; - } - } - final String input = this.options().color(); if (input != null) { final TextColor color = ColorUtils.parseColor(user, input); - if (color == null) { - if (this.carbonChat.carbonSettings().showTips()) { - this.carbonChat.logger().error("Tip: Channel color found (" + input + ") is invalid!"); - this.carbonChat.logger().error("Falling back to #FFFFFF"); - } - - return NamedTextColor.WHITE; + if (color != null) { + return color; } - - return color; } return NamedTextColor.WHITE; diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/SetColorCommand.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/SetChannelColorCommand.java similarity index 89% rename from CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/SetColorCommand.java rename to CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/SetChannelColorCommand.java index 8345feda..6bbd3926 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/SetColorCommand.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/SetChannelColorCommand.java @@ -14,15 +14,15 @@ import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.format.TextColor; import org.checkerframework.checker.nullness.qual.NonNull; -public class SetColorCommand { +public class SetChannelColorCommand { private final @NonNull CarbonChat carbonChat; @SuppressWarnings("methodref.receiver.bound.invalid") - public SetColorCommand(final @NonNull CommandManager commandManager) { + public SetChannelColorCommand(final @NonNull CommandManager commandManager) { this.carbonChat = CarbonChatProvider.carbonChat(); - final CommandSettings commandSettings = this.carbonChat.commandSettings().get("setcolor"); + final CommandSettings commandSettings = this.carbonChat.commandSettings().get("setchannelcolor"); if (commandSettings == null || !commandSettings.enabled()) { return; @@ -33,7 +33,7 @@ public class SetColorCommand { commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(), commandManager.createDefaultCommandMeta()) .senderType(PlayerUser.class) // player - .permission("carbonchat.setcolor." + channel.key()) + .permission("carbonchat.setchannelcolor." + channel.key()) .argument(StaticArgument.of(channel.key())) .argument(TextColorArgument.of("color")) // remember to replace this when cloud 1.1.0 releases .handler(context -> { diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/misc/CommandRegistrar.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/misc/CommandRegistrar.java index 3176d41e..407265df 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/misc/CommandRegistrar.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/misc/CommandRegistrar.java @@ -16,7 +16,7 @@ import net.draycia.carbon.common.commands.MessageCommand; import net.draycia.carbon.common.commands.MuteCommand; import net.draycia.carbon.common.commands.NicknameCommand; import net.draycia.carbon.common.commands.ReplyCommand; -import net.draycia.carbon.common.commands.SetColorCommand; +import net.draycia.carbon.common.commands.SetChannelColorCommand; import net.draycia.carbon.common.commands.SpyChannelCommand; import net.draycia.carbon.common.commands.SudoChannelCommand; import net.draycia.carbon.common.commands.ToggleCommand; @@ -40,7 +40,7 @@ public final class CommandRegistrar { new MuteCommand(commandManager); new NicknameCommand(commandManager); new ReplyCommand(commandManager); - new SetColorCommand(commandManager); + new SetChannelColorCommand(commandManager); new ShadowMuteCommand(commandManager); new SpyChannelCommand(commandManager); new SudoChannelCommand(commandManager); diff --git a/CarbonChat-Common/src/main/resources/carbonCommands.conf b/CarbonChat-Common/src/main/resources/carbonCommands.conf index e9774e7f..62e38a73 100644 --- a/CarbonChat-Common/src/main/resources/carbonCommands.conf +++ b/CarbonChat-Common/src/main/resources/carbonCommands.conf @@ -1,132 +1,140 @@ { "registry": { "channel": { - "enabled": true, - "name": "channel", "aliases": [ "ch", - "switch", - "join" - ] + "join", + "switch" + ], + "enabled": true, + "name": "channel" }, "channellist": { - "enabled": true, - "name": "channellist", "aliases": [ "chlist" - ] + ], + "enabled": true, + "name": "channellist" }, "chatreload": { - "enabled": true, - "name": "chatreload", "aliases": [ - "creload", - "cr" - ] + "cr", + "creload" + ], + "enabled": true, + "name": "chatreload" }, "clearchat": { - "enabled": true, - "name": "clearchat", "aliases": [ - "clear", - "cc" - ] + "cc", + "clear" + ], + "enabled": true, + "name": "clearchat" }, "ignore": { - "enabled": true, - "name": "ignore", "aliases": [ "block" - ] + ], + "enabled": true, + "name": "ignore" }, "me": { - "enabled": true, - "name": "me", "aliases": [ "rp" - ] + ], + "enabled": true, + "name": "me" }, "message": { - "enabled": true, - "name": "message", "aliases": [ "msg", - "whisper", - "w" - ] + "w", + "whisper" + ], + "enabled": true, + "name": "message" + }, + "msgtoggle": { + "aliases": [ + "messagetoggle" + ], + "enabled": true, + "name": "msgtoggle" }, "mute": { - "enabled": true, - "name": "mute", "aliases": [ "m" - ] + ], + "enabled": true, + "name": "mute" }, "nickname": { - "enabled": true, - "name": "nickname", "aliases": [ "nick" - ] + ], + "enabled": true, + "name": "nickname" }, "reply": { - "enabled": true, - "name": "reply", "aliases": [ "r" - ] + ], + "enabled": true, + "name": "reply" + }, + "setchannelcolor": { + "aliases": [ + "schc", + "setchcolor" + ], + "enabled": true, + "name": "setchannelcolor" }, "setcolor": { - "enabled": true, - "name": "setcolor", "aliases": [ "setcolor" - ] + ], + "enabled": true, + "name": "setcolor" }, "shadowmute": { - "enabled": true, - "name": "shadowmute", "aliases": [ "sm", "smute" - ] + ], + "enabled": true, + "name": "shadowmute" }, "spy": { - "enabled": true, - "name": "spy", "aliases": [ "spych", "spychannel" - ] + ], + "enabled": true, + "name": "spy" }, "sudochannel": { - "enabled": true, - "name": "sudochannel", "aliases": [ - "sch", - "sudoch", - "schannel", + "channelsudo", "chsudo", - "channelsudo" - ] + "sch", + "schannel", + "sudoch" + ], + "enabled": true, + "name": "sudochannel" }, "toggle": { - "enabled": true, - "name": "toggle", "aliases": [ - "togglechannel", "tch", - "togglech", "tchannel", - "togglec" - ] - }, - "msgtoggle": { + "togglec", + "togglech", + "togglechannel" + ], "enabled": true, - "name": "msgtoggle", - "aliases": [ - "messagetoggle" - ] + "name": "toggle" } } }