mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Move nickname settings to a section
This commit is contained in:
6 files changed
+88
-43
No files matched your search
+3
-3
@@ -76,7 +76,7 @@ public final class NicknameCommand extends CarbonCommand {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (!this.config.primaryConfig().useCarbonNicknames()) {
|
||||
if (!this.config.primaryConfig().nickname().useCarbonNicknames()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -132,8 +132,8 @@ public final class NicknameCommand extends CarbonCommand {
|
||||
|
||||
// If the nickname is caught in the character limit, return without setting a nickname.
|
||||
final int nickNameLength = PlainTextComponentSerializer.plainText().serialize(parsedNick.get()).length();
|
||||
final int minLength = this.config.primaryConfig().nicknameMinLength();
|
||||
final int maxLength = this.config.primaryConfig().nicknameMaxLength();
|
||||
final int minLength = this.config.primaryConfig().nickname().minLength();
|
||||
final int maxLength = this.config.primaryConfig().nickname().maxLength();
|
||||
if (nickNameLength < minLength || maxLength < nickNameLength) {
|
||||
this.carbonMessages.nicknameErrorCharacterLimit(sender, parsedNick.get(), minLength, maxLength);
|
||||
return;
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||
import org.spongepowered.configurate.loader.ConfigurationLoader;
|
||||
|
||||
@@ -133,6 +134,10 @@ public final class ConfigManager {
|
||||
|
||||
try {
|
||||
final var node = loader.load();
|
||||
try {
|
||||
clazz.getDeclaredMethod("upgrade", ConfigurationNode.class).invoke(null, node);
|
||||
} catch (final NoSuchMethodException ignore) {
|
||||
}
|
||||
final @Nullable T config = node.get(clazz);
|
||||
if (config == null) {
|
||||
throw new ConfigurateException(node, "Failed to deserialize " + clazz.getName() + " from node");
|
||||
@@ -140,7 +145,7 @@ public final class ConfigManager {
|
||||
node.set(clazz, config);
|
||||
loader.save(node);
|
||||
return config;
|
||||
} catch (final ConfigurateException exception) {
|
||||
} catch (final ConfigurateException | ReflectiveOperationException exception) {
|
||||
this.logger.error("Failed to load config '{}'", file, exception);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -22,13 +22,19 @@ package net.draycia.carbon.common.config;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import net.draycia.carbon.common.util.Exceptions;
|
||||
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.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.NodePath;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
|
||||
|
||||
@ConfigSerializable
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@@ -38,34 +44,34 @@ public class PrimaryConfig {
|
||||
private Locale defaultLocale = Locale.US;
|
||||
|
||||
@Comment("""
|
||||
The default channel that new players will be in when they join.
|
||||
If the channel is not found or the player cannot use the channel, they will speak in basic non-channel chat.
|
||||
""")
|
||||
The default channel that new players will be in when they join.
|
||||
If the channel is not found or the player cannot use the channel, they will speak in basic non-channel chat.
|
||||
""")
|
||||
private Key defaultChannel = Key.key("carbon", "global");
|
||||
|
||||
@Comment("""
|
||||
The service that will be used to store and load player information.
|
||||
One of: JSON, H2, MYSQL, PSQL
|
||||
Note: If you choose MYSQL or PSQL make sure you configure the "database-settings" section of this file!
|
||||
""")
|
||||
The service that will be used to store and load player information.
|
||||
One of: JSON, H2, MYSQL, PSQL
|
||||
Note: If you choose MYSQL or PSQL make sure you configure the "database-settings" section of this file!
|
||||
""")
|
||||
private StorageType storageType = StorageType.JSON;
|
||||
|
||||
@Comment("""
|
||||
When "storage-type" is set to MYSQL or PSQL, this section configures the database connection.
|
||||
If JSON or H2 storage is used, this section can be ignored.
|
||||
""")
|
||||
When "storage-type" is set to MYSQL or PSQL, this section configures the database connection.
|
||||
If JSON or H2 storage is used, this section can be ignored.
|
||||
""")
|
||||
private DatabaseSettings databaseSettings = new DatabaseSettings();
|
||||
|
||||
@Comment("Various ClearChat command settings.")
|
||||
private ClearChatSettings clearChatSettings = new ClearChatSettings();
|
||||
|
||||
@Comment("""
|
||||
Plugin-wide custom placeholders.
|
||||
These will be parsed in all messages rendered and sent by Carbon.
|
||||
This includes chat, command feedback, and others.
|
||||
Make sure to close your tags so they do not bleed into other formats.
|
||||
Only a single pass is done so custom placeholders will not work within each other.
|
||||
""")
|
||||
Plugin-wide custom placeholders.
|
||||
These will be parsed in all messages rendered and sent by Carbon.
|
||||
This includes chat, command feedback, and others.
|
||||
Make sure to close your tags so they do not bleed into other formats.
|
||||
Only a single pass is done so custom placeholders will not work within each other.
|
||||
""")
|
||||
private Map<String, String> customPlaceholders = Map.of();
|
||||
|
||||
@Comment("The suggestions shown when using the TAB key in chat.")
|
||||
@@ -89,15 +95,11 @@ public class PrimaryConfig {
|
||||
);
|
||||
|
||||
private MessagingSettings messagingSettings = new MessagingSettings();
|
||||
private NicknameSettings nicknameSettings = new NicknameSettings();
|
||||
|
||||
@Comment("Whether Carbon's nickname management should be used. Disable this if you wish to have another plugin manage nicknames.")
|
||||
private boolean useCarbonNicknames = true;
|
||||
|
||||
@Comment("Minimum number of characters in nickname.")
|
||||
private int nicknameMinLength = 3;
|
||||
|
||||
@Comment("Maximum number of characters in nickname.")
|
||||
private int nicknameMaxLength = 16;
|
||||
public NicknameSettings nickname() {
|
||||
return this.nicknameSettings;
|
||||
}
|
||||
|
||||
@Comment("Whether Carbon should check for updates using the GitHub API on startup.")
|
||||
private boolean updateChecker = true;
|
||||
@@ -178,22 +180,58 @@ public class PrimaryConfig {
|
||||
return this.messageSound;
|
||||
}
|
||||
|
||||
public boolean useCarbonNicknames() {
|
||||
return this.useCarbonNicknames;
|
||||
}
|
||||
|
||||
public int nicknameMinLength() {
|
||||
return this.nicknameMinLength;
|
||||
}
|
||||
|
||||
public int nicknameMaxLength() {
|
||||
return this.nicknameMaxLength;
|
||||
}
|
||||
|
||||
public boolean updateChecker() {
|
||||
return this.updateChecker;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void upgrade(final ConfigurationNode node) {
|
||||
final ConfigurationTransformation.VersionedBuilder builder = ConfigurationTransformation.versionedBuilder()
|
||||
.versionKey("config-version");
|
||||
final ConfigurationTransformation initial = ConfigurationTransformation.builder()
|
||||
.addAction(NodePath.path("use-carbon-nicknames"), (path, value) -> new Object[]{"nickname-settings", "use-carbon-nicknames"})
|
||||
.build();
|
||||
builder.addVersion(0, initial);
|
||||
final ConfigurationTransformation.Versioned upgrader = builder.build();
|
||||
final int from = upgrader.version(node);
|
||||
try {
|
||||
upgrader.apply(node);
|
||||
} catch (final ConfigurateException e) {
|
||||
Exceptions.rethrow(e);
|
||||
}
|
||||
if (from == ConfigurationTransformation.Versioned.VERSION_UNKNOWN) {
|
||||
final ConfigurationNode versionNode = node.node(upgrader.versionKey());
|
||||
if (versionNode instanceof CommentedConfigurationNode commented) {
|
||||
commented.comment("Used internally to track changes to the config. Do not edit manually!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public static final class NicknameSettings {
|
||||
|
||||
@Comment("Minimum number of characters in nickname (excluding formatting).")
|
||||
private int minLength = 3;
|
||||
|
||||
@Comment("Maximum number of characters in nickname (excluding formatting).")
|
||||
private int maxLength = 16;
|
||||
|
||||
@Comment("Whether Carbon's nickname management should be used. Disable this if you wish to have another plugin manage nicknames.")
|
||||
private boolean useCarbonNicknames = true;
|
||||
|
||||
public boolean useCarbonNicknames() {
|
||||
return this.useCarbonNicknames;
|
||||
}
|
||||
|
||||
public int minLength() {
|
||||
return this.minLength;
|
||||
}
|
||||
|
||||
public int maxLength() {
|
||||
return this.maxLength;
|
||||
}
|
||||
}
|
||||
|
||||
public enum StorageType {
|
||||
JSON,
|
||||
MYSQL,
|
||||
|
||||
@@ -170,7 +170,7 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
|
||||
@Override
|
||||
public @Nullable Component nickname() {
|
||||
if (!this.config.primaryConfig().useCarbonNicknames()) {
|
||||
if (!this.config.primaryConfig().nickname().useCarbonNicknames()) {
|
||||
return null;
|
||||
}
|
||||
return this.displayName.orNull();
|
||||
@@ -437,7 +437,7 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
|
||||
@Override
|
||||
public boolean hasNickname() {
|
||||
if (!this.config.primaryConfig().useCarbonNicknames()) {
|
||||
if (!this.config.primaryConfig().nickname().useCarbonNicknames()) {
|
||||
return false;
|
||||
}
|
||||
return this.displayName.hasValue();
|
||||
|
||||
@@ -271,6 +271,8 @@ public final class DatabaseUserManager extends CachingUserManager {
|
||||
}
|
||||
|
||||
private record CarbonLogCreator(Logger logger) implements LogCreator {
|
||||
|
||||
@Override
|
||||
public Log createLogger(final Class<?> clazz) {
|
||||
final Logger l = this.logger;
|
||||
return new Log() {
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class CarbonPlayerPaper extends WrappedCarbonPlayer implements Forw
|
||||
) {
|
||||
super(carbonPlayerCommon);
|
||||
|
||||
if (config.primaryConfig().useCarbonNicknames()) {
|
||||
if (config.primaryConfig().nickname().useCarbonNicknames()) {
|
||||
this.player().ifPresent(this.applyDisplayNameToBukkit(carbonPlayerCommon.nickname()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user