Finish custom color feature

This commit is contained in:
Draycia committed 2020-11-07 02:04:14 -08:00
1 parent 77e74d05a3
commit 98d7501ee0
3 files changed
+34 -9

No files matched your search

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