mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Finish custom color feature
This commit is contained in:
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();
|
||||
|
||||
void customChatColor(@Nullable TextColor customChatColor);
|
||||
void customChatColor(@Nullable TextColor customChatColor, boolean fromRemote);
|
||||
|
||||
@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.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() {
|
||||
|
||||
+10
-8
@@ -70,12 +70,13 @@ public class MySQLUserService<T extends PlayerUser, C extends ConsoleUser> 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<T extends PlayerUser, C extends ConsoleUser> imple
|
||||
user.nickname(nickname, true);
|
||||
}
|
||||
|
||||
user.muted(users.<Boolean>get("muted"), true);
|
||||
user.shadowMuted(users.<Boolean>get("shadowmuted"), true);
|
||||
user.spyingWhispers(users.<Boolean>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<T extends PlayerUser, C extends ConsoleUser> 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
|
||||
|
||||
Reference in new issue
Block a user