mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Fix regression with channel radius being constantly reset
This commit is contained in:
3 files changed
+37
-43
No files matched your search
+21
-35
@@ -70,7 +70,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.NodePath;
|
|
||||||
import org.spongepowered.configurate.loader.ConfigurationLoader;
|
import org.spongepowered.configurate.loader.ConfigurationLoader;
|
||||||
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
|
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
|
||||||
|
|
||||||
@@ -126,44 +125,32 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
|||||||
events.subscribe(CarbonReloadEvent.class, -99, true, event -> this.reloadConfigChannels());
|
events.subscribe(CarbonReloadEvent.class, -99, true, event -> this.reloadConfigChannels());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigurationTransformation.Versioned versioned() {
|
public static ConfigurationTransformation.Versioned configChatChannelUpgrader() {
|
||||||
|
// final ConfigurationTransformation initial;
|
||||||
|
|
||||||
return ConfigurationTransformation.versionedBuilder()
|
return ConfigurationTransformation.versionedBuilder()
|
||||||
.addVersion(0, initialTransform())
|
.versionKey(ConfigManager.CONFIG_VERSION_KEY)
|
||||||
|
// .addVersion(0, initial)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConfigurationTransformation initialTransform() {
|
public static <N extends ConfigurationNode> N upgradeConfigChatChannelNode(final N node) throws ConfigurateException {
|
||||||
return ConfigurationTransformation.builder()
|
if (true) {
|
||||||
.addAction(NodePath.path(), (path, value) -> {
|
// No transformations yet!
|
||||||
value.node("radius").set(-1);
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/SpongePowered/Configurate/blob/1ec74f6474237585aee858b636d9761d237839d5/examples/src/main/java/org/spongepowered/configurate/examples/Transformations.java#L107
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply the transformations to a node.
|
|
||||||
*
|
|
||||||
* <p>This method also prints information about the version update that
|
|
||||||
* occurred</p>
|
|
||||||
*
|
|
||||||
* @param node the node to transform
|
|
||||||
* @param <N> node type
|
|
||||||
* @return provided node, after transformation
|
|
||||||
*/
|
|
||||||
public static <N extends ConfigurationNode> N updateNode(final N node) throws ConfigurateException {
|
|
||||||
if (!node.virtual()) { // we only want to migrate existing data
|
if (!node.virtual()) { // we only want to migrate existing data
|
||||||
final ConfigurationTransformation.Versioned trans = versioned();
|
final ConfigurationTransformation.Versioned upgrader = configChatChannelUpgrader();
|
||||||
final int startVersion = trans.version(node);
|
final int from = upgrader.version(node);
|
||||||
trans.apply(node);
|
upgrader.apply(node);
|
||||||
final int endVersion = trans.version(node);
|
final int to = upgrader.version(node);
|
||||||
|
|
||||||
if (startVersion != endVersion) { // we might not have made any changes
|
ConfigManager.configVersionComment(node, upgrader);
|
||||||
|
|
||||||
|
if (from != to) { // we might not have made any changes
|
||||||
// TODO: use logger
|
// TODO: use logger
|
||||||
//CarbonChatProvider.carbonChat().logger().info("Updated config schema from " + startVersion + " to " + endVersion);
|
//CarbonChatProvider.carbonChat().logger().info("Updated config schema from " + from + " to " + to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,15 +302,14 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
|||||||
final Class<? extends ConfigChatChannel> type = special == null ? ConfigChatChannel.class : special.cls();
|
final Class<? extends ConfigChatChannel> type = special == null ? ConfigChatChannel.class : special.cls();
|
||||||
|
|
||||||
final ConfigurationLoader<?> loader = this.config.configurationLoader(channelFile, ConfigManager.extractHeader(type));
|
final ConfigurationLoader<?> loader = this.config.configurationLoader(channelFile, ConfigManager.extractHeader(type));
|
||||||
final ConfigurationNode loaded = updateNode(loader.load());
|
final ConfigurationNode loaded = upgradeConfigChatChannelNode(loader.load());
|
||||||
final @Nullable ConfigChatChannel channel = loaded.get(type);
|
final @Nullable ConfigChatChannel channel = loaded.get(type);
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
throw new ConfigurateException("Config deserialized to null.");
|
throw new ConfigurateException("Config deserialized to null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
final ConfigurationNode newNode = loader.createNode();
|
loaded.set(type, channel);
|
||||||
newNode.set(type, channel);
|
loader.save(loaded);
|
||||||
loader.save(newNode);
|
|
||||||
|
|
||||||
return channel;
|
return channel;
|
||||||
} catch (final ConfigurateException exception) {
|
} catch (final ConfigurateException exception) {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
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.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||||
import org.spongepowered.configurate.CommentedConfigurationNodeIntermediary;
|
import org.spongepowered.configurate.CommentedConfigurationNodeIntermediary;
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
@@ -50,11 +51,13 @@ import org.spongepowered.configurate.loader.ConfigurationLoader;
|
|||||||
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
||||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||||
import org.spongepowered.configurate.objectmapping.meta.Processor;
|
import org.spongepowered.configurate.objectmapping.meta.Processor;
|
||||||
|
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
@Singleton
|
@Singleton
|
||||||
public final class ConfigManager {
|
public final class ConfigManager {
|
||||||
|
|
||||||
|
public static final String CONFIG_VERSION_KEY = "config-version";
|
||||||
private static final String PRIMARY_CONFIG_FILE_NAME = "config.conf";
|
private static final String PRIMARY_CONFIG_FILE_NAME = "config.conf";
|
||||||
private static final String COMMAND_SETTINGS_FILE_NAME = "command-settings.conf";
|
private static final String COMMAND_SETTINGS_FILE_NAME = "command-settings.conf";
|
||||||
|
|
||||||
@@ -187,4 +190,14 @@ public final class ConfigManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <N extends ConfigurationNode> void configVersionComment(
|
||||||
|
final N rootNode,
|
||||||
|
final ConfigurationTransformation.Versioned versionedTransformation
|
||||||
|
) {
|
||||||
|
final ConfigurationNode versionNode = rootNode.node(versionedTransformation.versionKey());
|
||||||
|
if (!versionNode.virtual() && versionNode instanceof CommentedConfigurationNode commented) {
|
||||||
|
commented.comment("Used internally to track changes to the config. Do not edit manually!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,6 @@ import net.kyori.adventure.sound.Sound;
|
|||||||
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.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.NodePath;
|
import org.spongepowered.configurate.NodePath;
|
||||||
@@ -186,7 +185,7 @@ public class PrimaryConfig {
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static void upgrade(final ConfigurationNode node) {
|
public static void upgrade(final ConfigurationNode node) {
|
||||||
final ConfigurationTransformation.VersionedBuilder builder = ConfigurationTransformation.versionedBuilder()
|
final ConfigurationTransformation.VersionedBuilder builder = ConfigurationTransformation.versionedBuilder()
|
||||||
.versionKey("config-version");
|
.versionKey(ConfigManager.CONFIG_VERSION_KEY);
|
||||||
final ConfigurationTransformation initial = ConfigurationTransformation.builder()
|
final ConfigurationTransformation initial = ConfigurationTransformation.builder()
|
||||||
.addAction(NodePath.path("use-carbon-nicknames"), (path, value) -> new Object[]{"nickname-settings", "use-carbon-nicknames"})
|
.addAction(NodePath.path("use-carbon-nicknames"), (path, value) -> new Object[]{"nickname-settings", "use-carbon-nicknames"})
|
||||||
.build();
|
.build();
|
||||||
@@ -202,12 +201,8 @@ public class PrimaryConfig {
|
|||||||
} catch (final ConfigurateException e) {
|
} catch (final ConfigurateException e) {
|
||||||
Exceptions.rethrow(e);
|
Exceptions.rethrow(e);
|
||||||
}
|
}
|
||||||
if (from == ConfigurationTransformation.Versioned.VERSION_UNKNOWN) {
|
|
||||||
final ConfigurationNode versionNode = node.node(upgrader.versionKey());
|
ConfigManager.configVersionComment(node, upgrader);
|
||||||
if (versionNode instanceof CommentedConfigurationNode commented) {
|
|
||||||
commented.comment("Used internally to track changes to the config. Do not edit manually!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
|
|||||||
Reference in new issue
Block a user