Finish user settings feature

This commit is contained in:
Draycia authored and Josh (Vicarious) committed 2020-07-07 05:05:11 -07:00
1 parent 6530c8d026
commit 36672f8ed3
10 files changed
+116 -19

No files matched your search

+6
View File
@@ -156,6 +156,12 @@
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- mcMMO and MiniMessage must be compiled locally -->
@@ -157,7 +157,7 @@ public class SimpleChatChannel extends ChatChannel {
// Get formatted message
TextComponent formattedMessage = (TextComponent)MiniMessage.get().parse(formatEvent.getFormat(),
"color", "<" + color.toString() + ">",
"color", "<color:" + color.toString() + ">",
"phase", Long.toString(System.currentTimeMillis() % 25),
"server", simpleChat.getConfig().getString("server-name", "Server"),
"message", formatEvent.getMessage());
@@ -175,7 +175,7 @@ public class SimpleChatChannel extends ChatChannel {
chatUser.sendMessage(componentEvent.getComponent());
} else {
TextComponent newFormat = (TextComponent)MiniMessage.get().parse(formatEvent.getFormat(),
"color", "<" + userColor.toString() + ">",
"color", "<color:" + userColor.toString() + ">",
"phase", Long.toString(System.currentTimeMillis() % 25),
"server", simpleChat.getConfig().getString("server-name", "Server"),
"message", formatEvent.getMessage());
@@ -9,6 +9,7 @@ import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.channels.ChatChannel;
import net.draycia.simplechat.storage.ChatUser;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.entity.Player;
@CommandAlias("chcolor|channelcolor")
@CommandPermission("simplechat.setcolor")
@@ -22,7 +23,9 @@ public class ChannelColorCommand extends BaseCommand {
@Default
@CommandCompletion("@chatchannel @chatcolors")
public void baseCommand(ChatUser user, ChatChannel chatChannel, String color) {
public void baseCommand(Player player, ChatChannel chatChannel, String color) {
ChatUser user = simpleChat.getUserService().wrap(player);
user.getChannelSettings(chatChannel).setColor(TextColor.fromHexString(color));
}
@@ -14,11 +14,11 @@ import org.bukkit.entity.Player;
@CommandAlias("clearchat|cc")
@CommandPermission("simplechat.clearchat")
public class CommandClearChat extends BaseCommand {
public class ClearChatCommand extends BaseCommand {
private SimpleChat simpleChat;
public CommandClearChat(SimpleChat simpleChat) {
public ClearChatCommand(SimpleChat simpleChat) {
this.simpleChat = simpleChat;
}
@@ -0,0 +1,48 @@
package net.draycia.simplechat.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.ConditionFailedException;
import co.aikar.commands.annotation.*;
import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.channels.ChatChannel;
import net.draycia.simplechat.storage.ChatUser;
import net.draycia.simplechat.storage.UserChannelSettings;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player;
@CommandAlias("setcolor")
@CommandPermission("simplechat.setcolor")
public class SetColorCommand extends BaseCommand {
private SimpleChat simpleChat;
public SetColorCommand(SimpleChat simpleChat) {
this.simpleChat = simpleChat;
}
@Default
@CommandCompletion("@chatchannel")
public void baseCommand(Player player, @Conditions("canuse:true") ChatChannel channel, String color) {
// TODO: condition for ChatChannel existing
if (channel == null || color == null) {
throw new ConditionFailedException("Channel or Color not supplied!");
}
ChatUser user = simpleChat.getUserService().wrap(player);
// TODO: move into conditions
if (!player.hasPermission("simplechat.setcolor." + channel.getName())) {
throw new ConditionFailedException("You can't set colors for this channel!");
}
UserChannelSettings settings = user.getChannelSettings(channel);
settings.setColor(TextColor.fromHexString(color));
user.sendMessage(MiniMessage.get().parse(simpleChat.getConfig().getString("language.channel-color-set"),
"color", "<color:" + color + ">", "channel", channel.getName(), "hex", color));
}
}
@@ -24,6 +24,8 @@ public class ChannelManager {
ConfigurationSection section = simpleChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
ConfigurationSection defaults = simpleChat.getConfig().getConfigurationSection("default");
String name = key;
if (section.contains("is-town-chat")) {
builder = TownChatChannel.townBuilder(key);
hasTownChat = true;
@@ -83,7 +85,8 @@ public class ChannelManager {
}
if (section.contains("name")) {
builder.setName(section.getString("name"));
name = section.getString("name");
//builder.setName(section.getString("name"));
}
if (section.contains("color")) {
@@ -138,6 +141,11 @@ public class ChannelManager {
builder.setFirstMatchingGroup(defaults.getBoolean("first-matching-group"));
}
if (name.length() > 16) {
simpleChat.getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
simpleChat.getLogger().warning("Skipping channel, please check your settings!");
}
ChatChannel channel = builder.build(simpleChat);
if (channel.isTownChat() || channel.isNationChat() || channel.isAllianceChat()) {
@@ -52,6 +52,10 @@ public class CommandManager {
});
commandManager.getCommandConditions().addCondition(ChatChannel.class,"canuse", (context, execution, value) -> {
if (value == null) {
throw new ConditionFailedException(simpleChat.getConfig().getString("language.cannot-use-channel"));
}
ChatUser user = simpleChat.getUserService().wrap(context.getIssuer().getPlayer());
if (!value.canPlayerUse(user)) {
@@ -66,7 +70,7 @@ public class CommandManager {
manager.registerCommand(new ToggleCommand(simpleChat));
manager.registerCommand(new ChannelCommand(simpleChat));
manager.registerCommand(new IgnoreCommand(simpleChat));
manager.registerCommand(new CommandClearChat(simpleChat));
manager.registerCommand(new ClearChatCommand(simpleChat));
manager.registerCommand(new ShadowMuteCommand(simpleChat));
manager.registerCommand(new ChatReloadCommand(simpleChat));
manager.registerCommand(new MeCommand(simpleChat));
@@ -74,6 +78,7 @@ public class CommandManager {
manager.registerCommand(new ReplyCommand(simpleChat));
manager.registerCommand(new MuteCommand(simpleChat));
manager.registerCommand(new ChannelColorCommand(simpleChat));
manager.registerCommand(new SetColorCommand(simpleChat));
}
public co.aikar.commands.CommandManager getCommandManager() {
@@ -46,13 +46,15 @@ public class MySQLUserService extends UserService {
database = new HikariPooledDatabase(BukkitDB.getRecommendedOptions(simpleChat, username, password, dbname, hostandport));
DB.setGlobalDatabase(database);
try {
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_users (uuid CHAR(36) PRIMARY KEY," +
"channel TINYTEXT , muted BOOLEAN, shadowmuted BOOLEAN)");
"channel VARCHAR(16), muted BOOLEAN, shadowmuted BOOLEAN)");
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_channel_settings (uuid CHAR(36), channel TINYTEXT, spying BOOLEAN, ignored BOOLEAN, color TINYTEXT, PRIMARY KEY (uuid, channel))");
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_channel_settings (uuid CHAR(36), channel CHAR(16), spying BOOLEAN, ignored BOOLEAN, color TINYTEXT, PRIMARY KEY (uuid, channel))");
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_ignored_users (uuid CHAR(36), user CHAR(36), PRIMARY KEY (uuid, user)");
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_ignored_users (uuid CHAR(36), user CHAR(36), PRIMARY KEY (uuid, user))");
} catch (SQLException e) {
e.printStackTrace();
}
@@ -124,29 +126,49 @@ public class MySQLUserService extends UserService {
private void saveUser(RemovalNotification<UUID, SimpleChatUser> notification) {
SimpleChatUser user = notification.getValue();
if (user == null) {
System.out.println("null");
return;
}
database.createTransaction(stm -> {
// Save user general data
stm.executeUpdate("INSERT INTO sc_users (uuid, channel, muted, shadowmuted) VALUES (?, ?, ?, ?) " +
"ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?",
user.getUUID().toString(), user.getSelectedChannel().getName(), user.isMuted(), user.isShadowMuted(),
user.getSelectedChannel().getName(), user.isMuted(), user.isShadowMuted());
String selectedName = null;
if (user.getSelectedChannel() != null) {
selectedName = user.getSelectedChannel().getName();
}
simpleChat.getLogger().info("Saving user data!");
stm.executeUpdateQuery("INSERT INTO sc_users (uuid, channel, muted, shadowmuted) VALUES (?, ?, ?, ?) " +
"ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?",
user.getUUID().toString(), selectedName, user.isMuted(), user.isShadowMuted(),
selectedName, user.isMuted(), user.isShadowMuted());
simpleChat.getLogger().info("Saving user channel settings!");
// Save user channel settings
for (Map.Entry<String, UserChannelSettings> entry : user.getChannelSettings().entrySet()) {
UserChannelSettings value = entry.getValue();
stm.executeUpdate("INSERT INTO sc_channel_settings (uuid, channel, spying, ignored, color) VALUES (?, ?, ?, ?, ?) " +
String colorString = null;
if (value.getColor() != null) {
colorString = value.getColor().asHexString();
}
stm.executeUpdateQuery("INSERT INTO sc_channel_settings (uuid, channel, spying, ignored, color) VALUES (?, ?, ?, ?, ?) " +
"ON DUPLICATE KEY UPDATE spying = ?, ignored = ?, color = ?",
user.getUUID().toString(), entry.getKey(), value.isSpying(), value.isIgnored(), value.getColor().asHexString(),
value.isSpying(), value.isIgnored(), value.getColor().asHexString());
user.getUUID().toString(), entry.getKey(), value.isSpying(), value.isIgnored(), colorString,
value.isSpying(), value.isIgnored(), colorString);
}
simpleChat.getLogger().info("Saving user ignores!");
// Save user ignore list (remove old entries then add new ones)
// TODO: keep DB up to date with settings as settings are mutated
stm.executeUpdate("DELETE FROM sc_ignored_users WHERE uuid = ?", user.getUUID().toString());
stm.executeUpdateQuery("DELETE FROM sc_ignored_users WHERE uuid = ?", user.getUUID().toString());
for (UUID entry : user.getIgnoredUsers()) {
stm.executeUpdate("INSERT INTO sc_ignored_users (uuid, user) VALUES (?, ?)",
stm.executeUpdateQuery("INSERT INTO sc_ignored_users (uuid, user) VALUES (?, ?)",
user.getUUID().toString(), entry.toString());
}
@@ -32,6 +32,10 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
@Override
public @Nullable TextColor getColor() {
if (color == null) {
return null;
}
return TextColor.fromHexString(color);
}
+1
View File
@@ -76,6 +76,7 @@ language:
player-joined: '%player_displayname% has joined <server>!'
vote-received: '<name> has voted on <service>!'
cannot-use-channel: "You cannot use that channel!"
channel-color-set: "<green>You have set <color><channel> <green>color to <hex>!"
server-name: 'Server'