diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/CarbonTranslations.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/CarbonTranslations.java index 9043eb76..114d70fc 100644 --- a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/CarbonTranslations.java +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/CarbonTranslations.java @@ -65,6 +65,8 @@ public final class CarbonTranslations { @Setting private String clearNotify = "Chat has been cleared by ."; @Setting private String clearExempt = "You were exempt from the clear due to your permissions!"; @Setting private String cannotWhisperSelf = "You cannot whisper yourself!"; + @Setting private String whisperPingChanged = "Whisper ping settings changed!"; + @Setting private String channelPingChanged = "Channel ping settings changed!"; public ExceptionMessages exceptionMessages() { return this.exceptionMessages; @@ -214,4 +216,12 @@ public final class CarbonTranslations { return this.cannotWhisperSelf; } + public String channelPingChanged() { + return this.channelPingChanged; + } + + public String whisperPingChanged() { + return this.whisperPingChanged; + } + } 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 cb43116f..71c69923 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 @@ -137,11 +137,11 @@ public interface PlayerUser extends CarbonUser { void pingOptions(@NonNull PingOptions pingOptions); - public static class PingOptions { + class PingOptions { public @Nullable Sound whisperSound; public @Nullable Sound pingSound; - public PingOptions(@Nullable Sound whisperSound, @Nullable Sound pingSound) { + public PingOptions(final @Nullable Sound whisperSound, final @Nullable Sound pingSound) { this.whisperSound = whisperSound; this.pingSound = pingSound; } @@ -150,7 +150,7 @@ public interface PlayerUser extends CarbonUser { return this.whisperSound; } - public void whisperSound(@Nullable Sound whisperSound) { + public void whisperSound(final @Nullable Sound whisperSound) { this.whisperSound = whisperSound; } @@ -158,7 +158,7 @@ public interface PlayerUser extends CarbonUser { return this.pingSound; } - public void pingSound(@Nullable Sound pingSound) { + public void pingSound(final @Nullable Sound pingSound) { this.pingSound = pingSound; } } 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 633c68ad..4434a7c6 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 @@ -48,13 +48,14 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single { private @Nullable String nickname = null; private @Nullable UUID replyTarget = null; private @Nullable TextColor customChatColor = null; + private @NonNull PingOptions pingOptions = new PingOptions(null, null); private @Nullable String selectedChannelKey = null; private transient @Nullable ChatChannel selectedChannel = null; private transient @NonNull Audience audience; - @SuppressWarnings("initialization.fields.uninitialized") + @SuppressWarnings({"initialization.fields.uninitialized", "method.invocation.invalid"}) public BukkitPlayerUser() { final CarbonChatBukkit carbonChatBukkit = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat"); @@ -97,6 +98,16 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single { return PlaceholderAPI.setPlaceholders(player, input); } + @Override + public @NonNull PingOptions pingOptions() { + return this.pingOptions; + } + + @Override + public void pingOptions(final @NonNull PingOptions pingOptions) { + this.pingOptions = pingOptions; + } + @Override public boolean online() { return Bukkit.getPlayer(this.uuid()) != null; diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/PingOptionsCommand.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/PingOptionsCommand.java index 6c554d45..b621a75d 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/PingOptionsCommand.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/commands/PingOptionsCommand.java @@ -32,13 +32,12 @@ public class PingOptionsCommand { commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(), commandManager.createDefaultCommandMeta()) .senderType(PlayerUser.class) // player - .permission("carbonchat.nickname") + .permission("carbonchat.pingoptions.channels") .argument(StaticArgument.of("channels")) .argument(EnumArgument.of(Sound.Source.class, "sound")) - //.argument(FloatArgument.newBuilder("volume").withMin(0).withMax(1).build()) // this doesn't work idk why - .argument(FloatArgument.of("volume")) - .argument(FloatArgument.of("pitch")) - .handler(this::setChannelOptions) + .argument(FloatArgument.newBuilder("volume").withMin(0).withMax(1).asRequired().build()) + .argument(FloatArgument.newBuilder("pitch").withMin(0).withMax(1).asRequired().build()) + .handler(this::channelOptions) .build() ); @@ -46,29 +45,30 @@ public class PingOptionsCommand { commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(), commandManager.createDefaultCommandMeta()) .senderType(PlayerUser.class) // player - .permission("carbonchat.nickname") + .permission("carbonchat.pingoptions.whispers") .argument(StaticArgument.of("whispers")) .argument(EnumArgument.of(Sound.Source.class, "sound")) - //.argument(FloatArgument.newBuilder("volume").withMin(0).withMax(1).build()) // this doesn't work idk why - .argument(FloatArgument.of("volume")) - .argument(FloatArgument.of("pitch")) - .handler(this::setWhisperOptions) + .argument(FloatArgument.newBuilder("volume").withMin(0).withMax(1).asRequired().build()) + .argument(FloatArgument.newBuilder("pitch").withMin(0).withMax(1).asRequired().build()) + .handler(this::whisperOptions) .build() ); } - private void setChannelOptions(CommandContext context) { + private void channelOptions(final @NonNull CommandContext context) { ((PlayerUser) context.getSender()).pingOptions().pingSound(Sound.sound(Key.key(context.get("sound")), Sound.Source.PLAYER, context.get("volume"), context.get("pitch"))); - // TODO: send message "your ping settings were changed!" + context.getSender().sendMessage(this.carbonChat.messageProcessor().processMessage( + this.carbonChat.translations().channelPingChanged())); } - private void setWhisperOptions(CommandContext context) { + private void whisperOptions(final @NonNull CommandContext context) { ((PlayerUser) context.getSender()).pingOptions().whisperSound(Sound.sound(Key.key(context.get("sound")), Sound.Source.PLAYER, context.get("volume"), context.get("pitch"))); - // TODO: send message "your whisper ping settings were changed!" + context.getSender().sendMessage(this.carbonChat.messageProcessor().processMessage( + this.carbonChat.translations().whisperPingChanged())); } } 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 9d59105a..f2325228 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 @@ -254,6 +254,34 @@ public class MySQLUserService imple } final Sound whisperSound = user.pingOptions().whisperSound(); + final String whisperName; + final Float whisperVolume; + final Float whisperPitch; + + if (whisperSound != null) { + whisperName = whisperSound.name().asString(); + whisperVolume = whisperSound.volume(); + whisperPitch = whisperSound.pitch(); + } else { + whisperName = null; + whisperVolume = null; + whisperPitch = null; + } + + final Sound channelSound = user.pingOptions().pingSound(); + final String channelName; + final Float channelVolume; + final Float channelPitch; + + if (channelSound != null) { + channelName = channelSound.name().asString(); + channelVolume = channelSound.volume(); + channelPitch = channelSound.pitch(); + } else { + channelName = null; + channelVolume = null; + channelPitch = null; + } this.carbonChat.logger().info("Saving user data!"); stm.executeUpdateQuery("INSERT INTO sc_users (uuid, channel, muted, shadowmuted, spyingwhispers, nickname, customchatcolor, whisperpingkey, whisperpingvolume " + @@ -262,9 +290,9 @@ public class MySQLUserService imple "whisperpingpitch = ?, channelpingkey = ?, channelpingvolume = ?, channelpingpitch = ?", user.uuid().toString(), selectedName, user.muted(), user.shadowMuted(), user.spyingWhispers(), user.nickname(), user.customChatColor(), - whisperSound.name().asString(), whisperSound.volume(), whisperSound.pitch(), + whisperName, whisperVolume, whisperPitch, channelName, channelVolume, channelPitch, selectedName, user.muted(), user.shadowMuted(), user.spyingWhispers(), user.nickname(), user.customChatColor(), - whisperSound.name().asString(), whisperSound.volume(), whisperSound.pitch()); + whisperName, whisperVolume, whisperPitch, channelName, channelVolume, channelPitch); this.carbonChat.logger().info("Saving user channel settings!"); // Save user channel settings