Configuration fixes

This commit is contained in:
Draycia committed 2020-09-25 01:45:36 -07:00
1 parent f549c47479
commit 3cd6abb6f7
8 files changed
+65 -63

No files matched your search

@@ -49,8 +49,7 @@ public class CarbonSettings {
private @Nullable StorageType storageType = StorageType.JSON; private @Nullable StorageType storageType = StorageType.JSON;
@Setting(comment = "The credentials used to connect to your database. Requires storageType=MYSQL") @Setting(comment = "The credentials used to connect to your database. Requires storageType=MYSQL")
private @NonNull SQLCredentials sqlCredentials = private @NonNull SQLCredentials sqlCredentials = new SQLCredentials();
new SQLCredentials("username", "password", "db", "localhost", 3306);
@Setting(comment = "Options: NONE, REDIS, BUNGEECORD") @Setting(comment = "Options: NONE, REDIS, BUNGEECORD")
private @NonNull MessagingType messagingType = MessagingType.NONE; private @NonNull MessagingType messagingType = MessagingType.NONE;
@@ -62,8 +61,7 @@ public class CarbonSettings {
"\n" + "\n" +
" Note: In order for channels to sync cross server, you'll need to enable is-cross-server for the\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.") " channel as well as this setting.")
private @NonNull RedisCredentials redisCredentials = private @NonNull RedisCredentials redisCredentials = new RedisCredentials();
new RedisCredentials("localhost", "", 6379, 0);
@Setting(comment = "Used for message formats - custom tags that are replaced in descending order" + @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%") "\nFor example, in the default config, <group> wil be replaced with <green>%vault_group%")
@@ -3,39 +3,45 @@ package net.draycia.carbon.api.config;
import net.draycia.carbon.api.Context; import net.draycia.carbon.api.Context;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ConfigSerializable
public class ChannelSettings { public class ChannelSettings {
private String key; @Setting private String key = "channel";
private String color; @Setting private String color = "#FFFFFF";
private Map<String, Context> contexts; @Setting private Map<String, Context> contexts = new HashMap<>(); // TODO: set defaults
private Map<String, String> formats; @Setting private Map<String, String> formats = new HashMap<>(); // TODO: set defaults
private String defaultFormatName; @Setting private String defaultFormatName = "default";
private boolean isDefault; @Setting private boolean isDefault = false;
private boolean ignorable; @Setting private boolean ignorable = true;
private boolean crossServer; @Setting private boolean crossServer = true;
private boolean honorsRecipientList; @Setting private boolean honorsRecipientList = false;
private boolean permissionGroupMatching; @Setting private boolean permissionGroupMatching = false;
private List<String> groupOverrides; @Setting private List<String> groupOverrides = new ArrayList<>();
private String name; @Setting private String name;
private String messagePrefix; @Setting private String messagePrefix;
private String switchMessage; @Setting private List<Pattern> itemLinkPatterns = Collections.singletonList(Pattern.compile(Pattern.quote("[item]")));
private List<Pattern> itemLinkPatterns; @Setting private List<String> aliases;
private String switchOtherMessage; @Setting private boolean shouldCancelChatEvent = false;
private List<String> aliases; @Setting private boolean primaryGroupOnly = false;
private boolean shouldCancelChatEvent; @Setting private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
private boolean primaryGroupOnly; @Setting private String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
private String cannotUseMessage; @Setting private String switchFailureMessage = "<red>You cannot use channel <channel>!";
private String toggleOtherOffMessage; @Setting private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
private String toggleOtherOnMessage; @Setting private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
private String toggleOnMessage; @Setting private String toggleOtherOnMessage = "<gray><player> <reset><gray>can now see <color><channel> <gray>chat!";
private String toggleOffMessage; @Setting private String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
private String cannotIgnoreMessage; @Setting private String cannotUseMessage = "You cannot use that channel!";
private String switchFailureMessage; @Setting private String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
@NonNull @NonNull
public String key() { public String key() {
@@ -1,5 +1,8 @@
package net.draycia.carbon.api.config; package net.draycia.carbon.api.config;
import org.spongepowered.configurate.serialize.ConfigSerializable;
@ConfigSerializable
public enum MessagingType { public enum MessagingType {
NONE, NONE,
REDIS, REDIS,
@@ -2,20 +2,16 @@ package net.draycia.carbon.api.config;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
@ConfigSerializable
public class RedisCredentials { public class RedisCredentials {
private final @NonNull String host; @Setting private @NonNull String host = "localhost";
private final @Nullable String password; @Setting private @Nullable String password = "";
private final int port; @Setting private int port = 6379;
private final int database; @Setting private int database = 0;
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() { public @NonNull String host() {
return this.host; return this.host;
@@ -1,23 +1,17 @@
package net.draycia.carbon.api.config; package net.draycia.carbon.api.config;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
@ConfigSerializable
public class SQLCredentials { public class SQLCredentials {
private final @NonNull String username; @Setting private @NonNull String username = "username";
private final @NonNull String password; @Setting private @NonNull String password = "password";
private final @NonNull String database; @Setting private @NonNull String database = "database";
private final @NonNull String host; @Setting private @NonNull String host = "host";
private final int port; @Setting private int port = 3306;
public SQLCredentials(final @NonNull String username, final @NonNull String password,
final @NonNull String database, final @NonNull String host, final int port) {
this.username = username;
this.password = password;
this.database = database;
this.host = host;
this.port = port;
}
public @NonNull String username() { public @NonNull String username() {
return this.username; return this.username;
@@ -1,5 +1,8 @@
package net.draycia.carbon.api.config; package net.draycia.carbon.api.config;
import org.spongepowered.configurate.serialize.ConfigSerializable;
@ConfigSerializable
public enum StorageType { public enum StorageType {
MYSQL, MYSQL,
JSON JSON
@@ -8,10 +8,8 @@ import org.spongepowered.configurate.serialize.ConfigSerializable;
@ConfigSerializable @ConfigSerializable
public final class WhisperPings { public final class WhisperPings {
@Setting @Setting private boolean enabled = true;
private boolean enabled = true; @Setting private @NonNull Key sound = Key.of(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup");
@Setting private @NonNull
Key sound = Key.of(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup");
@Setting private Sound.Source source = Sound.Source.PLAYER; @Setting private Sound.Source source = Sound.Source.PLAYER;
@Setting private float volume = 10.0F; @Setting private float volume = 10.0F;
@Setting private float pitch = 1.0F; @Setting private float pitch = 1.0F;
@@ -232,7 +232,8 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
final BasicConfigurationNode settingsNode = settingsLoader.load(); final BasicConfigurationNode settingsNode = settingsLoader.load();
this.carbonSettings = CarbonSettings.loadFrom(settingsNode); this.carbonSettings = CarbonSettings.loadFrom(settingsNode);
settingsLoader.save(settingsNode); settingsLoader.save(settingsNode);
} catch (final IOException | ObjectMappingException ignored) { } catch (final IOException | ObjectMappingException exception) {
exception.printStackTrace();
} }
} }
@@ -244,7 +245,8 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
final BasicConfigurationNode languageNode = languageLoader.load(); final BasicConfigurationNode languageNode = languageLoader.load();
this.translations = CarbonTranslations.loadFrom(languageNode); this.translations = CarbonTranslations.loadFrom(languageNode);
languageLoader.save(languageNode); languageLoader.save(languageNode);
} catch (final IOException | ObjectMappingException ignored) { } catch (final IOException | ObjectMappingException exception) {
exception.printStackTrace();
} }
} }
@@ -256,7 +258,8 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
final BasicConfigurationNode moderationNode = moderationLoader.load(); final BasicConfigurationNode moderationNode = moderationLoader.load();
this.moderationSettings = ModerationSettings.loadFrom(moderationNode); this.moderationSettings = ModerationSettings.loadFrom(moderationNode);
moderationLoader.save(moderationNode); moderationLoader.save(moderationNode);
} catch (final IOException | ObjectMappingException ignored) { } catch (final IOException | ObjectMappingException exception) {
exception.printStackTrace();
} }
} }
@@ -275,7 +278,8 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
final BasicConfigurationNode commandSettingsNode = commandSettingsLoader.load(); final BasicConfigurationNode commandSettingsNode = commandSettingsLoader.load();
this.commandSettings = CommandSettingsRegistry.loadFrom(commandSettingsNode); this.commandSettings = CommandSettingsRegistry.loadFrom(commandSettingsNode);
commandSettingsLoader.save(commandSettingsNode); commandSettingsLoader.save(commandSettingsNode);
} catch (final IOException | ObjectMappingException ignored) { } catch (final IOException | ObjectMappingException exception) {
exception.printStackTrace();
} }
} }