Begin color preference changes

This commit is contained in:
Draycia committed 2020-11-06 02:19:50 -08:00
1 parent af705e7812
commit 77e74d05a3
8 files changed
+155 -96

No files matched your search

@@ -1,5 +1,6 @@
package net.draycia.carbon.api.config; package net.draycia.carbon.api.config;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import net.draycia.carbon.api.CarbonChatProvider; import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.Context; import net.draycia.carbon.api.Context;
@@ -124,6 +125,15 @@ public final class ChannelOptions {
@Comment("The message that's sent when you attempt to ignore a channel but are unable to do so") @Comment("The message that's sent when you attempt to ignore a channel but are unable to do so")
private String cannotIgnoreMessage; private String cannotIgnoreMessage;
@Setting
@Comment("The order in which colors are chosen for the <color> 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() { private @NonNull SharedChannelOptions defaultOptions() {
return CarbonChatProvider.carbonChat().channelSettings().defaultChannelOptions(); return CarbonChatProvider.carbonChat().channelSettings().defaultChannelOptions();
} }
@@ -406,6 +416,14 @@ public final class ChannelOptions {
return this.shouldCancelChatEvent; return this.shouldCancelChatEvent;
} }
public List<ColorPriority> colorPriorities() {
if (this.colorPriorities == null) {
return this.defaultOptions().colorPriorities();
}
return this.colorPriorities;
}
public @Nullable List<String> aliases() { public @Nullable List<String> aliases() {
return this.aliases; return this.aliases;
} }
@@ -0,0 +1,7 @@
package net.draycia.carbon.api.config;
public enum ColorPriority {
PLAYER,
CUSTOM,
CHANNEL
}
@@ -36,6 +36,7 @@ public final class SharedChannelOptions {
@Setting private @NonNull String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!"; @Setting private @NonNull String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
@Setting private @NonNull String cannotUseMessage = "You cannot use that channel!"; @Setting private @NonNull String cannotUseMessage = "You cannot use that channel!";
@Setting private @NonNull String cannotIgnoreMessage = "<red>You cannot ignore that channel!"; @Setting private @NonNull String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
@Setting private @NonNull List<@NonNull ColorPriority> colorPriorities = new ArrayList<>();
public @NonNull String color() { public @NonNull String color() {
return this.color; return this.color;
@@ -117,4 +118,7 @@ public final class SharedChannelOptions {
return this.shouldCancelChatEvent; return this.shouldCancelChatEvent;
} }
public @NonNull List<@NonNull ColorPriority> colorPriorities() {
return this.colorPriorities;
}
} }
@@ -1,6 +1,7 @@
package net.draycia.carbon.api.users; package net.draycia.carbon.api.users;
import net.draycia.carbon.api.channels.ChatChannel; import net.draycia.carbon.api.channels.ChatChannel;
import net.kyori.adventure.text.format.TextColor;
import net.luckperms.api.model.group.Group; import net.luckperms.api.model.group.Group;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@@ -29,6 +30,10 @@ public interface PlayerUser extends CarbonUser {
@NonNull String name(); @NonNull String name();
@Nullable TextColor customChatColor();
void customChatColor(@Nullable TextColor customChatColor);
@NonNull String parsePlaceholders(@NonNull String input); @NonNull String parsePlaceholders(@NonNull String input);
@NonNull UserChannelSettings channelSettings(@NonNull ChatChannel channel); @NonNull UserChannelSettings channelSettings(@NonNull ChatChannel channel);
@@ -107,15 +112,15 @@ public interface PlayerUser extends CarbonUser {
@NonNull Iterable<UUID> ignoredUsers(); @NonNull Iterable<UUID> 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(); @NonNull Collection<@NonNull Group> groups();
@Nullable Group primaryGroup(); @Nullable Group primaryGroup();
void sendMessage(final @NonNull PlayerUser sender, @NonNull String message); void sendMessage(@NonNull PlayerUser sender, @NonNull String message);
@Nullable ChatChannel selectedChannel(); @Nullable ChatChannel selectedChannel();
@@ -3,6 +3,7 @@ package net.draycia.carbon.common.channels;
import net.draycia.carbon.api.CarbonChat; import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.channels.TextChannel; import net.draycia.carbon.api.channels.TextChannel;
import net.draycia.carbon.api.config.ChannelOptions; 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.ConsoleUser;
import net.draycia.carbon.api.users.PlayerUser; import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.common.utils.ColorUtils; import net.draycia.carbon.common.utils.ColorUtils;
@@ -140,11 +141,34 @@ public class CarbonChatChannel implements TextChannel {
continue; 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(), TextComponent formatComponent = (TextComponent) this.carbonChat.messageProcessor().processMessage(formatEvent.format(),
"displayname", displayName, "displayname", displayName,
"color", "<" + targetColor.asHexString() + ">", "color", "<" + chosenColor.asHexString() + ">",
"playercolor", "<" + user.customChatColor(),
"phase", Long.toString(System.currentTimeMillis() % 25), "phase", Long.toString(System.currentTimeMillis() % 25),
"message", formatEvent.message()); "message", formatEvent.message());
@@ -152,7 +176,7 @@ public class CarbonChatChannel implements TextChannel {
final String prefix = this.carbonChat.carbonSettings().spyPrefix(); final String prefix = this.carbonChat.carbonSettings().spyPrefix();
formatComponent = (TextComponent) MiniMessage.get().parse(prefix, "color", formatComponent = (TextComponent) MiniMessage.get().parse(prefix, "color",
targetColor.asHexString()).append(formatComponent); chosenColor.asHexString()).append(formatComponent);
} }
final ChatComponentEvent newEvent = new ChatComponentEvent(user, target, this, formatComponent, final ChatComponentEvent newEvent = new ChatComponentEvent(user, target, this, formatComponent,
@@ -173,11 +197,19 @@ public class CarbonChatChannel implements TextChannel {
CarbonEvents.post(consoleFormatEvent); 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(), final TextComponent consoleFormat = (TextComponent) this.carbonChat.messageProcessor().processMessage(consoleFormatEvent.format(),
"displayname", displayName, "displayname", displayName,
"color", "<" + targetColor.asHexString() + ">", "color", "<" + targetColor.asHexString() + ">",
"playercolor", "<" + user.customChatColor(),
"phase", Long.toString(System.currentTimeMillis() % 25), "phase", Long.toString(System.currentTimeMillis() % 25),
"message", consoleFormatEvent.message()); "message", consoleFormatEvent.message());
@@ -377,30 +409,15 @@ public class CarbonChatChannel implements TextChannel {
@Override @Override
public @NonNull TextColor channelColor(final @NonNull CarbonUser user) { 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(); final String input = this.options().color();
if (input != null) { if (input != null) {
final TextColor color = ColorUtils.parseColor(user, input); final TextColor color = ColorUtils.parseColor(user, input);
if (color == null) { 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;
}
return color; return color;
} }
}
return NamedTextColor.WHITE; return NamedTextColor.WHITE;
} }
@@ -14,15 +14,15 @@ import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
public class SetColorCommand { public class SetChannelColorCommand {
private final @NonNull CarbonChat carbonChat; private final @NonNull CarbonChat carbonChat;
@SuppressWarnings("methodref.receiver.bound.invalid") @SuppressWarnings("methodref.receiver.bound.invalid")
public SetColorCommand(final @NonNull CommandManager<CarbonUser> commandManager) { public SetChannelColorCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); 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()) { if (commandSettings == null || !commandSettings.enabled()) {
return; return;
@@ -33,7 +33,7 @@ public class SetColorCommand {
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(), commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
commandManager.createDefaultCommandMeta()) commandManager.createDefaultCommandMeta())
.senderType(PlayerUser.class) // player .senderType(PlayerUser.class) // player
.permission("carbonchat.setcolor." + channel.key()) .permission("carbonchat.setchannelcolor." + channel.key())
.argument(StaticArgument.of(channel.key())) .argument(StaticArgument.of(channel.key()))
.argument(TextColorArgument.of("color")) // remember to replace this when cloud 1.1.0 releases .argument(TextColorArgument.of("color")) // remember to replace this when cloud 1.1.0 releases
.handler(context -> { .handler(context -> {
@@ -16,7 +16,7 @@ import net.draycia.carbon.common.commands.MessageCommand;
import net.draycia.carbon.common.commands.MuteCommand; import net.draycia.carbon.common.commands.MuteCommand;
import net.draycia.carbon.common.commands.NicknameCommand; import net.draycia.carbon.common.commands.NicknameCommand;
import net.draycia.carbon.common.commands.ReplyCommand; 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.SpyChannelCommand;
import net.draycia.carbon.common.commands.SudoChannelCommand; import net.draycia.carbon.common.commands.SudoChannelCommand;
import net.draycia.carbon.common.commands.ToggleCommand; import net.draycia.carbon.common.commands.ToggleCommand;
@@ -40,7 +40,7 @@ public final class CommandRegistrar {
new MuteCommand(commandManager); new MuteCommand(commandManager);
new NicknameCommand(commandManager); new NicknameCommand(commandManager);
new ReplyCommand(commandManager); new ReplyCommand(commandManager);
new SetColorCommand(commandManager); new SetChannelColorCommand(commandManager);
new ShadowMuteCommand(commandManager); new ShadowMuteCommand(commandManager);
new SpyChannelCommand(commandManager); new SpyChannelCommand(commandManager);
new SudoChannelCommand(commandManager); new SudoChannelCommand(commandManager);
@@ -1,132 +1,140 @@
{ {
"registry": { "registry": {
"channel": { "channel": {
"enabled": true,
"name": "channel",
"aliases": [ "aliases": [
"ch", "ch",
"switch", "join",
"join" "switch"
] ],
"enabled": true,
"name": "channel"
}, },
"channellist": { "channellist": {
"enabled": true,
"name": "channellist",
"aliases": [ "aliases": [
"chlist" "chlist"
] ],
"enabled": true,
"name": "channellist"
}, },
"chatreload": { "chatreload": {
"enabled": true,
"name": "chatreload",
"aliases": [ "aliases": [
"creload", "cr",
"cr" "creload"
] ],
"enabled": true,
"name": "chatreload"
}, },
"clearchat": { "clearchat": {
"enabled": true,
"name": "clearchat",
"aliases": [ "aliases": [
"clear", "cc",
"cc" "clear"
] ],
"enabled": true,
"name": "clearchat"
}, },
"ignore": { "ignore": {
"enabled": true,
"name": "ignore",
"aliases": [ "aliases": [
"block" "block"
] ],
"enabled": true,
"name": "ignore"
}, },
"me": { "me": {
"enabled": true,
"name": "me",
"aliases": [ "aliases": [
"rp" "rp"
] ],
"enabled": true,
"name": "me"
}, },
"message": { "message": {
"enabled": true,
"name": "message",
"aliases": [ "aliases": [
"msg", "msg",
"whisper", "w",
"w" "whisper"
] ],
"enabled": true,
"name": "message"
},
"msgtoggle": {
"aliases": [
"messagetoggle"
],
"enabled": true,
"name": "msgtoggle"
}, },
"mute": { "mute": {
"enabled": true,
"name": "mute",
"aliases": [ "aliases": [
"m" "m"
] ],
"enabled": true,
"name": "mute"
}, },
"nickname": { "nickname": {
"enabled": true,
"name": "nickname",
"aliases": [ "aliases": [
"nick" "nick"
] ],
"enabled": true,
"name": "nickname"
}, },
"reply": { "reply": {
"enabled": true,
"name": "reply",
"aliases": [ "aliases": [
"r" "r"
] ],
"enabled": true,
"name": "reply"
},
"setchannelcolor": {
"aliases": [
"schc",
"setchcolor"
],
"enabled": true,
"name": "setchannelcolor"
}, },
"setcolor": { "setcolor": {
"enabled": true,
"name": "setcolor",
"aliases": [ "aliases": [
"setcolor" "setcolor"
] ],
"enabled": true,
"name": "setcolor"
}, },
"shadowmute": { "shadowmute": {
"enabled": true,
"name": "shadowmute",
"aliases": [ "aliases": [
"sm", "sm",
"smute" "smute"
] ],
"enabled": true,
"name": "shadowmute"
}, },
"spy": { "spy": {
"enabled": true,
"name": "spy",
"aliases": [ "aliases": [
"spych", "spych",
"spychannel" "spychannel"
] ],
"enabled": true,
"name": "spy"
}, },
"sudochannel": { "sudochannel": {
"enabled": true,
"name": "sudochannel",
"aliases": [ "aliases": [
"sch", "channelsudo",
"sudoch",
"schannel",
"chsudo", "chsudo",
"channelsudo" "sch",
] "schannel",
"sudoch"
],
"enabled": true,
"name": "sudochannel"
}, },
"toggle": { "toggle": {
"enabled": true,
"name": "toggle",
"aliases": [ "aliases": [
"togglechannel",
"tch", "tch",
"togglech",
"tchannel", "tchannel",
"togglec" "togglec",
] "togglech",
}, "togglechannel"
"msgtoggle": { ],
"enabled": true, "enabled": true,
"name": "msgtoggle", "name": "toggle"
"aliases": [
"messagetoggle"
]
} }
} }
} }