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 883ede3c..d86f7396 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 @@ -32,7 +32,7 @@ public interface PlayerUser extends CarbonUser { @Nullable TextColor customChatColor(); - void customChatColor(@Nullable TextColor customChatColor); + void customChatColor(@Nullable TextColor customChatColor, boolean fromRemote); @NonNull String parsePlaceholders(@NonNull String input); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/bukkit/users/BukkitPlayerUser.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/bukkit/users/BukkitPlayerUser.java index 7a1b77a7..1a59442b 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/bukkit/users/BukkitPlayerUser.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/bukkit/users/BukkitPlayerUser.java @@ -16,6 +16,7 @@ import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.ForwardingAudience; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextColor; import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPermsProvider; import net.luckperms.api.model.group.Group; @@ -46,6 +47,7 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single { private boolean spyingWhispers = false; private @Nullable String nickname = null; private @Nullable UUID replyTarget = null; + private @Nullable TextColor customChatColor = null; private @Nullable String selectedChannelKey = null; private transient @Nullable ChatChannel selectedChannel = null; @@ -182,6 +184,27 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single { return this.carbonChat.resolveName(this.uuid); } + @Override + public @Nullable TextColor customChatColor() { + return this.customChatColor; + } + + @Override + public void customChatColor(@Nullable final TextColor customChatColor, final boolean fromRemote) { + this.customChatColor = customChatColor; + + if (!fromRemote) { + if (customChatColor == null) { + this.carbonChat.messageManager().sendMessage("custom-chat-color-reset", this.uuid(), byteArray -> { + }); + } else { + this.carbonChat.messageManager().sendMessage("custom-chat-color", this.uuid(), byteArray -> { + byteArray.writeUTF(customChatColor.asHexString()); + }); + } + } + } + @Override @SuppressWarnings("argument.type.incompatible") public @Nullable ChatChannel selectedChannel() { diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/users/MySQLUserService.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/users/MySQLUserService.java index 6c43a266..9da79715 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/users/MySQLUserService.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/users/MySQLUserService.java @@ -70,12 +70,13 @@ public class MySQLUserService imple try { this.database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_users (uuid CHAR(36) PRIMARY KEY," + "channel VARCHAR(16), muted BOOLEAN, shadowmuted BOOLEAN, spyingwhispers BOOLEAN," + - "nickname VARCHAR(512))"); + "nickname VARCHAR(512), customchatcolor VARCHAR(32))"); // Ignore the exception, it's just saying the column already exists try { this.database.executeUpdate("ALTER TABLE sc_users ADD COLUMN spyingwhispers BOOLEAN DEFAULT false"); this.database.executeUpdate("ALTER TABLE sc_users ADD COLUMN nickname VARCHAR(512) DEFAULT false"); + this.database.executeUpdate("ALTER TABLE sc_users ADD COLUMN customchatcolor VARCHAR(32) DEFAULT false"); } catch (final SQLSyntaxErrorException ignored) { } @@ -169,9 +170,10 @@ public class MySQLUserService imple user.nickname(nickname, true); } - user.muted(users.get("muted"), true); - user.shadowMuted(users.get("shadowmuted"), true); - user.spyingWhispers(users.get("spyingwhispers"), true); + user.muted(users.get("muted"), true); + user.shadowMuted(users.get("shadowmuted"), true); + user.spyingWhispers(users.get("spyingwhispers"), true); + user.customChatColor(users.get("customchatcolor"), true); for (final DbRow channelSetting : channelSettings) { final ChatChannel chatChannel = this.carbonChat.channelRegistry().get(channelSetting.getString("channel")); @@ -215,10 +217,10 @@ public class MySQLUserService imple } this.carbonChat.logger().info("Saving user data!"); - stm.executeUpdateQuery("INSERT INTO sc_users (uuid, channel, muted, shadowmuted, spyingwhispers, nickname) VALUES (?, ?, ?, ?, ?, ?) " + - "ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?, spyingwhispers = ?, nickname =?", - user.uuid().toString(), selectedName, user.muted(), user.shadowMuted(), user.spyingWhispers(), user.nickname(), - selectedName, user.muted(), user.shadowMuted(), user.spyingWhispers(), user.nickname()); + stm.executeUpdateQuery("INSERT INTO sc_users (uuid, channel, muted, shadowmuted, spyingwhispers, nickname, customchatcolor) VALUES (?, ?, ?, ?, ?, ?, ?) " + + "ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?, spyingwhispers = ?, nickname = ?, customchatcolor = ?", + user.uuid().toString(), selectedName, user.muted(), user.shadowMuted(), user.spyingWhispers(), user.nickname(), user.customChatColor(), + selectedName, user.muted(), user.shadowMuted(), user.spyingWhispers(), user.nickname(), user.customChatColor()); this.carbonChat.logger().info("Saving user channel settings!"); // Save user channel settings