From 3878be35637c9b84f2be957e3433e24104f4fe6c Mon Sep 17 00:00:00 2001 From: Draycia Date: Tue, 22 Sep 2020 23:59:12 -0700 Subject: [PATCH] It compiles! --- .../carbon/api/config/CarbonSettings.java | 104 ++++++++++++++++-- .../net/draycia/carbon/util/CarbonUtils.java | 5 - .../common/listeners/events/PingHandler.java | 14 +-- .../listeners/events/PlayerJoinListener.java | 2 +- .../listeners/events/WhisperPingHandler.java | 10 +- .../carbon/common/users/JSONUserService.java | 1 - 6 files changed, 110 insertions(+), 26 deletions(-) diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/CarbonSettings.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/CarbonSettings.java index 697f7146..7ec0eb57 100644 --- a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/CarbonSettings.java +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/CarbonSettings.java @@ -1,20 +1,30 @@ package net.draycia.carbon.api.config; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.sound.Sound; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.configurate.objectmapping.Setting; +import org.spongepowered.configurate.serialize.ConfigSerializable; +import java.util.HashMap; import java.util.List; import java.util.Map; +@ConfigSerializable public class CarbonSettings { - private @NonNull String spyPrefix; - private @NonNull String serverName; - private boolean showTips; - private @NonNull List<@NonNull ChannelSettings> channelSettings; - private @Nullable StorageType storageType; - private @NonNull SQLCredentials sqlCredentials; - private @NonNull Map<@Nullable String, @NonNull String> customPlaceholders; + @Setting private @NonNull String spyPrefix = "[SPY] "; + @Setting private @NonNull String serverName = "Server"; + @Setting private boolean showTips = true; + @Setting private @NonNull List<@NonNull ChannelSettings> channelSettings; // TODO: unfuck this, it's loaded from file? + @Setting private @Nullable StorageType storageType = StorageType.JSON; + @Setting private @NonNull SQLCredentials sqlCredentials = + new SQLCredentials("username", "password", "db", "localhost", 3306); + @Setting private @NonNull Map<@Nullable String, @NonNull String> customPlaceholders = new HashMap<>(); + @Setting private @NonNull Pings pings = new Pings(); + @Setting private @NonNull WhisperPings whisperPings = new WhisperPings(); + @Setting private @Nullable String channelOnJoin = ""; public @NonNull String spyPrefix() { return this.spyPrefix; @@ -44,9 +54,89 @@ public class CarbonSettings { return this.customPlaceholders; } + public @Nullable String channelOnJoin() { + return this.channelOnJoin; + } + + public @NonNull Pings pings() { + return this.pings; + } + + public @NonNull WhisperPings whisperPings() { + return this.whisperPings; + } + public enum StorageType { MYSQL, JSON } + @ConfigSerializable + public final class WhisperPings { + @Setting private boolean enabled = true; + @Setting private @NonNull Key sound = Key.of(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup"); + @Setting private Sound.Source source = Sound.Source.PLAYER; + @Setting private float volume = 10.0F; + @Setting private float pitch = 1.0F; + + public boolean enabled() { + return this.enabled; + } + + public Key sound() { + return this.sound; + } + + public Sound.Source source() { + return this.source; + } + + public float volume() { + return this.volume; + } + + public float pitch() { + return this.pitch; + } + } + + @ConfigSerializable + public final class Pings { + @Setting private boolean enabled = true; + @Setting private @NonNull String prefix = ""; + @Setting private boolean caseSensitive = false; + @Setting private @NonNull Key sound = Key.of(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup"); + @Setting private Sound.Source source = Sound.Source.PLAYER; + @Setting private float volume = 10.0F; + @Setting private float pitch = 1.0F; + + public boolean enabled() { + return this.enabled; + } + + public String prefix() { + return this.prefix; + } + + public boolean caseSensitive() { + return this.caseSensitive; + } + + public Key sound() { + return this.sound; + } + + public Sound.Source source() { + return this.source; + } + + public float volume() { + return this.volume; + } + + public float pitch() { + return this.pitch; + } + } + } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonUtils.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonUtils.java index 1fd2feb6..06c901ef 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonUtils.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonUtils.java @@ -20,13 +20,9 @@ */ package net.draycia.carbon.util; -import me.clip.placeholderapi.PlaceholderAPI; -import net.draycia.carbon.api.users.ChatUser; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.serializer.bungeecord.BungeeCordComponentSerializer; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; @@ -37,7 +33,6 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayList; import java.util.List; diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/PingHandler.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/PingHandler.java index c7f8ace5..ef55946a 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/PingHandler.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/PingHandler.java @@ -14,7 +14,7 @@ public class PingHandler { final CarbonChat carbonChat = CarbonChatProvider.carbonChat(); CarbonEvents.register(ChatComponentEvent.class, PostOrders.LAST, false, event -> { - if (!carbonChat.getConfig().getBoolean("pings.enabled")) { + if (!carbonChat.carbonSettings().pings().enabled()) { return; } @@ -23,8 +23,8 @@ public class PingHandler { } final String targetName = event.target().name(); - final String prefix = carbonChat.getConfig().getString("pings.prefix", ""); - final boolean caseSensitive = carbonChat.getConfig().getBoolean("pings.case-sensitive", false); + final String prefix = carbonChat.carbonSettings().pings().prefix(); + final boolean caseSensitive = carbonChat.carbonSettings().pings().caseSensitive(); if (caseSensitive) { if (!event.originalMessage().contains(prefix + targetName)) { @@ -36,10 +36,10 @@ public class PingHandler { } } - final Key key = Key.of(carbonChat.getConfig().getString("pings.sound")); - final Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("pings.source")); - final float volume = (float) carbonChat.getConfig().getDouble("pings.volume"); - final float pitch = (float) carbonChat.getConfig().getDouble("pings.pitch"); + final Key key = carbonChat.carbonSettings().pings().sound(); + final Sound.Source source = carbonChat.carbonSettings().pings().source(); + final float volume = carbonChat.carbonSettings().pings().volume(); + final float pitch = carbonChat.carbonSettings().pings().pitch(); event.target().playSound(Sound.of(key, source, volume, pitch)); }); diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/PlayerJoinListener.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/PlayerJoinListener.java index 8c552e4f..c2066c96 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/PlayerJoinListener.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/PlayerJoinListener.java @@ -21,7 +21,7 @@ public class PlayerJoinListener { user.nickname(user.nickname()); } - final String channel = carbonChat.getConfig().getString("channel-on-join"); + final String channel = carbonChat.carbonSettings().channelOnJoin(); if (channel == null || channel.isEmpty()) { return; diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/WhisperPingHandler.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/WhisperPingHandler.java index b532a8a4..a2c6aa77 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/WhisperPingHandler.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/listeners/events/WhisperPingHandler.java @@ -22,14 +22,14 @@ public class WhisperPingHandler { return; } - if (!carbonChat.getConfig().getBoolean("whisper.pings.enabled")) { + if (!carbonChat.carbonSettings().whisperPings().enabled()) { return; } - final Key key = Key.of(carbonChat.getConfig().getString("whisper.pings.sound")); - final Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("whisper.pings.source")); - final float volume = (float) carbonChat.getConfig().getDouble("whisper.pings.volume"); - final float pitch = (float) carbonChat.getConfig().getDouble("whisper.pings.pitch"); + final Key key = carbonChat.carbonSettings().whisperPings().sound(); + final Sound.Source source = carbonChat.carbonSettings().whisperPings().source(); + final float volume = carbonChat.carbonSettings().whisperPings().volume(); + final float pitch = carbonChat.carbonSettings().whisperPings().pitch(); event.sender().playSound(Sound.of(key, source, volume, pitch)); }); diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/users/JSONUserService.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/users/JSONUserService.java index 4924adf8..648e4b3e 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/users/JSONUserService.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/users/JSONUserService.java @@ -18,7 +18,6 @@ import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Type; import java.util.Timer; import java.util.TimerTask;