mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Begin color preference changes
This commit is contained in:
1 parent
af705e7812
commit
77e74d05a3
8 files changed
+155
-96
No files matched your search
+38
-21
@@ -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;
|
||||
|
||||
+4
-4
@@ -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<CarbonUser> commandManager) {
|
||||
public SetChannelColorCommand(final @NonNull CommandManager<CarbonUser> 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 -> {
|
||||
+2
-2
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user