mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
More configuration progress
This commit is contained in:
1 parent
3878be3563
commit
f588f3b24b
13 files changed
+318
-256
No files matched your search
@@ -1,9 +1,10 @@
|
||||
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.BasicConfigurationNode;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
@@ -14,17 +15,77 @@ import java.util.Map;
|
||||
@ConfigSerializable
|
||||
public class CarbonSettings {
|
||||
|
||||
@Setting private @NonNull String spyPrefix = "<color>[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 =
|
||||
private static final ObjectMapper<CarbonSettings> MAPPER;
|
||||
|
||||
static {
|
||||
try {
|
||||
MAPPER = ObjectMapper.forClass(CarbonSettings.class); // We hold on to the instance of our ObjectMapper
|
||||
} catch (final ObjectMappingException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static CarbonSettings loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
return MAPPER.bindToNew().populate(node);
|
||||
}
|
||||
|
||||
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
MAPPER.bind(this).serialize(node);
|
||||
}
|
||||
|
||||
@Setting(comment = "The prefix shown when spying on a user's message")
|
||||
private @NonNull String spyPrefix = "<color>[SPY] ";
|
||||
|
||||
@Setting(comment = "Used for <server> placeholder in channel formats")
|
||||
private @NonNull String serverName = "Server";
|
||||
|
||||
@Setting(comment = "Set this to false to disable warnings and tips when the plugin thinks there may be configuration issues.")
|
||||
private boolean showTips = true;
|
||||
|
||||
@Setting(comment = "")
|
||||
private @NonNull List<@NonNull ChannelSettings> channelSettings; // TODO: unfuck this, it's loaded from file?
|
||||
|
||||
@Setting(comment = "Options: JSON, MYSQL")
|
||||
private @Nullable StorageType storageType = StorageType.JSON;
|
||||
|
||||
@Setting(comment = "The credentials used to connect to your database. Requires storageType=MYSQL")
|
||||
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 = "";
|
||||
|
||||
@Setting(comment = "Options: NONE, REDIS, BUNGEECORD")
|
||||
private @NonNull MessagingType messagingType = MessagingType.NONE;
|
||||
|
||||
@Setting(comment = " Options:\n" +
|
||||
" 'bungee' - Uses bungee plugin messaging, requires BungeeCord or another proxy which supports it (Velocity!)\n" +
|
||||
" 'redis' - Uses redis for cross server syncing, does not require a server proxy\n" +
|
||||
" 'none' - Do not sync anything cross server, this is the default\n" +
|
||||
"\n" +
|
||||
" Note: In order for channels to sync cross server, you'll need to enable is-cross-server for the\n" +
|
||||
" channel as well as this setting.")
|
||||
private @NonNull RedisCredentials redisCredentials =
|
||||
new RedisCredentials("localhost", "", 6379, 0);
|
||||
|
||||
@Setting(comment = "Used for message formats - custom tags that are replaced in descending order" +
|
||||
"\nFor example, in the default config, <group> wil be replaced with <green>%vault_group%")
|
||||
private @NonNull Map<@Nullable String, @NonNull String> customPlaceholders = new HashMap<String, String>() {
|
||||
{
|
||||
this.put("prefix", "<gray>[<group><gray>]");
|
||||
this.put("group", "<green>%vault_group%");
|
||||
}
|
||||
};
|
||||
|
||||
@Setting(comment = "Plays a sound and highlights the message when someone types your name")
|
||||
private @NonNull ChannelPings channelPings = new ChannelPings();
|
||||
|
||||
@Setting(comment = "Plays a sound when receiving private messages with /whisper /msg")
|
||||
private @NonNull WhisperPings whisperPings = new WhisperPings();
|
||||
|
||||
@Setting(comment = "Sets the player's channel to the specified channel when they join" +
|
||||
"\nSet to \"\" or remove to disable" +
|
||||
"\nSet to DEFAULT to set the player's channel to the default channel on join" +
|
||||
"\nOtherwise, set to a channel to set the player's channel to it on join" +
|
||||
"\nFor example, channel-on-join: \"global\" sets their channel to global on join")
|
||||
private @Nullable String channelOnJoin = "";
|
||||
|
||||
public @NonNull String spyPrefix() {
|
||||
return this.spyPrefix;
|
||||
@@ -50,6 +111,14 @@ public class CarbonSettings {
|
||||
return this.sqlCredentials;
|
||||
}
|
||||
|
||||
public @NonNull MessagingType messagingType() {
|
||||
return this.messagingType;
|
||||
}
|
||||
|
||||
public @NonNull RedisCredentials redisCredentials() {
|
||||
return this.redisCredentials;
|
||||
}
|
||||
|
||||
public Map<String, String> customPlaceholders() {
|
||||
return this.customPlaceholders;
|
||||
}
|
||||
@@ -58,85 +127,12 @@ public class CarbonSettings {
|
||||
return this.channelOnJoin;
|
||||
}
|
||||
|
||||
public @NonNull Pings pings() {
|
||||
return this.pings;
|
||||
public @NonNull ChannelPings channelPings() {
|
||||
return this.channelPings;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
@ConfigSerializable
|
||||
public final class ChannelPings {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
public enum MessagingType {
|
||||
NONE,
|
||||
REDIS,
|
||||
BUNGEECORD
|
||||
}
|
||||
@@ -1,11 +1,38 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import org.spongepowered.configurate.BasicConfigurationNode;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ConfigSerializable
|
||||
public class ModerationSettings {
|
||||
|
||||
private static final ObjectMapper<ModerationSettings> MAPPER;
|
||||
|
||||
static {
|
||||
try {
|
||||
MAPPER = ObjectMapper.forClass(ModerationSettings.class); // We hold on to the instance of our ObjectMapper
|
||||
} catch (final ObjectMappingException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static ModerationSettings loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
return MAPPER.bindToNew().populate(node);
|
||||
}
|
||||
|
||||
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
|
||||
MAPPER.bind(this).serialize(node);
|
||||
}
|
||||
|
||||
// TODO: comment this
|
||||
@Setting
|
||||
private String shadowMutePrefix = "[SM] ";
|
||||
@@ -83,4 +110,45 @@ public class ModerationSettings {
|
||||
}
|
||||
}
|
||||
|
||||
@Setting
|
||||
private Filters filters = new Filters();
|
||||
|
||||
public Filters filters() {
|
||||
return this.filters;
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public final class Filters {
|
||||
|
||||
@Setting
|
||||
private boolean enabled = true;
|
||||
|
||||
@Setting(comment = "The keys (\"****\" for example) are what the text is replaced with.\n" +
|
||||
"The strings in the lists (\"lag\" etc) are what's replaced.\n" +
|
||||
"Set to filters: {} if you want to disable the filter feature.\n" +
|
||||
"Set the key to \"_\" for the replacement to be blank (remove the filtered pattern).")
|
||||
private Map<String, List<Pattern>> replacements = new HashMap<String, List<Pattern>>() {
|
||||
{
|
||||
this.put("****", Collections.singletonList(Pattern.compile("la[g]+")));
|
||||
}
|
||||
};
|
||||
|
||||
@Setting(comment = "Anything in blocked-words will prevent the message from being sent at all.\n" +
|
||||
"Set to blocked-words: [] if you want to disable the blocked words feature.")
|
||||
private List<Pattern> blockedPatterns = Collections.singletonList(Pattern.compile("pineapple doesn't belong on pizza"));
|
||||
|
||||
public boolean enabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public Map<String, List<Pattern>> replacements() {
|
||||
return this.replacements;
|
||||
}
|
||||
|
||||
public List<Pattern> blockedPatterns() {
|
||||
return this.blockedPatterns;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class RedisCredentials {
|
||||
|
||||
private final @NonNull String host;
|
||||
private final @Nullable String password;
|
||||
private final int port;
|
||||
private final int database;
|
||||
|
||||
public RedisCredentials(final @NonNull String host, final @Nullable String password, final int port, final int database) {
|
||||
this.host = host;
|
||||
this.password = password;
|
||||
this.port = port;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public @NonNull String host() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public @Nullable String password() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public int port() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public int database() {
|
||||
return this.database;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
public enum StorageType {
|
||||
MYSQL,
|
||||
JSON
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
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.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user