diff --git a/invalid/main/java/org/spongepowered/common/command/SpongeCommandFactory.java b/invalid/main/java/org/spongepowered/common/command/SpongeCommandFactory.java index 6c1c3c56b26..0c814c61c8a 100644 --- a/invalid/main/java/org/spongepowered/common/command/SpongeCommandFactory.java +++ b/invalid/main/java/org/spongepowered/common/command/SpongeCommandFactory.java @@ -98,12 +98,12 @@ import org.spongepowered.common.bridge.world.WorldInfoBridge; import org.spongepowered.common.bridge.world.chunk.ChunkBridge; import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.category.MetricsCategory; -import org.spongepowered.common.config.type.ConfigBase; -import org.spongepowered.common.config.type.DimensionConfig; -import org.spongepowered.common.config.type.GlobalConfig; -import org.spongepowered.common.config.type.TrackerConfig; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.inheritable.category.MetricsCategory; +import org.spongepowered.common.config.inheritable.ConfigBase; +import org.spongepowered.common.config.inheritable.DimensionConfig; +import org.spongepowered.common.config.inheritable.GlobalConfig; +import org.spongepowered.common.config.inheritable.TrackerConfig; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.entity.EntityUtil; import org.spongepowered.common.event.SpongeEventManager; import org.spongepowered.common.mixin.core.world.WorldAccessor; diff --git a/invalid/main/java/org/spongepowered/common/mixin/invalid/core/world/gen/ServerChunkProviderMixin.java b/invalid/main/java/org/spongepowered/common/mixin/invalid/core/world/gen/ServerChunkProviderMixin.java index 75b2e160d36..63c0b195e7d 100644 --- a/invalid/main/java/org/spongepowered/common/mixin/invalid/core/world/gen/ServerChunkProviderMixin.java +++ b/invalid/main/java/org/spongepowered/common/mixin/invalid/core/world/gen/ServerChunkProviderMixin.java @@ -55,7 +55,7 @@ import org.spongepowered.common.bridge.world.chunk.ChunkBridge; import org.spongepowered.common.bridge.world.chunk.ServerChunkProviderBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.category.WorldCategory; +import org.spongepowered.common.config.inheritable.category.WorldCategory; import org.spongepowered.common.event.tracking.IPhaseState; import org.spongepowered.common.event.tracking.PhaseContext; import org.spongepowered.common.event.tracking.PhasePrinter; diff --git a/invalid/main/java/org/spongepowered/common/mixin/invalid/core/world/spawner/WorldEntitySpawnerMixin.java b/invalid/main/java/org/spongepowered/common/mixin/invalid/core/world/spawner/WorldEntitySpawnerMixin.java index 71f53a63298..746a1ad603d 100644 --- a/invalid/main/java/org/spongepowered/common/mixin/invalid/core/world/spawner/WorldEntitySpawnerMixin.java +++ b/invalid/main/java/org/spongepowered/common/mixin/invalid/core/world/spawner/WorldEntitySpawnerMixin.java @@ -60,7 +60,7 @@ import org.spongepowered.common.bridge.world.chunk.ChunkBridge; import org.spongepowered.common.bridge.world.chunk.AbstractChunkProviderBridge; import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.event.tracking.PhaseContext; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.common.event.tracking.phase.generation.GenerationPhase; diff --git a/invalid/main/java/org/spongepowered/common/mixin/invalid/optimization/world/gen/structure/MapGenStructureMixin_Structure_Saving.java b/invalid/main/java/org/spongepowered/common/mixin/invalid/optimization/world/gen/structure/MapGenStructureMixin_Structure_Saving.java index cef50dbd7a7..63154829a82 100644 --- a/invalid/main/java/org/spongepowered/common/mixin/invalid/optimization/world/gen/structure/MapGenStructureMixin_Structure_Saving.java +++ b/invalid/main/java/org/spongepowered/common/mixin/invalid/optimization/world/gen/structure/MapGenStructureMixin_Structure_Saving.java @@ -42,8 +42,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.SpongeImplHooks; -import org.spongepowered.common.config.category.StructureModCategory; -import org.spongepowered.common.config.category.StructureSaveCategory; +import org.spongepowered.common.config.inheritable.category.StructureModCategory; +import org.spongepowered.common.config.inheritable.category.StructureSaveCategory; import javax.annotation.Nullable; import java.util.Locale; @@ -150,4 +150,4 @@ protected void initializeStructureData(final World worldIn) } } } -} \ No newline at end of file +} diff --git a/invalid/main/java/org/spongepowered/common/mixin/invalid/plugin/entityactivation/EntityActivationRange.java b/invalid/main/java/org/spongepowered/common/mixin/invalid/plugin/entityactivation/EntityActivationRange.java index c1f7d0080dd..ed08eefa9ff 100644 --- a/invalid/main/java/org/spongepowered/common/mixin/invalid/plugin/entityactivation/EntityActivationRange.java +++ b/invalid/main/java/org/spongepowered/common/mixin/invalid/plugin/entityactivation/EntityActivationRange.java @@ -69,10 +69,10 @@ import org.spongepowered.common.bridge.world.chunk.ChunkBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.category.EntityActivationModCategory; -import org.spongepowered.common.config.category.EntityActivationRangeCategory; -import org.spongepowered.common.config.type.GlobalConfig; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.inheritable.category.EntityActivationModCategory; +import org.spongepowered.common.config.inheritable.category.EntityActivationRangeCategory; +import org.spongepowered.common.config.inheritable.GlobalConfig; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.accessor.entity.EntityAccessor; import org.spongepowered.common.accessor.entity.LivingEntityAccessor; import org.spongepowered.common.accessor.util.math.AxisAlignedBBAccessor; diff --git a/invalid/main/java/org/spongepowered/common/mixin/invalid/plugin/tileentityactivation/TileEntityActivation.java b/invalid/main/java/org/spongepowered/common/mixin/invalid/plugin/tileentityactivation/TileEntityActivation.java index 9a78571871d..e65c23f4a91 100644 --- a/invalid/main/java/org/spongepowered/common/mixin/invalid/plugin/tileentityactivation/TileEntityActivation.java +++ b/invalid/main/java/org/spongepowered/common/mixin/invalid/plugin/tileentityactivation/TileEntityActivation.java @@ -41,10 +41,10 @@ import org.spongepowered.common.bridge.world.chunk.ChunkBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.category.BlockEntityActivationCategory; -import org.spongepowered.common.config.category.BlockEntityActivationModCategory; -import org.spongepowered.common.config.type.GlobalConfig; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.inheritable.category.BlockEntityActivationCategory; +import org.spongepowered.common.config.inheritable.category.BlockEntityActivationModCategory; +import org.spongepowered.common.config.inheritable.GlobalConfig; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.mixin.invalid.accessor.server.management.PlayerChunkMapAccessor; import org.spongepowered.common.mixin.invalid.accessor.server.management.PlayerChunkMapEntryAccessor; import org.spongepowered.common.util.VecHelper; diff --git a/invalid/main/java/org/spongepowered/common/util/SpongeHooks.java b/invalid/main/java/org/spongepowered/common/util/SpongeHooks.java index 67314139413..cf7abb8ce37 100644 --- a/invalid/main/java/org/spongepowered/common/util/SpongeHooks.java +++ b/invalid/main/java/org/spongepowered/common/util/SpongeHooks.java @@ -40,7 +40,7 @@ import org.spongepowered.common.bridge.world.ServerWorldBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.world.teleport.ConfigTeleportHelperFilter; import java.util.stream.Collectors; diff --git a/src/main/java/org/spongepowered/common/SpongeCommon.java b/src/main/java/org/spongepowered/common/SpongeCommon.java index e5eb1e7c8db..e3644b146fa 100644 --- a/src/main/java/org/spongepowered/common/SpongeCommon.java +++ b/src/main/java/org/spongepowered/common/SpongeCommon.java @@ -32,11 +32,9 @@ import org.spongepowered.api.Sponge; import org.spongepowered.api.event.Event; import org.spongepowered.api.util.Direction; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.SpongeConfigSaveManager; -import org.spongepowered.common.config.type.CustomDataConfig; -import org.spongepowered.common.config.type.GlobalConfig; -import org.spongepowered.common.config.type.TrackerConfig; +import org.spongepowered.common.config.InheritableConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.inheritable.GlobalConfig; import org.spongepowered.common.launch.Launcher; import org.spongepowered.common.registry.SpongeGameRegistry; import org.spongepowered.common.scheduler.AsyncScheduler; @@ -60,10 +58,7 @@ public final class SpongeCommon { ); // Can't @Inject these because they are referenced before everything is initialized - @Nullable private static SpongeConfig globalConfigAdapter; - @Nullable private static SpongeConfig trackerConfigAdapter; - @Nullable private static SpongeConfig customDataConfigAdapter; - @Nullable private static SpongeConfigSaveManager configSaveManager; + @Nullable private static InheritableConfigHandle globalConfigAdapter; @Inject @Nullable private static SpongeGame game; @@ -110,7 +105,7 @@ public static Path getGameDirectory() { } public static Path getPluginConfigDirectory() { - return SpongeCommon.getGameDirectory().resolve(SpongeCommon.getGlobalConfigAdapter().getConfig().getGeneral().configDir()); + return SpongeCommon.getGameDirectory().resolve(SpongeConfigs.getCommon().get().getGeneral().configDir()); } public static Path getSpongeConfigDirectory() { @@ -144,34 +139,6 @@ public static void setActivePlugin(@Nullable final PluginContainer plugin) { SpongeCommon.activePlugin = plugin; } - public static SpongeConfigSaveManager getConfigSaveManager() { - if (SpongeCommon.configSaveManager == null) { - SpongeCommon.configSaveManager = new SpongeConfigSaveManager(); - } - return SpongeCommon.configSaveManager; - } - - public static SpongeConfig getGlobalConfigAdapter() { - if (SpongeCommon.globalConfigAdapter == null) { - SpongeCommon.globalConfigAdapter = new SpongeConfig<>(SpongeConfig.Type.GLOBAL, getSpongeConfigDirectory().resolve("global.conf"), SpongeCommon.ECOSYSTEM_ID, null, false); - } - return SpongeCommon.globalConfigAdapter; - } - - public static SpongeConfig getCustomDataConfigAdapter() { - if (SpongeCommon.customDataConfigAdapter == null) { - SpongeCommon.customDataConfigAdapter = new SpongeConfig<>(SpongeConfig.Type.CUSTOM_DATA, getSpongeConfigDirectory().resolve("custom_data.conf"), SpongeCommon.ECOSYSTEM_ID, null, true); - } - return SpongeCommon.customDataConfigAdapter; - } - - public static SpongeConfig getTrackerConfigAdapter() { - if (SpongeCommon.trackerConfigAdapter == null) { - SpongeCommon.trackerConfigAdapter = new SpongeConfig<>(SpongeConfig.Type.TRACKER, getSpongeConfigDirectory().resolve("tracker.conf"), SpongeCommon.ECOSYSTEM_ID, null, true); - } - return SpongeCommon.trackerConfigAdapter; - } - /** * Throws the given event. * diff --git a/src/main/java/org/spongepowered/common/bridge/CreatorTrackedBridge.java b/src/main/java/org/spongepowered/common/bridge/CreatorTrackedBridge.java index d4ecdf2d6c8..3b9a6fd4de9 100644 --- a/src/main/java/org/spongepowered/common/bridge/CreatorTrackedBridge.java +++ b/src/main/java/org/spongepowered/common/bridge/CreatorTrackedBridge.java @@ -28,7 +28,7 @@ import net.minecraft.tileentity.TileEntity; import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.api.entity.living.player.User; -import org.spongepowered.common.config.category.ModuleCategory; +import org.spongepowered.common.config.common.ModuleCategory; import org.spongepowered.common.entity.PlayerTracker; import org.spongepowered.common.event.tracking.PhaseTracker; diff --git a/src/main/java/org/spongepowered/common/bridge/TrackableBridge.java b/src/main/java/org/spongepowered/common/bridge/TrackableBridge.java index 9d2beba0c2b..e9c12a6624a 100644 --- a/src/main/java/org/spongepowered/common/bridge/TrackableBridge.java +++ b/src/main/java/org/spongepowered/common/bridge/TrackableBridge.java @@ -24,7 +24,7 @@ */ package org.spongepowered.common.bridge; -import org.spongepowered.common.config.type.TrackerConfig; +import org.spongepowered.common.config.tracker.TrackerConfig; public interface TrackableBridge { diff --git a/src/main/java/org/spongepowered/common/bridge/optimization/OptimizedMapDataBridge.java b/src/main/java/org/spongepowered/common/bridge/optimization/OptimizedMapDataBridge.java index 68f3e6307b2..9ad731790d8 100644 --- a/src/main/java/org/spongepowered/common/bridge/optimization/OptimizedMapDataBridge.java +++ b/src/main/java/org/spongepowered/common/bridge/optimization/OptimizedMapDataBridge.java @@ -28,7 +28,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.world.storage.MapData; -import org.spongepowered.common.config.category.OptimizationCategory; +import org.spongepowered.common.config.common.OptimizationCategory; /** * Only used for the {@link OptimizationCategory#useMapOptimization()} mixins targeting {@link MapData}. diff --git a/src/main/java/org/spongepowered/common/bridge/world/storage/WorldInfoBridge.java b/src/main/java/org/spongepowered/common/bridge/world/storage/WorldInfoBridge.java index 30f45fb1f9f..be595a5f571 100644 --- a/src/main/java/org/spongepowered/common/bridge/world/storage/WorldInfoBridge.java +++ b/src/main/java/org/spongepowered/common/bridge/world/storage/WorldInfoBridge.java @@ -30,8 +30,8 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.api.world.SerializationBehavior; import org.spongepowered.api.world.teleport.PortalAgentType; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.InheritableConfigHandle; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.world.dimension.SpongeDimensionType; import java.util.Optional; @@ -105,9 +105,9 @@ public interface WorldInfoBridge { Optional bridge$getUniqueIdForIndex(int index); - @Nullable SpongeConfig bridge$getConfigAdapter(); + @Nullable InheritableConfigHandle bridge$getConfigAdapter(); - boolean bridge$createWorldConfig(); + void bridge$setConfigAdapter(final InheritableConfigHandle adapter); void bridge$saveConfig(); } diff --git a/src/main/java/org/spongepowered/common/command/manager/SpongeCommandManager.java b/src/main/java/org/spongepowered/common/command/manager/SpongeCommandManager.java index e6f79cf0394..e6ba3501689 100644 --- a/src/main/java/org/spongepowered/common/command/manager/SpongeCommandManager.java +++ b/src/main/java/org/spongepowered/common/command/manager/SpongeCommandManager.java @@ -67,6 +67,7 @@ import org.spongepowered.common.command.registrar.SpongeParameterizedCommandRegistrar; import org.spongepowered.common.command.registrar.tree.RootCommandTreeBuilder; import org.spongepowered.common.command.sponge.SpongeCommand; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.common.event.ShouldFire; import org.spongepowered.common.event.lifecycle.RegisterCommandEventImpl; import org.spongepowered.common.event.tracking.PhaseTracker; @@ -220,7 +221,7 @@ public CommandMapping registerAliasWithNamespacing( // We need to consider the configuration file - if there is an entry in there // then remove an alias if the command is not entitled to use it. - SpongeCommon.getGlobalConfigAdapter().getConfig() + SpongeConfigs.getCommon().get() .getCommands() .getAliases() .entrySet() diff --git a/src/main/java/org/spongepowered/common/config/category/GlobalGeneralCategory.java b/src/main/java/org/spongepowered/common/config/Config.java similarity index 55% rename from src/main/java/org/spongepowered/common/config/category/GlobalGeneralCategory.java rename to src/main/java/org/spongepowered/common/config/Config.java index cc212b6aa90..4138df33260 100644 --- a/src/main/java/org/spongepowered/common/config/category/GlobalGeneralCategory.java +++ b/src/main/java/org/spongepowered/common/config/Config.java @@ -22,22 +22,37 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config; -import ninja.leaping.configurate.objectmapping.Setting; -import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; +import ninja.leaping.configurate.transformation.ConfigurationTransformation; -@ConfigSerializable -public class GlobalGeneralCategory extends GeneralCategory { +public interface Config { - @Setting(value = "file-io-thread-sleep", comment = "If 'true', sleeping between chunk saves will be enabled, beware of memory issues.") - private boolean fileIOThreadSleep = false; + ConfigurationTransformation EMPTY_VERSIONED = ConfigurationTransformation.versionedBuilder().build(); - public GlobalGeneralCategory() { - + /** + * Path array builder. Will be removed in configurate 4.0. + * + * @param path path + * @return path + */ + static Object[] path(Object... path) { + return path; } - public boolean getFileIOThreadSleep() { - return this.fileIOThreadSleep; + /** + * Get a transformation that will be applied to this configuration on load. + * + *

We assume this is a versioned transformation. Configurate 4.0 will be + * able to enforce this.

+ * + *

When determining versions, round to the nearest 100 and add 100 for + * every major release. This allows for future minor releases to add + * configuration changes in previous major releases.

+ * + * @return A transformation instance + */ + default ConfigurationTransformation getTransformation() { + return EMPTY_VERSIONED; } } diff --git a/src/main/java/org/spongepowered/common/config/ConfigHandle.java b/src/main/java/org/spongepowered/common/config/ConfigHandle.java new file mode 100644 index 00000000000..c4f83b9f430 --- /dev/null +++ b/src/main/java/org/spongepowered/common/config/ConfigHandle.java @@ -0,0 +1,227 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.config; + +import static java.util.Objects.requireNonNull; + +import com.google.common.reflect.TypeToken; +import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.loader.ConfigurationLoader; +import ninja.leaping.configurate.objectmapping.ObjectMapper; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.api.util.Functional; + +import java.io.IOException; +import java.util.Iterator; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ForkJoinPool; +import java.util.function.UnaryOperator; + + +/** + * A holder for load/save state of a configuration. + */ +public class ConfigHandle { + private static final Logger LOGGER = LogManager.getLogger(); + /** + * Location where current version is stored + */ + public static final Object[] VERSION_PATH = new Object[] {"version"}; + private static final String VERSION_COMMENT = "Active configuration version\n" + + "This has no relation to the current Sponge version, and will be updated automatically\n" + + "Manual changes may cause unpredictable results."; + + // Save suppression + // Temporary fix for IO spam -- just don't save during server load. + private static boolean saveSuppressed = true; + private static final Set> saveQueue = ConcurrentHashMap.newKeySet(); + + /** + * Enable or disable save suppression. + * + *

Save on initial load will always be performed, no matter what this setting is.

+ * + * @implNote Default save suppression is {@code true}. + * @param suppressed whether saves should be suppressed + */ + public static void setSaveSuppressed(boolean suppressed) { + ConfigHandle.saveSuppressed = suppressed; + if (!suppressed && !ConfigHandle.saveQueue.isEmpty()) { + for (final Iterator> it = ConfigHandle.saveQueue.iterator(); it.hasNext();) { + try { + it.next().doSave(); + } catch (IOException | ObjectMappingException ex) { + LOGGER.error("Unable to save a Sponge configuration!", ex); + } + it.remove(); + } + } + } + + protected final @Nullable ConfigurationLoader loader; + protected final ObjectMapper.BoundInstance mapper; + protected @MonotonicNonNull CommentedConfigurationNode node; + + ConfigHandle(final T instance) { + try { + this.mapper = ObjectMapper.forObject(instance); + } catch (final ObjectMappingException ex) { + // object mapper classes are constant from compile onwards, this failure will always happen. + throw new AssertionError(ex); + } + this.loader = null; + } + + ConfigHandle(final T instance, final @Nullable ConfigurationLoader loader) { + try { + this.mapper = ObjectMapper.forObject(instance); + } catch (ObjectMappingException ex) { + // object mapper classes are constant from compile onwards, this failure will always happen. + throw new AssertionError(ex); + } + this.loader = loader; + } + + /** + * If this configuration refers to a transient world or dimension type, it + * will be marked as {@code detached}, meaning that it will not + * be persisted. + * + * @return whether the node is attached, false if detached + */ + public boolean isAttached() { + return this.loader != null; + } + + public T get() { + return this.mapper.getInstance(); + } + + public CompletableFuture updateAndSave(final UnaryOperator updater) { + final T updated = requireNonNull(updater, "updater").apply(this.mapper.getInstance()); + return Functional.asyncFailableFuture(() -> { + // TODO: Force one save at a time + this.save(); + return updated; + }, ForkJoinPool.commonPool()); + } + + void load() throws IOException, ObjectMappingException { + if (this.loader == null) { // we are virtual + return; + } + + this.node = this.loader.load(); + this.doVersionUpdate(); + this.mapper.populate(this.node); + this.doSave(); + } + + protected final void doVersionUpdate() { + final boolean wasEmpty = this.node.getValue() == null; // TODO(Configurate 3.7) isEmpty + final CommentedConfigurationNode versionNode = this.node.getNode(VERSION_PATH); + final int existingVersion = versionNode.getInt(-1); + this.mapper.getInstance().getTransformation().apply(this.node); + final int newVersion = versionNode.getInt(-1); + if (!wasEmpty && newVersion > existingVersion) { + LOGGER.info("Updated {} from version {} to {}", this.mapper.getInstance(), existingVersion, newVersion); + } + versionNode.setComment(VERSION_COMMENT); // TODO(Configurate 3.7) setCommentIfAbsent + this.node.getNode(VERSION_PATH).setValue(versionNode); // workaround for some weird issue, can remove @configurate 4.0 + } + + public void reload() throws IOException, ObjectMappingException { + // TODO: Something nicer? + this.load(); + } + + public final void save() { + if (ConfigHandle.saveSuppressed) { + ConfigHandle.saveQueue.add(this); + } else { + try { + doSave(); + } catch (final IOException | ObjectMappingException ex) { + LOGGER.error("Unable to save configuration to {}", this.loader, ex); + } + } + } + + protected void doSave() throws ObjectMappingException, IOException { + if (this.loader == null) { + return; + } + + if (this.node == null) { + this.node = this.loader.createEmptyNode(); + } + + this.mapper.serialize(this.node); + this.loader.save(this.node); + } + + @Nullable + private CommentedConfigurationNode getSetting(String key) { + if (key.equalsIgnoreCase("config-enabled")) { + return this.node.getNode(key); + } else if (!key.contains(".") || key.indexOf('.') == key.length() - 1) { + return null; + } else { + CommentedConfigurationNode node = this.node; + final String[] split = key.split("\\."); + return node.getNode((Object[]) split); + } + } + + public CompletableFuture updateSetting(String key, Object value) { + return Functional.asyncFailableFuture(() -> { + CommentedConfigurationNode upd = this.getSetting(key); + this.mapper.populate(this.node); + this.save(); + return upd; + }, ForkJoinPool.commonPool()); + } + + public CompletableFuture updateSetting(String key, V value, TypeToken token) { + return Functional.asyncFailableFuture(() -> { + CommentedConfigurationNode upd = this.getSetting(key); + upd.setValue(token, value); + this.mapper.populate(this.node); + this.save(); + return upd; + }, ForkJoinPool.commonPool()); + } + + public ConfigurationNode getNode() { + return this.node; + } +} diff --git a/src/main/java/org/spongepowered/common/config/FileMovingConfigurationTransformation.java b/src/main/java/org/spongepowered/common/config/FileMovingConfigurationTransformation.java new file mode 100644 index 00000000000..6d1f4189b1b --- /dev/null +++ b/src/main/java/org/spongepowered/common/config/FileMovingConfigurationTransformation.java @@ -0,0 +1,74 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.config; + +import com.google.common.collect.ImmutableSet; +import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.loader.ConfigurationLoader; +import ninja.leaping.configurate.transformation.ConfigurationTransformation; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.io.IOException; +import java.util.Set; + +/** + * A transformation that moves a set of entries from the loaded file into another file. + */ +public class FileMovingConfigurationTransformation extends ConfigurationTransformation { + private final Set paths; + private final ConfigurationLoader destinationLoader; + private final boolean override; + + public FileMovingConfigurationTransformation(final Set paths, final ConfigurationLoader destinationLoader, final boolean override) { + this.paths = ImmutableSet.copyOf(paths); + this.destinationLoader = destinationLoader; + this.override = override; + } + + @Override + public void apply(final @NonNull ConfigurationNode oldConfig) { + try { + final ConfigurationNode newConfig = this.destinationLoader.load(); + boolean acted = false; + for (final Object[] path : this.paths) { + final ConfigurationNode source = oldConfig.getNode(path); + if (!source.isVirtual()) { + acted = true; + if (override) { + newConfig.getNode(path).setValue(source); + } else { + newConfig.getNode(path).mergeValuesFrom(source); + } + source.setValue(null); + } + } + if (acted) { + this.destinationLoader.save(newConfig); + } + } catch (final IOException ex) { + SpongeConfigs.LOGGER.error("Unable to save destination configuration while migrating {}", oldConfig, ex); + } + } +} diff --git a/src/main/java/org/spongepowered/common/config/InheritableConfigHandle.java b/src/main/java/org/spongepowered/common/config/InheritableConfigHandle.java new file mode 100644 index 00000000000..6926b295fe7 --- /dev/null +++ b/src/main/java/org/spongepowered/common/config/InheritableConfigHandle.java @@ -0,0 +1,209 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.config; + +import ninja.leaping.configurate.Types; +import ninja.leaping.configurate.ValueType; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; +import ninja.leaping.configurate.loader.ConfigurationLoader; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; +import ninja.leaping.configurate.util.ConfigurationNodeWalker; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.common.config.inheritable.BaseConfig; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.function.Consumer; +import java.util.function.Function; + +public class InheritableConfigHandle extends ConfigHandle { + + /** + * The parent configuration - values are inherited from this + */ + private final @Nullable InheritableConfigHandle parent; + + /** + * A node representation of {@link #node}, merged with the data of {@link #parent}. + */ + private CommentedConfigurationNode mergedNode; + + InheritableConfigHandle(final T instance, final @Nullable InheritableConfigHandle parent) { + super(instance); + this.parent = parent; + } + + InheritableConfigHandle(final T instance, + final ConfigurationLoader loader, + final @Nullable InheritableConfigHandle parent) { + super(instance, loader); + this.parent = parent; + } + + /** + * Get or create a value, initializing in the parent configuration if not present. + * + * @param getter Function to get value + * @param setter Function to set default value + * @param populate whether default value should be written + * @param value type + * @return value or default + */ + public V getOrCreateValue(final Function getter, final Consumer setter, boolean populate) { + V ret = getter.apply(this.get()); + if (ret == null && populate) { + setter.accept(this.get()); + if(this.parent != null) { + setter.accept(this.parent.get()); + } + ret = getter.apply(this.get()); + } + return ret; + } + + public void load() throws IOException, ObjectMappingException { + if (this.isAttached()) { + // store "what's in the file" separately in memory + this.node = this.loader.load(); + // and perform any necessary version updates + this.doVersionUpdate(); + + // make a copy of the file data + this.mergedNode = this.node.copy(); + } else { + this.mergedNode = SimpleCommentedConfigurationNode.root(SpongeConfigs.OPTIONS); + } + + // merge with settings from parent + if (this.parent != null) { + this.mergedNode.mergeValuesFrom(this.parent.mergedNode); + } + + // populate the config object + this.mapper.populate(this.mergedNode); + this.doSave(); + } + + public void doSave() { + if (!this.isAttached()) { + return; + } + + try { + // save from the mapped object --> node + this.mapper.serialize(this.node); + + // before saving this config, remove any values already declared with the same value on the parent + if (this.parent != null) { + this.removeDuplicates(this.node); + } + + // save the data to disk + this.loader.save(this.node); + + // In order for the removeDuplicates method to function properly, it is extremely + // important to avoid running save on parent BEFORE children save. Doing so will + // cause duplicate nodes to not be removed as parent would have cleaned up + // all duplicates prior. + // While this issue would only occur when there are multiple levels of inheritance, + // which we don't currently have, there's no harm in supporting it anyways. + // To handle the above issue, we save AFTER saving child config. + if (this.parent != null) { + this.parent.doSave(); + } + } catch (IOException | ObjectMappingException e) { + SpongeConfigs.LOGGER.error("Failed to save configuration", e); + } + } + + /** + * Traverses the given {@code root} config node, removing any values which + * are also present and set to the same value on this configs "parent". + * + * @param root The node to process + */ + private void removeDuplicates(CommentedConfigurationNode root) { + if (!this.isAttached()) { + return; + } + if (this.parent == null) { + throw new IllegalStateException("parent is null"); + } + + Iterator> it = ConfigurationNodeWalker.DEPTH_FIRST_POST_ORDER.walkWithPath(root); + while (it.hasNext()) { + ConfigurationNodeWalker.VisitedNode next = it.next(); + CommentedConfigurationNode node = next.getNode(); + + // remove empty maps + if (node.hasMapChildren()) { + if (node.getChildrenMap().isEmpty()) { + node.setValue(null); + } + continue; + } + + // ignore list values + if (node.getParent() != null && node.getParent().getValueType() == ValueType.LIST) { + continue; + } + + final Object[] currentPath = next.getPath().getArray(); + // Version node should be equal, but is important to keep + if (Arrays.equals(VERSION_PATH, currentPath)) { + continue; + } + + // if the node already exists in the parent config, remove it + CommentedConfigurationNode parentValue = this.parent.mergedNode.getNode(currentPath); + if (Objects.equals(node.getValue(), parentValue.getValue())) { + node.setValue(null); + } else { + // Fix list bug + if (parentValue.getValue() == null) { + if (node.getValueType() == ValueType.LIST) { + final List nodeList = (List) node.getValue(); + if (nodeList.isEmpty()) { + node.setValue(null); + } + continue; + } + } + // Fix double bug + final Double nodeVal = node.getValue(Types::asDouble); + if (nodeVal != null) { + Double parentVal = parentValue.getValue(Types::asDouble); + if (parentVal == null && nodeVal.doubleValue() == 0 || (parentVal != null && nodeVal.doubleValue() == parentVal.doubleValue())) { + node.setValue(null); + } + } + } + } + } +} diff --git a/src/main/java/org/spongepowered/common/config/SpongeConfigManager.java b/src/main/java/org/spongepowered/common/config/PluginConfigManager.java similarity index 90% rename from src/main/java/org/spongepowered/common/config/SpongeConfigManager.java rename to src/main/java/org/spongepowered/common/config/PluginConfigManager.java index 3d1bac41793..92ef8bb9398 100644 --- a/src/main/java/org/spongepowered/common/config/SpongeConfigManager.java +++ b/src/main/java/org/spongepowered/common/config/PluginConfigManager.java @@ -39,27 +39,27 @@ * Implementation of service to manage configurations. */ @Singleton -public final class SpongeConfigManager implements ConfigManager { +public final class PluginConfigManager implements ConfigManager { @Override public ConfigRoot getSharedConfig(PluginContainer container) { - return new SpongeConfigRoot(getMapperFactory(container), container.getMetadata().getId().toLowerCase(), SpongeCommon.getPluginConfigDirectory()); + return new PluginConfigRoot(getMapperFactory(container), container.getMetadata().getId().toLowerCase(), SpongeCommon.getPluginConfigDirectory()); } @Override public ConfigRoot getPluginConfig(PluginContainer container) { - return new SpongeConfigRoot(getMapperFactory(container), container.getMetadata().getId().toLowerCase(), SpongeCommon + return new PluginConfigRoot(getMapperFactory(container), container.getMetadata().getId().toLowerCase(), SpongeCommon .getPluginConfigDirectory().resolve(container.getMetadata().getId().toLowerCase())); } public static ConfigRoot getSharedRoot(PluginContainer container) { final String name = container.getMetadata().getId(); - return new SpongeConfigRoot(getMapperFactory(container), name, SpongeCommon.getPluginConfigDirectory()); + return new PluginConfigRoot(getMapperFactory(container), name, SpongeCommon.getPluginConfigDirectory()); } public static ConfigRoot getPrivateRoot(PluginContainer container) { final String name = container.getMetadata().getId(); - return new SpongeConfigRoot(getMapperFactory(container), name, SpongeCommon.getPluginConfigDirectory().resolve(name)); + return new PluginConfigRoot(getMapperFactory(container), name, SpongeCommon.getPluginConfigDirectory().resolve(name)); } private static ObjectMapperFactory getMapperFactory(PluginContainer container) { diff --git a/src/main/java/org/spongepowered/common/config/SpongeConfigRoot.java b/src/main/java/org/spongepowered/common/config/PluginConfigRoot.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/SpongeConfigRoot.java rename to src/main/java/org/spongepowered/common/config/PluginConfigRoot.java index 54b81db41b4..d119241a050 100644 --- a/src/main/java/org/spongepowered/common/config/SpongeConfigRoot.java +++ b/src/main/java/org/spongepowered/common/config/PluginConfigRoot.java @@ -39,12 +39,12 @@ /** * Root for sponge configurations. */ -public class SpongeConfigRoot implements ConfigRoot { +public class PluginConfigRoot implements ConfigRoot { private final ObjectMapperFactory mapperFactory; private final String pluginName; private final Path baseDir; - SpongeConfigRoot(ObjectMapperFactory mapperFactory, String pluginName, Path baseDir) { + PluginConfigRoot(ObjectMapperFactory mapperFactory, String pluginName, Path baseDir) { this.mapperFactory = mapperFactory; this.pluginName = pluginName; this.baseDir = baseDir; diff --git a/src/main/java/org/spongepowered/common/config/SpongeConfig.java b/src/main/java/org/spongepowered/common/config/SpongeConfig.java deleted file mode 100644 index ec67cf74a8c..00000000000 --- a/src/main/java/org/spongepowered/common/config/SpongeConfig.java +++ /dev/null @@ -1,365 +0,0 @@ -/* - * This file is part of Sponge, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.common.config; - -import com.google.common.reflect.TypeToken; -import ninja.leaping.configurate.ConfigurationOptions; -import ninja.leaping.configurate.Types; -import ninja.leaping.configurate.ValueType; -import ninja.leaping.configurate.commented.CommentedConfigurationNode; -import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; -import ninja.leaping.configurate.hocon.HoconConfigurationLoader; -import ninja.leaping.configurate.objectmapping.ObjectMapper; -import ninja.leaping.configurate.objectmapping.ObjectMappingException; -import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers; -import ninja.leaping.configurate.util.ConfigurationNodeWalker; -import org.spongepowered.api.util.Functional; -import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.type.ConfigBase; -import org.spongepowered.common.config.type.CustomDataConfig; -import org.spongepowered.common.config.type.DimensionConfig; -import org.spongepowered.common.config.type.GlobalConfig; -import org.spongepowered.common.config.type.TrackerConfig; -import org.spongepowered.common.config.type.WorldConfig; -import org.spongepowered.common.util.IpSet; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ForkJoinPool; - -import javax.annotation.Nullable; - -@SuppressWarnings("unchecked") -public class SpongeConfig { - - public enum Type { - CUSTOM_DATA(CustomDataConfig.class), - TRACKER(TrackerConfig.class), - GLOBAL(GlobalConfig.class), - DIMENSION(DimensionConfig.class), - WORLD(WorldConfig.class); - - final Class type; - - Type(Class type) { - this.type = type; - } - } - - private static final String HEADER = "1.0\n" - + "\n" - + "# If you need help with the configuration or have any questions related to Sponge,\n" - + "# join us at the IRC or drop by our forums and leave a post.\n" - + "\n" - + "# IRC: #sponge @ irc.esper.net ( https://webchat.esper.net/?channel=sponge )\n" - + "# Forums: https://forums.spongepowered.org/\n"; - - private static final ConfigurationOptions LOADER_OPTIONS = ConfigurationOptions.defaults() - .setHeader(HEADER) - .setSerializers(TypeSerializers.getDefaultSerializers().newChild() - .registerType(TypeToken.of(IpSet.class), new IpSet.IpSetSerializer()) - ); - - /** - * The type of this config instance - */ - private final Type type; - - /** - * The parent configuration - values are inherited from this - */ - @Nullable private final SpongeConfig parent; - - /** - * The loader (mapped to a file) used to read/write the config to disk - */ - private HoconConfigurationLoader loader; - - /** - * A node representation of "whats actually in the file". - */ - private CommentedConfigurationNode fileData = SimpleCommentedConfigurationNode.root(LOADER_OPTIONS); - - /** - * A node representation of {@link #fileData}, merged with the data of {@link #parent}. - */ - private CommentedConfigurationNode data = SimpleCommentedConfigurationNode.root(LOADER_OPTIONS); - - /** - * The mapper instance used to populate the config instance - */ - private ObjectMapper.BoundInstance configMapper; - - private final String modId; - private final boolean isDummy; - - public static SpongeConfig newDummyConfig(Type type) { - return new SpongeConfig<>(type); - } - - private SpongeConfig(Type type) { - this.type = type; - this.parent = null; - this.modId = null; - this.isDummy = true; - - try { - this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(this.type.type).bindToNew(); - } catch (Exception e) { - SpongeCommon.getLogger().error("Failed to initialize dummy configuration", e); - } - } - - public SpongeConfig(Type type, Path path, String modId, SpongeConfig parent, boolean forceSaveOnLoad) { - this.type = type; - this.parent = parent; - this.modId = modId; - this.isDummy = false; - - try { - Files.createDirectories(path.getParent()); - if (Files.notExists(path)) { - Files.createFile(path); - } - - this.loader = HoconConfigurationLoader.builder().setPath(path).build(); - this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(this.type.type).bindToNew(); - - // If load fails, avoid saving as this can mess up world configs. - if (!this.load()) { - return; - } - // In order for the removeDuplicates method to function properly, it is extremely - // important to avoid running save on parent BEFORE children save. Doing so will - // cause duplicate nodes to not be removed properly as parent would have cleaned up - // all duplicates prior. - // To handle the above issue, we only call save for world configs during init. - if (!forceSaveOnLoad && parent != null && parent.parent != null) { - this.saveNow(); - } else if (forceSaveOnLoad) { - this.saveNow(); - } - } catch (Exception e) { - SpongeCommon.getLogger().error("Failed to initialize configuration", e); - } - } - - public T getConfig() { - return this.configMapper.getInstance(); - } - - public void save() { - if (this.isDummy) { - return; - } - SpongeCommon.getConfigSaveManager().save(this); - } - - boolean saveNow() { - if (this.isDummy) { - return false; - } - try { - // save from the mapped object --> node - CommentedConfigurationNode saveNode = SimpleCommentedConfigurationNode.root(LOADER_OPTIONS); - this.configMapper.serialize(saveNode.getNode(this.modId)); - - // before saving this config, remove any values already declared with the same value on the parent - if (this.parent != null) { - this.removeDuplicates(saveNode); - } - - // save the data to disk - this.loader.save(saveNode); - - // In order for the removeDuplicates method to function properly, it is extremely - // important to avoid running save on parent BEFORE children save. Doing so will - // cause duplicate nodes to not be removed as parent would have cleaned up - // all duplicates prior. - // To handle the above issue, we save AFTER saving child config. - if (this.parent != null) { - this.parent.saveNow(); - } - return true; - } catch (IOException | ObjectMappingException e) { - SpongeCommon.getLogger().error("Failed to save configuration", e); - return false; - } - } - - public boolean load() { - if (this.isDummy) { - return true; - } - if (!SpongeCommon.getConfigSaveManager().flush(this)) { - // Can't reload - SpongeCommon.getLogger().error("Failed to load configuration due to error in flushing config"); - return false; - } - - try { - // load settings from file - CommentedConfigurationNode loadedNode = this.loader.load(); - - // This is where we can inject versioning. -// ConfigurationTransformation.versionedBuilder() -// .addVersion(2, ConfigurationTransformation.builder() -// .addAction(path("optimizations", "faster-thread-checks"), (input, value) -> { -// }) -// ).build(); - - // store "what's in the file" separately in memory - this.fileData = loadedNode; - - // make a copy of the file data - this.data = this.fileData.copy(); - - // merge with settings from parent - if (this.parent != null) { - this.parent.load(); - this.data.mergeValuesFrom(this.parent.data); - } - - // populate the config object - this.populateInstance(); - return true; - } catch (Exception e) { - SpongeCommon.getLogger().error("Failed to load configuration", e); - return false; - } - } - - private void populateInstance() throws ObjectMappingException { - if (this.isDummy) { - return; - } - this.configMapper.populate(this.data.getNode(this.modId)); - } - - /** - * Traverses the given {@code root} config node, removing any values which - * are also present and set to the same value on this configs "parent". - * - * @param root The node to process - */ - private void removeDuplicates(CommentedConfigurationNode root) { - if (this.isDummy) { - return; - } - if (this.parent == null) { - throw new IllegalStateException("parent is null"); - } - - Iterator> it = ConfigurationNodeWalker.DEPTH_FIRST_POST_ORDER.walkWithPath(root); - while (it.hasNext()) { - ConfigurationNodeWalker.VisitedNode next = it.next(); - CommentedConfigurationNode node = next.getNode(); - - // remove empty maps - if (node.hasMapChildren()) { - if (node.getChildrenMap().isEmpty()) { - node.setValue(null); - } - continue; - } - - // ignore list values - if (node.getParent() != null && node.getParent().getValueType() == ValueType.LIST) { - continue; - } - - // if the node already exists in the parent config, remove it - CommentedConfigurationNode parentValue = this.parent.data.getNode(next.getPath().getArray()); - if (Objects.equals(node.getValue(), parentValue.getValue())) { - node.setValue(null); - } else { - // Fix list bug - if (parentValue.getValue() == null) { - if (node.getValueType() == ValueType.LIST) { - final List nodeList = (List) node.getValue(); - if (nodeList.isEmpty()) { - node.setValue(null); - } - continue; - } - } - // Fix double bug - final Double nodeVal = node.getValue(Types::asDouble); - if (nodeVal != null) { - Double parentVal = parentValue.getValue(Types::asDouble); - if (parentVal == null && nodeVal.doubleValue() == 0 || (parentVal != null && nodeVal.doubleValue() == parentVal.doubleValue())) { - node.setValue(null); - } - } - } - } - } - - public CompletableFuture updateSetting(String key, Object value) { - return Functional.asyncFailableFuture(() -> { - CommentedConfigurationNode upd = this.getSetting(key); - upd.setValue(value); - this.populateInstance(); - this.saveNow(); - return upd; - }, ForkJoinPool.commonPool()); - } - - public CompletableFuture updateSetting(String key, V value, TypeToken token) { - return Functional.asyncFailableFuture(() -> { - CommentedConfigurationNode upd = this.getSetting(key); - upd.setValue(token, value); - this.populateInstance(); - this.save(); - return upd; - }, ForkJoinPool.commonPool()); - } - - public CommentedConfigurationNode getRootNode() { - return this.data.getNode(this.modId); - } - - @Nullable - private CommentedConfigurationNode getSetting(String key) { - if (key.equalsIgnoreCase("config-enabled")) { - return this.getRootNode().getNode(key); - } else if (!key.contains(".") || key.indexOf('.') == key.length() - 1) { - return null; - } else { - CommentedConfigurationNode node = this.getRootNode(); - final String[] split = key.split("\\."); - return node.getNode((Object[]) split); - } - } - - public Type getType() { - return this.type; - } -} diff --git a/src/main/java/org/spongepowered/common/config/SpongeConfigSaveManager.java b/src/main/java/org/spongepowered/common/config/SpongeConfigSaveManager.java deleted file mode 100644 index d5db4c5f052..00000000000 --- a/src/main/java/org/spongepowered/common/config/SpongeConfigSaveManager.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This file is part of Sponge, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.common.config; - -import org.spongepowered.common.SpongeCommon; - -import java.util.HashSet; -import java.util.Set; - -/** - * To avoid file saving issues with Windows and to allow some async file saving, - * this manager acts as a staging ground for file saves so that we can do them - * in batches. - * - *

This class is intended to be thread safe through the use of - * synchronisation.

- */ -public class SpongeConfigSaveManager { - - private final Set> stagedConfigs = new HashSet<>(); - - public void save(SpongeConfig spongeConfig) { - synchronized (this) { - // TODO Minecraft 1.14 - Check if the server is up or the game has stopped. - if (!SpongeCommon.isInitialized()) { - if (!this.stagedConfigs.isEmpty()) { - // We want to save and flush now, but add this into the set in case it is already present. - this.stagedConfigs.add(spongeConfig); - this.flush(); - } else { - // just save - spongeConfig.saveNow(); - } - } else { - this.stagedConfigs.add(spongeConfig); - } - } - } - - /** - * Flush a specific config. Returns true if successful or if the config was - * not in the set. False if there was an error on save. - * - * @param config The config to save now - * @return {@code true} if successful or unneeded, false otherwise. - */ - boolean flush(SpongeConfig config) { - synchronized (this) { - if (this.stagedConfigs.remove(config)) { - return config.saveNow(); - } - } - - return true; - } - - private void flush() { - if (!this.stagedConfigs.isEmpty()) { - synchronized (this) { - for (SpongeConfig spongeConfig : this.stagedConfigs) { - spongeConfig.saveNow(); - } - - this.stagedConfigs.clear(); - } - } - } - -} diff --git a/src/main/java/org/spongepowered/common/config/SpongeConfigs.java b/src/main/java/org/spongepowered/common/config/SpongeConfigs.java new file mode 100644 index 00000000000..001ec61ade2 --- /dev/null +++ b/src/main/java/org/spongepowered/common/config/SpongeConfigs.java @@ -0,0 +1,260 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.config; + +import com.google.common.reflect.TypeToken; +import ninja.leaping.configurate.ConfigurationOptions; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.hocon.HoconConfigurationLoader; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; +import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.api.ResourceKey; +import org.spongepowered.api.util.Tristate; +import org.spongepowered.api.world.dimension.DimensionType; +import org.spongepowered.api.world.dimension.DimensionTypes; +import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; +import org.spongepowered.common.config.customdata.CustomDataConfig; +import org.spongepowered.common.config.common.CommonConfig; +import org.spongepowered.common.config.inheritable.GlobalConfig; +import org.spongepowered.common.config.inheritable.WorldConfig; +import org.spongepowered.common.config.tracker.TrackerConfig; +import org.spongepowered.common.util.IpSet; +import org.spongepowered.common.world.server.SpongeWorldManager; + +import java.io.File; +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; + +public class SpongeConfigs { + + static final String HEADER = "\n" + + "# If you need help with the configuration or have any questions related to Sponge,\n" + + "# join us on Discord or drop by our forums and leave a post.\n" + + "\n" + + "# Discord: https://discord.gg/sponge\n" + + "# Forums: https://forums.spongepowered.org/\n"; + + static final ConfigurationOptions OPTIONS = ConfigurationOptions.defaults() + .setHeader(HEADER) + .setShouldCopyDefaults(true) + .setSerializers(TypeSerializers.getDefaultSerializers().newChild() + .registerType(TypeToken.of(IpSet.class), new IpSet.IpSetSerializer()) + ); + + static final Logger LOGGER = LogManager.getLogger(); + + private static final Object initLock = new Object(); + private static Path configDir; + + private static ConfigHandle sponge; + private static ConfigHandle trackerConfigAdapter; + private static ConfigHandle customDataConfigAdapter; + private static InheritableConfigHandle global; + + + public static Path getDirectory() { + if (SpongeConfigs.configDir == null) { + final Path baseDir = Paths.get(Objects.requireNonNull(System.getProperty("org.spongepowered.common.baseDir"), + "No base directory was passed to the Sponge configuration")); + SpongeConfigs.configDir = baseDir + .resolve("config") + .resolve(SpongeCommon.ECOSYSTEM_ID); + } + return SpongeConfigs.configDir; + } + + /** + * Get global configuration, containing options that cannot be overridden per-world. + * + * @return global config + */ + public static ConfigHandle getCommon() { + if (SpongeConfigs.sponge == null) { + synchronized (SpongeConfigs.initLock) { + if (SpongeConfigs.sponge == null) { + // Load global config first so we can migrate over old settings + SpongeConfigs.getGlobalInheritable(); + // Then load the actual configuration based on the new file + SpongeConfigs.sponge = create(new CommonConfig(), CommonConfig.FILE_NAME); + } + } + } + return sponge; + } + + public static CompletableFuture savePluginsInMetricsConfig(final Map entries) { + return SpongeConfigs.getCommon().updateSetting("metrics.plugin-states", entries, + new TypeToken>() { private static final long serialVersionUID = -1L;}); + } + + public static ConfigHandle getCustomData() { + if (SpongeConfigs.customDataConfigAdapter == null) { + SpongeConfigs.customDataConfigAdapter = SpongeConfigs.create(new CustomDataConfig(), CustomDataConfig.FILE_NAME); + } + return customDataConfigAdapter; + } + + public static ConfigHandle getTracker() { + if (SpongeConfigs.trackerConfigAdapter == null) { + SpongeConfigs.trackerConfigAdapter = SpongeConfigs.create(new TrackerConfig(), TrackerConfig.FILE_NAME); + } + return SpongeConfigs.trackerConfigAdapter; + } + + + public static InheritableConfigHandle getForWorld(final org.spongepowered.api.world.World spongeWorld) { + return getForWorld((net.minecraft.world.World) spongeWorld); + } + + public static InheritableConfigHandle getForWorld(final net.minecraft.world.World mcWorld) { + return ((WorldInfoBridge) mcWorld.getWorldInfo()).bridge$getConfigAdapter(); + } + + // Config-internal + // everything below here should (mostly) not be directly accessed + // unless performing specialized initialization (mostly world loads) + + public static HoconConfigurationLoader createLoader(final Path path) { + // use File for slightly better performance on directory creation + // Files.exists uses an exception for this :( + final File parentFile = path.getParent().toFile(); + if (!parentFile.exists()) { + parentFile.mkdirs(); + } + + return HoconConfigurationLoader.builder() + .setPath(path) + .setDefaultOptions(OPTIONS) + .build(); + } + + public static ConfigHandle create(final T instance, final String fileName) { + // TODO(zml): Rather than rethrowing exceptions: + // - gather all errors on load + // - as soon as the first error has occurred, disable saving for the rest of the server runtime + // - once server has loaded, list every error + // - warn that configs will not save + // What happens when a config fails to load? Will using default settings cause anything to be damaged? + final HoconConfigurationLoader loader = createLoader(SpongeConfigs.getDirectory().resolve(fileName)); + try { + final ConfigHandle handle = new ConfigHandle<>(instance, loader); + handle.load(); + return handle; + } catch (final IOException | ObjectMappingException ex) { + LOGGER.error("Unable to load configuration {}. Sponge will operate in " + + "fallback mode, with default configuration options and will not write to the invalid file", fileName, ex); + return new ConfigHandle<>(instance); + } + } + + private static InheritableConfigHandle getGlobalInheritable() { + if (global == null) { + synchronized (initLock) { + if (global == null) { + try { + global = new InheritableConfigHandle<>(new GlobalConfig(), + createLoader(getDirectory().resolve(GlobalConfig.FILE_NAME)), null); + global.load(); + } catch (IOException | ObjectMappingException e) { + LOGGER.error("Unable to load global world configuration in {}. Sponge will run with default settings", GlobalConfig.FILE_NAME, e); + global = new InheritableConfigHandle<>(new GlobalConfig(), null); + } + } + } + } + return global; + } + + public static InheritableConfigHandle createDetached() { + return new InheritableConfigHandle<>(new WorldConfig(), SpongeConfigs.getGlobalInheritable()); + } + + public static InheritableConfigHandle createWorld(final @Nullable DimensionType legacyType, final ResourceKey world) { + // Path format: config/sponge/worlds//.conf + final Path configPath = getDirectory().resolve(Paths.get("worlds", world.getNamespace(), world.getValue() + ".conf")); + if (legacyType != null) { + // Legacy config path: config/sponge/worlds////world.conf + final String legacyName = getLegacyWorldName(world); + if (legacyName != null) { + final Path legacyPath = getDirectory().resolve(Paths.get("worlds", legacyType.getKey().getNamespace(), + getLegacyValue(legacyType.getKey()), legacyName, "world.conf")); + if (legacyPath.toFile().isFile() && !configPath.toFile().isFile()) { + try { + Files.createDirectories(configPath.getParent()); + Files.move(legacyPath, configPath); + final Path legacyParent = legacyPath.getParent(); + try (DirectoryStream str = Files.newDirectoryStream(legacyParent)) { + if (!str.iterator().hasNext()) { + Files.delete(legacyParent); + } + } + } catch (final IOException ex) { + LOGGER.error("Unable to migrate config for world {} from legacy location {}", world, legacyPath, ex); + } + } + } + } + try { + final InheritableConfigHandle config = new InheritableConfigHandle<>(new WorldConfig(), SpongeConfigs.createLoader(configPath), + SpongeConfigs.getGlobalInheritable()); + config.load(); + return config; + } catch (final IOException | ObjectMappingException ex) { + LOGGER.error("Unable to load configuration for world {}. Sponge will use a " + + "fallback configuration with default values that will not save.", world, ex); + return createDetached(); + } + } + + private static String getLegacyValue(final ResourceKey dimensionType) { + if (dimensionType.equals(DimensionTypes.THE_NETHER.get().getKey())) { + return "nether"; + } else { + return dimensionType.getValue(); + } + } + + private static @Nullable String getLegacyWorldName(final ResourceKey world) { + if (world.equals(SpongeWorldManager.VANILLA_OVERWORLD)) { + return "world"; + } else if (world.equals(SpongeWorldManager.VANILLA_THE_END)) { + return "DIM1"; + } else if (world.equals(SpongeWorldManager.VANILLA_THE_NETHER)) { + return "DIM-1"; + } + return null; + } + +} diff --git a/src/main/java/org/spongepowered/common/config/category/ConfigCategory.java b/src/main/java/org/spongepowered/common/config/category/ConfigCategory.java deleted file mode 100644 index 0eab7ec433b..00000000000 --- a/src/main/java/org/spongepowered/common/config/category/ConfigCategory.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of Sponge, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.common.config.category; - -import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; - -@ConfigSerializable -public abstract class ConfigCategory { - -} diff --git a/src/main/java/org/spongepowered/common/config/category/BrokenModCategory.java b/src/main/java/org/spongepowered/common/config/common/BrokenModCategory.java similarity index 93% rename from src/main/java/org/spongepowered/common/config/category/BrokenModCategory.java rename to src/main/java/org/spongepowered/common/config/common/BrokenModCategory.java index 244c9f5a64f..104a35148a4 100644 --- a/src/main/java/org/spongepowered/common/config/category/BrokenModCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/BrokenModCategory.java @@ -22,18 +22,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; @ConfigSerializable -public class BrokenModCategory extends ConfigCategory { +public class BrokenModCategory { @Setting(value = "broken-network-handler-mods", comment = "A list of mod ids that have broken network handlers (they interact with the game from a Netty handler thread).\n" + "All network handlers from a forcibly scheduled to run on the main thread.\n" diff --git a/src/main/java/org/spongepowered/common/config/category/BungeeCordCategory.java b/src/main/java/org/spongepowered/common/config/common/BungeeCordCategory.java similarity index 93% rename from src/main/java/org/spongepowered/common/config/category/BungeeCordCategory.java rename to src/main/java/org/spongepowered/common/config/common/BungeeCordCategory.java index c77a4389a33..393e4f309df 100644 --- a/src/main/java/org/spongepowered/common/config/category/BungeeCordCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/BungeeCordCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class BungeeCordCategory extends ConfigCategory { +public class BungeeCordCategory { @Setting(value = "ip-forwarding", comment = "If 'true', allows BungeeCord to forward IP address, UUID, and Game Profile to this server.") private boolean ipForwarding = false; @@ -36,4 +36,4 @@ public class BungeeCordCategory extends ConfigCategory { public boolean getIpForwarding() { return this.ipForwarding; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/CommandsCategory.java b/src/main/java/org/spongepowered/common/config/common/CommandsCategory.java similarity index 97% rename from src/main/java/org/spongepowered/common/config/category/CommandsCategory.java rename to src/main/java/org/spongepowered/common/config/common/CommandsCategory.java index 255a87d8390..2f4b498017c 100644 --- a/src/main/java/org/spongepowered/common/config/category/CommandsCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/CommandsCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class CommandsCategory extends ConfigCategory { +public class CommandsCategory { @Setting(comment = "Command aliases will resolve conflicts when multiple plugins request a specific command, \n" + "Correct syntax is = e.g. \"sethome=homeplugin\"") diff --git a/src/main/java/org/spongepowered/common/config/category/CommandsHiddenCategory.java b/src/main/java/org/spongepowered/common/config/common/CommandsHiddenCategory.java similarity index 95% rename from src/main/java/org/spongepowered/common/config/category/CommandsHiddenCategory.java rename to src/main/java/org/spongepowered/common/config/common/CommandsHiddenCategory.java index c706ded5378..1466c8a5863 100644 --- a/src/main/java/org/spongepowered/common/config/category/CommandsHiddenCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/CommandsHiddenCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class CommandsHiddenCategory extends ConfigCategory { +public class CommandsHiddenCategory { @Setting(value = "hide-on-discovery-attempt", comment = "If this is true, when a user tries to tab complete a command, or use \"/sponge which\" or \n" diff --git a/src/main/java/org/spongepowered/common/config/type/GlobalConfig.java b/src/main/java/org/spongepowered/common/config/common/CommonConfig.java similarity index 65% rename from src/main/java/org/spongepowered/common/config/type/GlobalConfig.java rename to src/main/java/org/spongepowered/common/config/common/CommonConfig.java index 07afedb60ec..e412d500e4e 100644 --- a/src/main/java/org/spongepowered/common/config/type/GlobalConfig.java +++ b/src/main/java/org/spongepowered/common/config/common/CommonConfig.java @@ -22,41 +22,38 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.type; +package org.spongepowered.common.config.common; -import com.google.common.base.Function; -import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import ninja.leaping.configurate.objectmapping.Setting; -import org.spongepowered.common.config.category.BrokenModCategory; -import org.spongepowered.common.config.category.BungeeCordCategory; -import org.spongepowered.common.config.category.PhaseTrackerCategory; -import org.spongepowered.common.config.category.CommandsCategory; -import org.spongepowered.common.config.category.ExploitCategory; -import org.spongepowered.common.config.category.GlobalGeneralCategory; -import org.spongepowered.common.config.category.GlobalWorldCategory; -import org.spongepowered.common.config.category.ModuleCategory; -import org.spongepowered.common.config.category.MovementChecksCategory; -import org.spongepowered.common.config.category.OptimizationCategory; -import org.spongepowered.common.config.category.PermissionCategory; -import org.spongepowered.common.config.category.ServicesCategory; -import org.spongepowered.common.config.category.SqlCategory; -import org.spongepowered.common.config.category.MetricsCategory; -import org.spongepowered.common.config.category.TeleportHelperCategory; +import org.spongepowered.common.config.Config; import org.spongepowered.common.util.IpSet; import java.net.InetAddress; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Predicate; -import javax.annotation.Nullable; +/** + * Sponge's core configuration. + * + *

The options in this file are non-inheritable.

+ * + *

Because of how early in the engine lifecycle this configuration is loaded, + * the configuration and its categories may not reference + * Minecraft classes

+ */ +public class CommonConfig implements Config { + + public static final String FILE_NAME = "sponge.conf"; -public class GlobalConfig extends GeneralConfigBase { + @Setting + private GeneralCategory general = new GeneralCategory(); - @Setting(comment = "Configuration options related to the Sql service, including connection aliases etc") + @Setting(comment = "Configuration options related to the SQL manager, including connection aliases etc") private SqlCategory sql = new SqlCategory(); @Setting @@ -80,35 +77,37 @@ public class GlobalConfig extends GeneralConfigBase { @Setting(value = "optimizations") private OptimizationCategory optimizations = new OptimizationCategory(); - @Setting - protected GlobalGeneralCategory general = new GlobalGeneralCategory(); - - @Setting - protected GlobalWorldCategory world = new GlobalWorldCategory(); - @Setting(value = "cause-tracker") private PhaseTrackerCategory causeTracker = new PhaseTrackerCategory(); @Setting(value = "teleport-helper", comment = "Blocks to blacklist for safe teleportation.") private TeleportHelperCategory teleportHelper = new TeleportHelperCategory(); - @Setting("movement-checks") - private MovementChecksCategory movementChecks = new MovementChecksCategory(); - @Setting(value = "broken-mods", comment = "Stopgap measures for dealing with broken mods") private BrokenModCategory brokenMods = new BrokenModCategory(); - @Setting(value = "metrics") - private MetricsCategory metricsCategory = new MetricsCategory(); - @Setting(value = "service-registration", comment = "Enables server owners to require specific plugins to provide Sponge services") private ServicesCategory servicesCategory = new ServicesCategory(); - public GlobalConfig() { + @Setting + private DebugCategory debug = new DebugCategory(); + + @Setting + private TimingsCategory timings = new TimingsCategory(); + + @Setting + private WorldCategory world = new WorldCategory(); + + + public CommonConfig() { super(); } + public GeneralCategory getGeneral() { + return this.general; + } + public BrokenModCategory getBrokenMods() { return this.brokenMods; } @@ -138,16 +137,9 @@ public ServicesCategory getServicesCategory() { } public Map> getIpSets() { - return ImmutableMap.copyOf(Maps.transformValues(this.ipSets, new Function, Predicate>() { - @Nullable - @Override - public Predicate apply(List input) { - return Predicates.and(input); - } - })); + return ImmutableMap.copyOf(Maps.transformValues(this.ipSets, Predicates::and)); } - public ExploitCategory getExploits() { return this.exploits; } @@ -160,16 +152,6 @@ public Predicate getIpSet(String name) { return this.ipSets.containsKey(name) ? Predicates.and(this.ipSets.get(name)) : null; } - @Override - public GlobalGeneralCategory getGeneral() { - return this.general; - } - - @Override - public GlobalWorldCategory getWorld() { - return this.world; - } - public PhaseTrackerCategory getPhaseTracker() { return this.causeTracker; } @@ -178,11 +160,16 @@ public TeleportHelperCategory getTeleportHelper() { return this.teleportHelper; } - public MovementChecksCategory getMovementChecks() { - return this.movementChecks; + public DebugCategory getDebug() { + return this.debug; } - public MetricsCategory getMetricsCategory() { - return this.metricsCategory; + public TimingsCategory getTimings() { + return this.timings; } + + public WorldCategory getWorld() { + return this.world; + } + } diff --git a/src/main/java/org/spongepowered/common/config/category/DebugCategory.java b/src/main/java/org/spongepowered/common/config/common/DebugCategory.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/category/DebugCategory.java rename to src/main/java/org/spongepowered/common/config/common/DebugCategory.java index 4f6587cbdc2..de811c955b4 100644 --- a/src/main/java/org/spongepowered/common/config/category/DebugCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/DebugCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class DebugCategory extends ConfigCategory { +public class DebugCategory { @Setting(value = "thread-contention-monitoring", comment = "If 'true', Java's thread contention monitoring for thread dumps is enabled.") private boolean enableThreadContentionMonitoring = false; diff --git a/src/main/java/org/spongepowered/common/config/category/EigenRedstoneCategory.java b/src/main/java/org/spongepowered/common/config/common/EigenRedstoneCategory.java similarity index 95% rename from src/main/java/org/spongepowered/common/config/category/EigenRedstoneCategory.java rename to src/main/java/org/spongepowered/common/config/common/EigenRedstoneCategory.java index 9ece6ea6c12..97eb2cb9363 100644 --- a/src/main/java/org/spongepowered/common/config/category/EigenRedstoneCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/EigenRedstoneCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class EigenRedstoneCategory extends ConfigCategory { +public class EigenRedstoneCategory { @Setting(value = "enabled", comment = "If 'true', uses theosib's redstone implementation which improves performance. \n" + "See https://bugs.mojang.com/browse/MC-11193 and \n " diff --git a/src/main/java/org/spongepowered/common/config/category/ExploitCategory.java b/src/main/java/org/spongepowered/common/config/common/ExploitCategory.java similarity index 98% rename from src/main/java/org/spongepowered/common/config/category/ExploitCategory.java rename to src/main/java/org/spongepowered/common/config/common/ExploitCategory.java index 7e31e1e5960..6e587fd9593 100644 --- a/src/main/java/org/spongepowered/common/config/category/ExploitCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/ExploitCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class ExploitCategory extends ConfigCategory { +public class ExploitCategory { @Setting(value = "prevent-creative-itemstack-name-exploit", comment = "Prevents an exploit in which the client sends a packet with the \n" + "itemstack name exceeding the string limit.") diff --git a/src/main/java/org/spongepowered/common/config/category/GeneralCategory.java b/src/main/java/org/spongepowered/common/config/common/GeneralCategory.java similarity index 90% rename from src/main/java/org/spongepowered/common/config/category/GeneralCategory.java rename to src/main/java/org/spongepowered/common/config/common/GeneralCategory.java index 817418948ac..b9490581177 100644 --- a/src/main/java/org/spongepowered/common/config/category/GeneralCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/GeneralCategory.java @@ -22,14 +22,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class GeneralCategory extends ConfigCategory { - +public class GeneralCategory { + + @Setting(value = "file-io-thread-sleep", comment = "If 'true', sleeping between chunk saves will be enabled, beware of memory issues.") + private boolean fileIOThreadSleep = false; + @Setting(value = "plugins-dir", comment = "Additional directory to search for plugins, relative to the \n" + "execution root or specified as an absolute path. \n" + "Note that the default: \"${CANONICAL_MODS_DIR}/plugins\" \n" @@ -46,11 +49,15 @@ public class GeneralCategory extends ConfigCategory { + "Note: It is not recommended to set this to \"${CANONICAL_CONFIG_DIR}/sponge\", as there is \n" + "a possibility that plugin configurations can conflict the Sponge core configurations. \n") private String configDir = "${CANONICAL_GAME_DIR}/config"; - + + public boolean getFileIoThreadSleep() { + return this.fileIOThreadSleep; + } + public String pluginsDir() { return this.pluginsDir; } - + public void setPluginsDir(String pluginsDir) { this.pluginsDir = pluginsDir; } @@ -62,4 +69,4 @@ public String configDir() { public void setConfigDir(String configDir) { this.configDir = configDir; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/ModuleCategory.java b/src/main/java/org/spongepowered/common/config/common/ModuleCategory.java similarity index 97% rename from src/main/java/org/spongepowered/common/config/category/ModuleCategory.java rename to src/main/java/org/spongepowered/common/config/common/ModuleCategory.java index f4e1b9ea1b8..2d3fa3026da 100644 --- a/src/main/java/org/spongepowered/common/config/category/ModuleCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/ModuleCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class ModuleCategory extends ConfigCategory { +public class ModuleCategory { @Setting(value = "bungeecord") private boolean pluginBungeeCord = false; diff --git a/src/main/java/org/spongepowered/common/config/category/OptimizationCategory.java b/src/main/java/org/spongepowered/common/config/common/OptimizationCategory.java similarity index 97% rename from src/main/java/org/spongepowered/common/config/category/OptimizationCategory.java rename to src/main/java/org/spongepowered/common/config/common/OptimizationCategory.java index 455db068e66..27c54d49604 100644 --- a/src/main/java/org/spongepowered/common/config/category/OptimizationCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/OptimizationCategory.java @@ -22,15 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; -import org.spongepowered.common.launch.Launcher; -import org.spongepowered.common.util.MissingImplementationException; @ConfigSerializable -public class OptimizationCategory extends ConfigCategory { +public class OptimizationCategory { @Setting(value = "drops-pre-merge", comment = "If 'true', block item drops are pre-processed to avoid \n" + "having to spawn extra entities that will be merged post spawning. \n" @@ -123,7 +121,7 @@ public class OptimizationCategory extends ConfigCategory { public OptimizationCategory() { // Enabled by default on SpongeVanilla, disabled by default on SpongeForge. // Because of how early this constructor gets called, we can't use SpongeImplHooks or even Game - this.preItemDropMerge = Launcher.getInstance().isVanilla(); + this.preItemDropMerge = true; //Launcher.getInstance().isVanilla(); // TODO: how to get this info even earlier } diff --git a/src/main/java/org/spongepowered/common/config/category/PermissionCategory.java b/src/main/java/org/spongepowered/common/config/common/PermissionCategory.java similarity index 94% rename from src/main/java/org/spongepowered/common/config/category/PermissionCategory.java rename to src/main/java/org/spongepowered/common/config/common/PermissionCategory.java index 50d671f04aa..fce4b2db74f 100644 --- a/src/main/java/org/spongepowered/common/config/category/PermissionCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/PermissionCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class PermissionCategory extends ConfigCategory { +public class PermissionCategory { @Setting(value = "forge-permissions-handler", comment = "If 'true', Sponge plugins will be used to handle permissions rather " + "than any Forge mod") diff --git a/src/main/java/org/spongepowered/common/config/category/PhaseTrackerCategory.java b/src/main/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java similarity index 97% rename from src/main/java/org/spongepowered/common/config/category/PhaseTrackerCategory.java rename to src/main/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java index 57f0e493b5e..2ad0b4bae3b 100644 --- a/src/main/java/org/spongepowered/common/config/category/PhaseTrackerCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java @@ -22,18 +22,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; -import org.spongepowered.common.launch.Launcher; -import org.spongepowered.common.util.MissingImplementationException; import java.util.HashMap; import java.util.Map; @ConfigSerializable -public class PhaseTrackerCategory extends ConfigCategory { +public class PhaseTrackerCategory { @Setting(value = "verbose", comment = "If 'true', the phase tracker will print out when there are too many phases \n" + "being entered, usually considered as an issue of phase re-entrance and \n" @@ -179,7 +177,7 @@ public Map getAutoFixedTiles() { } private boolean isVanilla() { - return Launcher.getInstance().isVanilla(); + return true; //Launcher.getInstance().isVanilla(); // TODO: access earlier } public void setAutoFixedTiles(Map autoFixedTiles) { diff --git a/src/main/java/org/spongepowered/common/config/category/ServicesCategory.java b/src/main/java/org/spongepowered/common/config/common/ServicesCategory.java similarity index 97% rename from src/main/java/org/spongepowered/common/config/category/ServicesCategory.java rename to src/main/java/org/spongepowered/common/config/common/ServicesCategory.java index e3533663891..0b0d061ed76 100644 --- a/src/main/java/org/spongepowered/common/config/category/ServicesCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/ServicesCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public final class ServicesCategory extends ConfigCategory { +public final class ServicesCategory { @Setting(value = "service-plugin", comment = "Services specified here can be implemented by plugins. To ensure that a" diff --git a/src/main/java/org/spongepowered/common/config/category/SqlCategory.java b/src/main/java/org/spongepowered/common/config/common/SqlCategory.java similarity index 94% rename from src/main/java/org/spongepowered/common/config/category/SqlCategory.java rename to src/main/java/org/spongepowered/common/config/common/SqlCategory.java index 34a69b53946..d2d7d393cc9 100644 --- a/src/main/java/org/spongepowered/common/config/category/SqlCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/SqlCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class SqlCategory extends ConfigCategory { +public class SqlCategory { @Setting(comment = "Aliases for SQL connections, in the format jdbc:protocol://[username[:password]@]host/database") private Map aliases = new HashMap<>(); @@ -39,4 +39,4 @@ public class SqlCategory extends ConfigCategory { public Map getAliases() { return this.aliases; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/StructureModCategory.java b/src/main/java/org/spongepowered/common/config/common/StructureModCategory.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/category/StructureModCategory.java rename to src/main/java/org/spongepowered/common/config/common/StructureModCategory.java index 05ef0a22c44..be1c42116b7 100644 --- a/src/main/java/org/spongepowered/common/config/category/StructureModCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/StructureModCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class StructureModCategory extends ConfigCategory { +public class StructureModCategory { @Setting(value = "enabled", comment = "If 'false', this mod will never save its structures. This may\n" + "break some mod functionalities when requesting to locate their\n" diff --git a/src/main/java/org/spongepowered/common/config/category/StructureSaveCategory.java b/src/main/java/org/spongepowered/common/config/common/StructureSaveCategory.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/category/StructureSaveCategory.java rename to src/main/java/org/spongepowered/common/config/common/StructureSaveCategory.java index 4c3b082227e..9ced9bd58b5 100644 --- a/src/main/java/org/spongepowered/common/config/category/StructureSaveCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/StructureSaveCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class StructureSaveCategory extends ConfigCategory { +public class StructureSaveCategory { @Setting(value = "enabled", comment = "If 'false', disables the modification to prevent certain structures\n" + "from saving to the world's data folder. If you wish to prevent certain\n" diff --git a/src/main/java/org/spongepowered/common/config/category/TeleportHelperCategory.java b/src/main/java/org/spongepowered/common/config/common/TeleportHelperCategory.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/category/TeleportHelperCategory.java rename to src/main/java/org/spongepowered/common/config/common/TeleportHelperCategory.java index 8d3239213d7..c2544fd2968 100644 --- a/src/main/java/org/spongepowered/common/config/category/TeleportHelperCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/TeleportHelperCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.List; @ConfigSerializable -public class TeleportHelperCategory extends ConfigCategory { +public class TeleportHelperCategory { @Setting(value = "force-blacklist", comment = "If 'true', this blacklist will always be respected, otherwise, plugins can choose whether \n" + "or not to respect it.") diff --git a/src/main/java/org/spongepowered/common/config/category/TimingsCategory.java b/src/main/java/org/spongepowered/common/config/common/TimingsCategory.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/category/TimingsCategory.java rename to src/main/java/org/spongepowered/common/config/common/TimingsCategory.java index d7481de7b70..3d2ae144885 100644 --- a/src/main/java/org/spongepowered/common/config/category/TimingsCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/TimingsCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import com.google.common.collect.Lists; import ninja.leaping.configurate.objectmapping.Setting; @@ -31,7 +31,7 @@ import java.util.List; @ConfigSerializable -public class TimingsCategory extends ConfigCategory { +public final class TimingsCategory { @Setting private boolean verbose = false; @@ -91,4 +91,4 @@ public void setHistoryLength(int historyLength) { this.historyLength = historyLength; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/GlobalWorldCategory.java b/src/main/java/org/spongepowered/common/config/common/WorldCategory.java similarity index 95% rename from src/main/java/org/spongepowered/common/config/category/GlobalWorldCategory.java rename to src/main/java/org/spongepowered/common/config/common/WorldCategory.java index 47c37af3530..a774ba969dc 100644 --- a/src/main/java/org/spongepowered/common/config/category/GlobalWorldCategory.java +++ b/src/main/java/org/spongepowered/common/config/common/WorldCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.common; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -32,7 +32,7 @@ import java.util.UUID; @ConfigSerializable -public class GlobalWorldCategory extends WorldCategory { +public final class WorldCategory { @Setting(value = "auto-player-save-interval", comment = "The auto-save tick interval used when saving global player data. (Default: 900) \n" + "Note: 20 ticks is equivalent to 1 second. Set to 0 to disable.") @@ -51,7 +51,7 @@ public class GlobalWorldCategory extends WorldCategory { + "Note: If you are using SpongeForge, make sure to enter any mod fake player's UUID to this list.") private List invalidLookupUuids = new ArrayList<>(); - public GlobalWorldCategory() { + public WorldCategory() { this.invalidLookupUuids.add(UUID.fromString("00000000-0000-0000-0000-000000000000")); this.invalidLookupUuids.add(UUID.fromString("0d0c4ca0-4ff1-11e4-916c-0800200c9a66")); // ComputerCraft FakePlayer this.invalidLookupUuids.add(UUID.fromString("41c82c87-7afb-4024-ba57-13d2c99cae77")); // Forge FakePlayer @@ -65,7 +65,7 @@ public boolean getLeafDecay() { return this.leafDecay; } - public void setLeafDecay(boolean flag) { + public void setLeafDecay(final boolean flag) { this.leafDecay = flag; } @@ -79,4 +79,4 @@ public int getGameProfileQueryTaskInterval() { public List getInvalidLookupUuids() { return this.invalidLookupUuids; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/type/CustomDataConfig.java b/src/main/java/org/spongepowered/common/config/customdata/CustomDataConfig.java similarity index 87% rename from src/main/java/org/spongepowered/common/config/type/CustomDataConfig.java rename to src/main/java/org/spongepowered/common/config/customdata/CustomDataConfig.java index 57cf6ef822c..d6f0a649b60 100644 --- a/src/main/java/org/spongepowered/common/config/type/CustomDataConfig.java +++ b/src/main/java/org/spongepowered/common/config/customdata/CustomDataConfig.java @@ -22,12 +22,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.type; +package org.spongepowered.common.config.customdata; import ninja.leaping.configurate.objectmapping.Setting; -import org.spongepowered.common.config.category.CustomDataRegistrationCategory; +import org.spongepowered.common.config.Config; -public class CustomDataConfig extends ConfigBase { +public final class CustomDataConfig implements Config { + + public static final String FILE_NAME = "custom_data.conf"; @Setting(value = "data-registration") private CustomDataRegistrationCategory datalists = new CustomDataRegistrationCategory(); diff --git a/src/main/java/org/spongepowered/common/config/category/CustomDataRegistrationCategory.java b/src/main/java/org/spongepowered/common/config/customdata/CustomDataRegistrationCategory.java similarity index 98% rename from src/main/java/org/spongepowered/common/config/category/CustomDataRegistrationCategory.java rename to src/main/java/org/spongepowered/common/config/customdata/CustomDataRegistrationCategory.java index a959a30f293..49f2ebac332 100644 --- a/src/main/java/org/spongepowered/common/config/category/CustomDataRegistrationCategory.java +++ b/src/main/java/org/spongepowered/common/config/customdata/CustomDataRegistrationCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.customdata; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -37,7 +37,7 @@ import java.util.concurrent.ConcurrentSkipListSet; @ConfigSerializable -public class CustomDataRegistrationCategory extends ConfigCategory { +public class CustomDataRegistrationCategory { /** * This isn't so much of a config option, this is more of allowing the diff --git a/src/main/java/org/spongepowered/common/config/type/GeneralConfigBase.java b/src/main/java/org/spongepowered/common/config/inheritable/BaseConfig.java similarity index 73% rename from src/main/java/org/spongepowered/common/config/type/GeneralConfigBase.java rename to src/main/java/org/spongepowered/common/config/inheritable/BaseConfig.java index 5f10d3798f5..0e675bff1a3 100644 --- a/src/main/java/org/spongepowered/common/config/type/GeneralConfigBase.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/BaseConfig.java @@ -22,32 +22,21 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.type; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; -import org.spongepowered.common.config.category.PlayerBlockTracker; -import org.spongepowered.common.config.category.DebugCategory; -import org.spongepowered.common.config.category.EntityActivationRangeCategory; -import org.spongepowered.common.config.category.EntityCategory; -import org.spongepowered.common.config.category.EntityCollisionCategory; -import org.spongepowered.common.config.category.GeneralCategory; -import org.spongepowered.common.config.category.LoggingCategory; -import org.spongepowered.common.config.category.SpawnerCategory; -import org.spongepowered.common.config.category.BlockEntityActivationCategory; -import org.spongepowered.common.config.category.TimingsCategory; -import org.spongepowered.common.config.category.WorldCategory; +import ninja.leaping.configurate.transformation.ConfigurationTransformation; +import org.spongepowered.common.config.Config; import java.util.ArrayList; import java.util.List; -public class GeneralConfigBase extends ConfigBase { +public abstract class BaseConfig implements Config { @Setting protected WorldCategory world = new WorldCategory(); @Setting(value = "player-block-tracker") private PlayerBlockTracker playerBlockTracker = new PlayerBlockTracker(); - @Setting - private DebugCategory debug = new DebugCategory(); @Setting(value = "entity") private EntityCategory entity = new EntityCategory(); @Setting(value = "entity-activation-range") @@ -55,27 +44,21 @@ public class GeneralConfigBase extends ConfigBase { @Setting(value = "entity-collisions") private EntityCollisionCategory entityCollisionCategory = new EntityCollisionCategory(); @Setting - private GeneralCategory general = new GeneralCategory(); - @Setting private LoggingCategory logging = new LoggingCategory(); @Setting(value = "spawner", comment = "Used to control spawn limits around players. \n" + "Note: The radius uses the lower value of mob spawn range and server's view distance.") private SpawnerCategory spawner = new SpawnerCategory(); @Setting(value = "tileentity-activation") private BlockEntityActivationCategory blockEntityActivationCategory = new BlockEntityActivationCategory(); - @Setting - private TimingsCategory timings = new TimingsCategory(); @Setting(value = "world-generation-modifiers", comment = "World Generation Modifiers to apply to the world") private final List worldModifiers = new ArrayList<>(); + @Setting("movement-checks") + private MovementChecksCategory movementChecks = new MovementChecksCategory(); public PlayerBlockTracker getBlockTracking() { return this.playerBlockTracker; } - public DebugCategory getDebug() { - return this.debug; - } - public EntityCategory getEntity() { return this.entity; } @@ -88,10 +71,6 @@ public EntityCollisionCategory getEntityCollisionCategory() { return this.entityCollisionCategory; } - public GeneralCategory getGeneral() { - return this.general; - } - public LoggingCategory getLogging() { return this.logging; } @@ -108,11 +87,26 @@ public BlockEntityActivationCategory getTileEntityActivationRange() { return this.blockEntityActivationCategory; } - public TimingsCategory getTimings() { - return this.timings; - } - public List getWorldGenModifiers() { return this.worldModifiers; } + + public MovementChecksCategory getMovementChecks() { + return this.movementChecks; + } + + @Override + public ConfigurationTransformation getTransformation() { + return ConfigurationTransformation.versionedBuilder() + // move everything out of sponge subcategory + .addVersion(1, buildInitialToOne()) + .build(); + } + + protected ConfigurationTransformation buildInitialToOne() { + return ConfigurationTransformation.builder() + .addAction(new Object[] {"sponge"}, (path, value) -> new Object[0]) + .build(); + } } + diff --git a/src/main/java/org/spongepowered/common/config/category/BlockEntityActivationCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/BlockEntityActivationCategory.java similarity index 95% rename from src/main/java/org/spongepowered/common/config/category/BlockEntityActivationCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/BlockEntityActivationCategory.java index f23f03ed171..3706796ea81 100644 --- a/src/main/java/org/spongepowered/common/config/category/BlockEntityActivationCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/BlockEntityActivationCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class BlockEntityActivationCategory extends ConfigCategory { +public final class BlockEntityActivationCategory { @Setting(value = "auto-populate", comment = "If 'true', newly discovered block entities will be added to this config with default settings.") private boolean autoPopulate = false; @@ -60,4 +60,4 @@ public int getDefaultTickRate() { public Map getModList() { return this.modList; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/BlockEntityActivationModCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/BlockEntityActivationModCategory.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/category/BlockEntityActivationModCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/BlockEntityActivationModCategory.java index 55eab0f79f2..08108929f36 100644 --- a/src/main/java/org/spongepowered/common/config/category/BlockEntityActivationModCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/BlockEntityActivationModCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class BlockEntityActivationModCategory extends ConfigCategory { +public final class BlockEntityActivationModCategory { @Setting(value = "enabled", comment = "If 'false', tileentity activation rules for this mod will be ignored and always tick.") private boolean isEnabled = true; @@ -79,4 +79,4 @@ public Map getTileEntityRangeList() { public Map getTileEntityTickRateList() { return this.tileEntityTickRateList; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/CollisionModCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/CollisionModCategory.java similarity index 93% rename from src/main/java/org/spongepowered/common/config/category/CollisionModCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/CollisionModCategory.java index 15f1cbdca92..794b1051bd1 100644 --- a/src/main/java/org/spongepowered/common/config/category/CollisionModCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/CollisionModCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class CollisionModCategory extends ConfigCategory { +public final class CollisionModCategory { @Setting(value = "enabled", comment = "If 'false', entity collision rules for this mod will be ignored.") private boolean isEnabled = true; @@ -71,11 +71,11 @@ public Map getDefaultMaxCollisions() { return this.defaultMaxCollisions; } - public Map getBlockList() { + public Map getBlockList() { return this.blockList; } - public Map getEntityList() { + public Map getEntityList() { return this.entityList; } } diff --git a/src/main/java/org/spongepowered/common/config/category/EntityActivationModCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/EntityActivationModCategory.java similarity index 92% rename from src/main/java/org/spongepowered/common/config/category/EntityActivationModCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/EntityActivationModCategory.java index e35974e65da..9a78ace9cd0 100644 --- a/src/main/java/org/spongepowered/common/config/category/EntityActivationModCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/EntityActivationModCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class EntityActivationModCategory extends ConfigCategory { +public final class EntityActivationModCategory { @Setting(value = "enabled", comment = "If 'false', entity activation rules for this mod will be ignored and always tick.") private boolean isEnabled = true; @@ -48,7 +48,7 @@ public Map getDefaultRanges() { return this.defaultRanges; } - public Map getEntityList() { + public Map getEntityList() { return this.entityList; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/EntityActivationRangeCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/EntityActivationRangeCategory.java similarity index 95% rename from src/main/java/org/spongepowered/common/config/category/EntityActivationRangeCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/EntityActivationRangeCategory.java index f25f0c53275..e744b65e14c 100644 --- a/src/main/java/org/spongepowered/common/config/category/EntityActivationRangeCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/EntityActivationRangeCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class EntityActivationRangeCategory extends ConfigCategory { +public final class EntityActivationRangeCategory { @Setting(value = "auto-populate", comment = "If 'true', newly discovered entities will be added to this config with a default value.") private boolean autoPopulate = false; @@ -59,4 +59,4 @@ public Map getDefaultRanges() { public Map getModList() { return this.modList; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/EntityCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/EntityCategory.java similarity index 97% rename from src/main/java/org/spongepowered/common/config/category/EntityCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/EntityCategory.java index a4289d99349..c9a00f0e655 100644 --- a/src/main/java/org/spongepowered/common/config/category/EntityCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/EntityCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class EntityCategory extends ConfigCategory { +public final class EntityCategory { @Setting(value = "max-bounding-box-size", comment = "Maximum size of an entity's bounding box before removing it. Set to 0 to disable") private int maxBoundingBoxSize = 1000; @@ -123,4 +123,4 @@ public int getMinimumLife() { public void setMinimumLife(int minimumLife) { this.minimumLife = Math.min(minimumLife, 20); } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/EntityCollisionCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/EntityCollisionCategory.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/category/EntityCollisionCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/EntityCollisionCategory.java index 6d996dea4ac..ccf27c5462f 100644 --- a/src/main/java/org/spongepowered/common/config/category/EntityCollisionCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/EntityCollisionCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class EntityCollisionCategory extends ConfigCategory { +public final class EntityCollisionCategory { @Setting(value = "auto-populate", comment = "If 'true', newly discovered entities/blocks will be added to this config with a default value.") private boolean autoPopulate = false; diff --git a/src/main/java/org/spongepowered/common/config/inheritable/GlobalConfig.java b/src/main/java/org/spongepowered/common/config/inheritable/GlobalConfig.java new file mode 100644 index 00000000000..023b2919598 --- /dev/null +++ b/src/main/java/org/spongepowered/common/config/inheritable/GlobalConfig.java @@ -0,0 +1,86 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.config.inheritable; + +import com.google.common.collect.ImmutableSet; +import ninja.leaping.configurate.transformation.ConfigurationTransformation; +import org.spongepowered.common.config.FileMovingConfigurationTransformation; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.common.CommonConfig; +import org.spongepowered.common.config.metrics.MetricsConfiguration; + +import java.util.Set; + +public final class GlobalConfig extends BaseConfig { + + public static final String FILE_NAME = "global.conf"; + + private static Object[] p(final Object... els) { + return els; + } + + // Paths moved to sponge.conf + private static final Set MIGRATE_SPONGE_PATHS = ImmutableSet.of( + p("world", "auto-player-save-interval"), + p("world", "leaf-decay"), + p("world", "game-profile-query-task-interval"), + p("world", "invalid-lookup-uuids"), + p("general"), + p("sql"), + p("commands"), + p("permission"), + p("modules"), + p("ip-sets"), + p("bungeecord"), + p("exploits"), + p("optimizations"), + p("cause-tracker"), + p("teleport-helper"), + p("broken-mods"), + p("service-registration"), + p("debug"), + p("timings") + ); + + // Paths moved to metrics.conf + private static final Set MIGRATE_METRICS_PATHS = ImmutableSet.of( + p("metrics") + ); + + public GlobalConfig() { + super(); + } + + @Override + protected ConfigurationTransformation buildInitialToOne() { + return ConfigurationTransformation.chain( + super.buildInitialToOne(), // parent conversion + new FileMovingConfigurationTransformation(MIGRATE_SPONGE_PATHS, // move to broken-out configuration files + SpongeConfigs.createLoader(SpongeConfigs.getDirectory().resolve(CommonConfig.FILE_NAME)), true), + new FileMovingConfigurationTransformation(MIGRATE_METRICS_PATHS, + SpongeConfigs.createLoader(SpongeConfigs.getDirectory().resolve(MetricsConfiguration.FILE_NAME)), true) + ); + } +} diff --git a/src/main/java/org/spongepowered/common/config/category/LoggingCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/LoggingCategory.java similarity index 98% rename from src/main/java/org/spongepowered/common/config/category/LoggingCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/LoggingCategory.java index 25e876a9722..b9d48865621 100644 --- a/src/main/java/org/spongepowered/common/config/category/LoggingCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/LoggingCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class LoggingCategory extends ConfigCategory { +public final class LoggingCategory { @Setting(value = "block-break", comment = "Log when blocks are broken") private boolean blockBreakLogging = false; @@ -182,4 +182,4 @@ public void setLogEntitySpeedRemoval(boolean flag) { public boolean logWorldAutomaticSaving() { return this.logWorldAutomaticSaving; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/MovementChecksCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/MovementChecksCategory.java similarity index 95% rename from src/main/java/org/spongepowered/common/config/category/MovementChecksCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/MovementChecksCategory.java index d14edd738fc..de00a9a16f6 100644 --- a/src/main/java/org/spongepowered/common/config/category/MovementChecksCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/MovementChecksCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class MovementChecksCategory extends ConfigCategory { +public class MovementChecksCategory { @Setting(value = "player-moved-too-quickly", comment = "Controls whether the 'player moved too quickly!' check will be enforced") private boolean playerMovedTooQuickly = true; diff --git a/src/main/java/org/spongepowered/common/config/category/PlayerBlockTracker.java b/src/main/java/org/spongepowered/common/config/inheritable/PlayerBlockTracker.java similarity index 95% rename from src/main/java/org/spongepowered/common/config/category/PlayerBlockTracker.java rename to src/main/java/org/spongepowered/common/config/inheritable/PlayerBlockTracker.java index 2100a79c869..4bc5e520b17 100644 --- a/src/main/java/org/spongepowered/common/config/category/PlayerBlockTracker.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/PlayerBlockTracker.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.List; @ConfigSerializable -public class PlayerBlockTracker extends ConfigCategory { +public final class PlayerBlockTracker { @Setting(value = "enabled", comment = "If 'true', adds player tracking support for block positions. \n" + "Note: This should only be disabled if you do not care who caused a block to change.") @@ -51,4 +51,4 @@ public void setEnabled(boolean flag) { public List getBlockBlacklist() { return this.blockBlacklist; } -} \ No newline at end of file +} diff --git a/src/main/java/org/spongepowered/common/config/category/SpawnerCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/SpawnerCategory.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/category/SpawnerCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/SpawnerCategory.java index fe95c267617..5abade402e7 100644 --- a/src/main/java/org/spongepowered/common/config/category/SpawnerCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/SpawnerCategory.java @@ -22,13 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class SpawnerCategory extends ConfigCategory { +public final class SpawnerCategory { @Setting(value = "spawn-limit-ambient", comment = "The number of ambients the spawner can potentially spawn around a player.") private int spawnLimitAmbient = 15; @@ -48,7 +48,7 @@ public class SpawnerCategory extends ConfigCategory { private int tickRateMonster = 1; public SpawnerCategory() { - + } public int getAnimalSpawnLimit() { diff --git a/src/main/java/org/spongepowered/common/config/category/WorldCategory.java b/src/main/java/org/spongepowered/common/config/inheritable/WorldCategory.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/category/WorldCategory.java rename to src/main/java/org/spongepowered/common/config/inheritable/WorldCategory.java index 1df76c8c821..e87441ed6e9 100644 --- a/src/main/java/org/spongepowered/common/config/category/WorldCategory.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/WorldCategory.java @@ -22,18 +22,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.inheritable; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.spongepowered.common.launch.Launcher; -import org.spongepowered.common.util.MissingImplementationException; import java.util.HashMap; import java.util.Map; @ConfigSerializable -public class WorldCategory extends ConfigCategory { +public class WorldCategory { @Setting(value = "auto-save-interval", comment = "The auto-save tick interval used to save all loaded chunks in a world. \n" + "Set to 0 to disable. (Default: 900) \n" @@ -48,7 +47,7 @@ public class WorldCategory extends ConfigCategory { private boolean worldEnabled = true; @Setting(value = "load-on-startup", comment = "If 'true', this world will load on startup.") - private Boolean loadOnStartup = false; + private Boolean loadOnStartup = true; @Setting(value = "generate-spawn-on-load", comment = "If 'true', this world will generate its spawn the moment its loaded.") private Boolean generateSpawnOnLoad = false; @@ -121,7 +120,7 @@ public WorldCategory() { try { // Enabled by default on SpongeVanilla, disabled by default on SpongeForge. // Because of how early this constructor gets called, we can't use SpongeImplHooks or even Game - this.denyChunkRequests = Launcher.getInstance().isVanilla(); + this.denyChunkRequests = true; //Launcher.getInstance().isVanilla(); // TODO: figure out how to access this information even earlier } catch (Exception e) { e.printStackTrace(); } @@ -147,7 +146,7 @@ public void setChunkUnloadDelay(int delay) { this.chunkUnloadDelay = delay; } - public Boolean loadOnStartup() { + public Boolean getLoadOnStartup() { return this.loadOnStartup; } diff --git a/src/main/java/org/spongepowered/common/config/type/WorldConfig.java b/src/main/java/org/spongepowered/common/config/inheritable/WorldConfig.java similarity index 92% rename from src/main/java/org/spongepowered/common/config/type/WorldConfig.java rename to src/main/java/org/spongepowered/common/config/inheritable/WorldConfig.java index 88d344bb46c..2d3609d0d88 100644 --- a/src/main/java/org/spongepowered/common/config/type/WorldConfig.java +++ b/src/main/java/org/spongepowered/common/config/inheritable/WorldConfig.java @@ -22,8 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.type; - -public final class WorldConfig extends GeneralConfigBase { +package org.spongepowered.common.config.inheritable; +public final class WorldConfig extends BaseConfig { } diff --git a/src/main/java/org/spongepowered/common/config/category/MetricsCategory.java b/src/main/java/org/spongepowered/common/config/metrics/MetricsConfiguration.java similarity index 72% rename from src/main/java/org/spongepowered/common/config/category/MetricsCategory.java rename to src/main/java/org/spongepowered/common/config/metrics/MetricsConfiguration.java index b02e553141d..9e933a99595 100644 --- a/src/main/java/org/spongepowered/common/config/category/MetricsCategory.java +++ b/src/main/java/org/spongepowered/common/config/metrics/MetricsConfiguration.java @@ -22,20 +22,25 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.metrics; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; +import ninja.leaping.configurate.transformation.ConfigurationTransformation; import org.spongepowered.api.util.Tristate; +import org.spongepowered.common.config.Config; import org.spongepowered.plugin.PluginContainer; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.Optional; + +// TODO: migration -- `sponge/metrics` from old `global.conf` @ConfigSerializable -public class MetricsCategory { +public class MetricsConfiguration implements Config { + + public static String FILE_NAME = "metrics.conf"; @Setting(value = "global-state", comment = "The global collection state that should be respected by all plugins that have no specified " + "collection state. If undefined then it is treated as disabled.") @@ -49,10 +54,20 @@ public Tristate getGlobalCollectionState() { } public Tristate getCollectionState(PluginContainer container) { - return Optional.ofNullable(this.pluginStates.get(container.getMetadata().getId())).orElse(Tristate.UNDEFINED); + final Tristate pluginState = this.pluginStates.get(container.getMetadata().getId()); + return pluginState == null ? Tristate.UNDEFINED : pluginState; } public Map getCollectionStates() { return Collections.unmodifiableMap(this.pluginStates); } + + @Override + public ConfigurationTransformation getTransformation() { + return ConfigurationTransformation.versionedBuilder() + .addVersion(1, ConfigurationTransformation.builder() + .addAction(Config.path("metrics"), (path, value) -> new Object[0]) + .build()) + .build(); + } } diff --git a/src/main/java/org/spongepowered/common/config/type/ConfigBase.java b/src/main/java/org/spongepowered/common/config/package-info.java similarity index 77% rename from src/main/java/org/spongepowered/common/config/type/ConfigBase.java rename to src/main/java/org/spongepowered/common/config/package-info.java index f7db20c6f22..219fa3e4e11 100644 --- a/src/main/java/org/spongepowered/common/config/type/ConfigBase.java +++ b/src/main/java/org/spongepowered/common/config/package-info.java @@ -22,14 +22,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.type; - /** - * Abstract config base for sponge configurations. + * All configuration for Sponge itself. + * + *

Sponge's configuration is spread across quite a few configuration files, + * some of which are read extremely early in the game initialization. This means + * that for the most part, anything in this package should be assumed to have + * no access to any Minecraft classes.

*/ -public abstract class ConfigBase { - - ConfigBase() { - - } -} +package org.spongepowered.common.config; diff --git a/src/main/java/org/spongepowered/common/config/category/BlockEntityTrackerCategory.java b/src/main/java/org/spongepowered/common/config/tracker/BlockEntityTrackerCategory.java similarity index 94% rename from src/main/java/org/spongepowered/common/config/category/BlockEntityTrackerCategory.java rename to src/main/java/org/spongepowered/common/config/tracker/BlockEntityTrackerCategory.java index 1d15590924a..a56026278ff 100644 --- a/src/main/java/org/spongepowered/common/config/category/BlockEntityTrackerCategory.java +++ b/src/main/java/org/spongepowered/common/config/tracker/BlockEntityTrackerCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.tracker; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class BlockEntityTrackerCategory extends ConfigCategory { +public class BlockEntityTrackerCategory { @Setting(value = "auto-populate", comment = "If 'true', newly discovered tileentities will be added to this config with default settings.") private boolean autoPopulate = false; diff --git a/src/main/java/org/spongepowered/common/config/category/BlockEntityTrackerModCategory.java b/src/main/java/org/spongepowered/common/config/tracker/BlockEntityTrackerModCategory.java similarity index 94% rename from src/main/java/org/spongepowered/common/config/category/BlockEntityTrackerModCategory.java rename to src/main/java/org/spongepowered/common/config/tracker/BlockEntityTrackerModCategory.java index 85efd11db87..ee8177db26c 100644 --- a/src/main/java/org/spongepowered/common/config/category/BlockEntityTrackerModCategory.java +++ b/src/main/java/org/spongepowered/common/config/tracker/BlockEntityTrackerModCategory.java @@ -22,17 +22,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.tracker; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; -import org.spongepowered.common.config.type.TrackerConfig; import java.util.HashMap; import java.util.Map; @ConfigSerializable -public class BlockEntityTrackerModCategory extends ConfigCategory { +public class BlockEntityTrackerModCategory { @Setting(value = "enabled", comment = "If 'false', all tracking for this mod will be disabled.") private boolean isEnabled = true; diff --git a/src/main/java/org/spongepowered/common/config/category/BlockTrackerCategory.java b/src/main/java/org/spongepowered/common/config/tracker/BlockTrackerCategory.java similarity index 95% rename from src/main/java/org/spongepowered/common/config/category/BlockTrackerCategory.java rename to src/main/java/org/spongepowered/common/config/tracker/BlockTrackerCategory.java index 6f1df174322..1be812a6729 100644 --- a/src/main/java/org/spongepowered/common/config/category/BlockTrackerCategory.java +++ b/src/main/java/org/spongepowered/common/config/tracker/BlockTrackerCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.tracker; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class BlockTrackerCategory extends ConfigCategory { +public class BlockTrackerCategory { @Setting(value = "auto-populate", comment = "If 'true', newly discovered blocks will be added to this config with default settings.") private boolean autoPopulate = false; diff --git a/src/main/java/org/spongepowered/common/config/category/BlockTrackerModCategory.java b/src/main/java/org/spongepowered/common/config/tracker/BlockTrackerModCategory.java similarity index 95% rename from src/main/java/org/spongepowered/common/config/category/BlockTrackerModCategory.java rename to src/main/java/org/spongepowered/common/config/tracker/BlockTrackerModCategory.java index 72d383a79d3..f73272c9138 100644 --- a/src/main/java/org/spongepowered/common/config/category/BlockTrackerModCategory.java +++ b/src/main/java/org/spongepowered/common/config/tracker/BlockTrackerModCategory.java @@ -22,17 +22,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.tracker; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; -import org.spongepowered.common.config.type.TrackerConfig; import java.util.HashMap; import java.util.Map; @ConfigSerializable -public class BlockTrackerModCategory extends ConfigCategory { +public class BlockTrackerModCategory { @Setting(value = "enabled", comment = "If 'false', all tracking for this mod will be ignored.") private boolean isEnabled = true; diff --git a/src/main/java/org/spongepowered/common/config/category/EntityTrackerCategory.java b/src/main/java/org/spongepowered/common/config/tracker/EntityTrackerCategory.java similarity index 95% rename from src/main/java/org/spongepowered/common/config/category/EntityTrackerCategory.java rename to src/main/java/org/spongepowered/common/config/tracker/EntityTrackerCategory.java index 1e01ccc5260..2fed9f72c60 100644 --- a/src/main/java/org/spongepowered/common/config/category/EntityTrackerCategory.java +++ b/src/main/java/org/spongepowered/common/config/tracker/EntityTrackerCategory.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.tracker; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -31,7 +31,7 @@ import java.util.Map; @ConfigSerializable -public class EntityTrackerCategory extends ConfigCategory { +public class EntityTrackerCategory { @Setting(value = "auto-populate", comment = "If 'true', newly discovered entities will be added to this config with default settings.") private boolean autoPopulate = false; diff --git a/src/main/java/org/spongepowered/common/config/category/EntityTrackerModCategory.java b/src/main/java/org/spongepowered/common/config/tracker/EntityTrackerModCategory.java similarity index 93% rename from src/main/java/org/spongepowered/common/config/category/EntityTrackerModCategory.java rename to src/main/java/org/spongepowered/common/config/tracker/EntityTrackerModCategory.java index ec1e06c737e..af3fb74ec7a 100644 --- a/src/main/java/org/spongepowered/common/config/category/EntityTrackerModCategory.java +++ b/src/main/java/org/spongepowered/common/config/tracker/EntityTrackerModCategory.java @@ -22,17 +22,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.category; +package org.spongepowered.common.config.tracker; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; -import org.spongepowered.common.config.type.TrackerConfig; import java.util.HashMap; import java.util.Map; @ConfigSerializable -public class EntityTrackerModCategory extends ConfigCategory { +public class EntityTrackerModCategory { @Setting(value = "enabled", comment = "If 'false', all tracking for this mod will be ignored.") private boolean isEnabled = true; @@ -52,7 +51,7 @@ public EntityTrackerModCategory() { public EntityTrackerModCategory(String name) { if (name.equals("minecraft")) { // These entities don't modify the world or spawn any drops - // Skipping bulk capturing shoukd be transparent to plugins + // Skipping bulk capturing should be transparent to plugins this.blockBulkCaptureMap.put("item", false); this.blockBulkCaptureMap.put("experience_orb", false); this.blockBulkCaptureMap.put("leash_hitch", false); diff --git a/src/main/java/org/spongepowered/common/config/type/TrackerConfig.java b/src/main/java/org/spongepowered/common/config/tracker/TrackerConfig.java similarity index 89% rename from src/main/java/org/spongepowered/common/config/type/TrackerConfig.java rename to src/main/java/org/spongepowered/common/config/tracker/TrackerConfig.java index 69df91bec19..6d1f8925190 100644 --- a/src/main/java/org/spongepowered/common/config/type/TrackerConfig.java +++ b/src/main/java/org/spongepowered/common/config/tracker/TrackerConfig.java @@ -22,16 +22,21 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.config.type; +package org.spongepowered.common.config.tracker; import ninja.leaping.configurate.objectmapping.Setting; -import org.spongepowered.common.config.category.BlockTrackerCategory; -import org.spongepowered.common.config.category.EntityTrackerCategory; -import org.spongepowered.common.config.category.BlockEntityTrackerCategory; +import org.spongepowered.common.config.Config; +import org.spongepowered.common.config.ConfigHandle; import org.spongepowered.common.event.tracking.IPhaseState; import org.spongepowered.common.event.tracking.PhaseContext; -public class TrackerConfig extends ConfigBase { +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class TrackerConfig implements Config { + + public static final String FILE_NAME = "tracker.conf"; /** * Used to determine whether block changes will be "captured" until diff --git a/src/main/java/org/spongepowered/common/config/type/DimensionConfig.java b/src/main/java/org/spongepowered/common/config/type/DimensionConfig.java deleted file mode 100644 index 3f566274d65..00000000000 --- a/src/main/java/org/spongepowered/common/config/type/DimensionConfig.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of Sponge, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.common.config.type; - -public class DimensionConfig extends GeneralConfigBase { - - public DimensionConfig() { - super(); - } -} diff --git a/src/main/java/org/spongepowered/common/data/provider/entity/PaintingData.java b/src/main/java/org/spongepowered/common/data/provider/entity/PaintingData.java index f0b305881f7..17cef4b9fb3 100644 --- a/src/main/java/org/spongepowered/common/data/provider/entity/PaintingData.java +++ b/src/main/java/org/spongepowered/common/data/provider/entity/PaintingData.java @@ -37,6 +37,7 @@ import org.spongepowered.common.accessor.entity.item.HangingEntityAccessor; import org.spongepowered.common.accessor.world.server.ChunkManagerAccessor; import org.spongepowered.common.accessor.world.server.EntityTrackerAccessor; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.common.data.provider.DataProviderRegistrator; import java.util.ArrayList; @@ -79,7 +80,7 @@ public static void register(final DataProviderRegistrator registrator) { for (final ServerPlayerEntity player : players) { SpongeCommon.getServerScheduler().submit(Task.builder() .plugin(SpongeCommon.getPlugin()) - .delayTicks(SpongeCommon.getGlobalConfigAdapter().getConfig().getEntity().getPaintingRespawnDelay()) + .delayTicks(SpongeConfigs.getForWorld(h.world).get().getEntity().getPaintingRespawnDelay()) .execute(() -> { final SSpawnPaintingPacket packet = new SSpawnPaintingPacket(h); player.connection.sendPacket(packet); diff --git a/src/main/java/org/spongepowered/common/entity/EntityUtil.java b/src/main/java/org/spongepowered/common/entity/EntityUtil.java index 943e3e849a9..298e5f02ce6 100644 --- a/src/main/java/org/spongepowered/common/entity/EntityUtil.java +++ b/src/main/java/org/spongepowered/common/entity/EntityUtil.java @@ -517,7 +517,7 @@ private static InvokingTeleporterContext createInvokingTeleporterPhase(final Ent final ServerWorld fromWorld = ((ServerWorld) entity.world); final Map portalAgents = - ((WorldInfoBridge) fromWorld.getWorldInfo()).bridge$getConfigAdapter().getConfig().getWorld().getPortalAgents(); + ((WorldInfoBridge) fromWorld.getWorldInfo()).bridge$getConfigAdapter().get().getWorld().getPortalAgents(); final ResourceKey worldKey; // Check if we're to use a different teleporter for this world diff --git a/src/main/java/org/spongepowered/common/entity/living/human/HumanEntity.java b/src/main/java/org/spongepowered/common/entity/living/human/HumanEntity.java index 3d6dca98aeb..c8263d6be86 100644 --- a/src/main/java/org/spongepowered/common/entity/living/human/HumanEntity.java +++ b/src/main/java/org/spongepowered/common/entity/living/human/HumanEntity.java @@ -69,6 +69,7 @@ import org.spongepowered.common.accessor.entity.player.PlayerEntityAccessor; import org.spongepowered.common.accessor.network.play.server.SPlayerListItemPacketAccessor; import org.spongepowered.common.accessor.network.play.server.SSpawnPlayerPacketAccessor; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.common.util.Constants; import javax.annotation.Nullable; @@ -338,7 +339,7 @@ private boolean updateFakeProfileWithSkin(final UUID skin) { } public void removeFromTabListDelayed(@Nullable final ServerPlayerEntity player, final SPlayerListItemPacket removePacket) { - final int delay = SpongeCommon.getGlobalConfigAdapter().getConfig().getEntity().getHumanPlayerListRemoveDelay(); + final int delay = SpongeConfigs.getForWorld(this.world).get().getEntity().getHumanPlayerListRemoveDelay(); final Runnable removeTask = () -> this.pushPackets(player, removePacket); if (delay == 0) { removeTask.run(); diff --git a/src/main/java/org/spongepowered/common/event/tracking/PhaseContext.java b/src/main/java/org/spongepowered/common/event/tracking/PhaseContext.java index b4f5ff0a408..d0e8daffc37 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/PhaseContext.java +++ b/src/main/java/org/spongepowered/common/event/tracking/PhaseContext.java @@ -38,10 +38,9 @@ import org.spongepowered.api.event.Event; import org.spongepowered.api.event.cause.Cause; import org.spongepowered.api.event.cause.EventContextKeys; -import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.SpongeImplHooks; import org.spongepowered.common.block.SpongeBlockSnapshot; import org.spongepowered.common.bridge.inventory.container.TrackedInventoryBridge; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.common.event.tracking.context.BlockItemDropsSupplier; import org.spongepowered.common.event.tracking.context.BlockItemEntityDropsSupplier; import org.spongepowered.common.event.tracking.context.CaptureBlockPos; @@ -250,7 +249,7 @@ public boolean allowsBulkEntityCaptures() { public P buildAndSwitch() { this.isCompleted = true; - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().generateStackTracePerStateEntry()) { + if (SpongeConfigs.getCommon().get().getPhaseTracker().generateStackTracePerStateEntry()) { this.stackTrace = new Exception("Debug Trace").getStackTrace(); } PhaseTracker.getInstance().switchToPhase(this.state, this); @@ -693,7 +692,7 @@ public boolean isCapturingBlockItemDrops() { } public void printTrace(final PrettyPrinter printer) { - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().generateStackTracePerStateEntry()) { + if (SpongeConfigs.getCommon().get().getPhaseTracker().generateStackTracePerStateEntry()) { printer.add("Entrypoint:") .add(this.stackTrace); } diff --git a/src/main/java/org/spongepowered/common/event/tracking/PhasePrinter.java b/src/main/java/org/spongepowered/common/event/tracking/PhasePrinter.java index 6879345ea2b..1d993826e69 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/PhasePrinter.java +++ b/src/main/java/org/spongepowered/common/event/tracking/PhasePrinter.java @@ -32,12 +32,13 @@ import org.spongepowered.api.entity.Entity; import org.spongepowered.api.util.Tuple; import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.ConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.common.CommonConfig; import org.spongepowered.common.util.PrettyPrinter; import org.spongepowered.common.bridge.world.ServerWorldBridge; import org.spongepowered.common.bridge.world.TrackedWorldBridge; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.category.PhaseTrackerCategory; -import org.spongepowered.common.config.type.GlobalConfig; +import org.spongepowered.common.config.common.PhaseTrackerCategory; import org.spongepowered.common.event.tracking.phase.tick.TickPhase; import org.spongepowered.plugin.PluginContainer; @@ -108,7 +109,7 @@ static void printNullSourceForBlock(final ServerWorld worldServer, final BlockPo static void printUnexpectedBlockChange(final ServerWorldBridge mixinWorld, final BlockPos pos, final net.minecraft.block.BlockState currentState, final net.minecraft.block.BlockState newState) { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose()) { return; } new PrettyPrinter(60).add("Unexpected World Change Detected!").centre().hr() @@ -130,7 +131,7 @@ static void printUnexpectedBlockChange(final ServerWorldBridge mixinWorld, final static void printExceptionSpawningEntity(final PhaseTracker tracker, final PhaseContext context, final Throwable e) { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose() && !PhasePrinter.printedExceptionsForEntities.isEmpty()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose() && !PhasePrinter.printedExceptionsForEntities.isEmpty()) { if (PhasePrinter.printedExceptionsForEntities.contains(context.state)) { return; } @@ -138,7 +139,7 @@ static void printExceptionSpawningEntity(final PhaseTracker tracker, final Phase final PrettyPrinter printer = new PrettyPrinter(60).add("Exception attempting to capture or spawn an Entity!").centre().hr(); PhasePrinter.printPhasestack(tracker, context, e, printer); printer.log(SpongeCommon.getLogger(), Level.ERROR); - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose()) { PhasePrinter.printedExceptionsForEntities.add(context.state); } } @@ -196,7 +197,7 @@ static void printPhaseStackWithException(final PhaseStack stack, final PrettyPri } static void printBlockTrackingException(final PhaseTracker tracker, final PhaseContext phaseData, final IPhaseState phaseState, final Throwable e) { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose() && !PhasePrinter.printedExceptionsForBlocks.isEmpty()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose() && !PhasePrinter.printedExceptionsForBlocks.isEmpty()) { if (PhasePrinter.printedExceptionsForBlocks.contains(phaseState)) { return; } @@ -204,7 +205,7 @@ static void printBlockTrackingException(final PhaseTracker tracker, final PhaseC final PrettyPrinter printer = new PrettyPrinter(60).add("Exception attempting to capture a block change!").centre().hr(); PhasePrinter.printPhasestack(tracker, phaseData, e, printer); printer.trace(System.err, SpongeCommon.getLogger(), Level.ERROR); - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose()) { PhasePrinter.printedExceptionsForBlocks.add(phaseState); } } @@ -243,7 +244,7 @@ public static void printMessageWithCaughtException(final PhaseStack stack, final } static void printExceptionFromPhase(final PhaseStack stack, final Throwable e, final PhaseContext context) { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose() && !PhasePrinter.printedExceptionsForState.isEmpty()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose() && !PhasePrinter.printedExceptionsForState.isEmpty()) { for (final IPhaseState iPhaseState : PhasePrinter.printedExceptionsForState) { if (context.state == iPhaseState) { return; @@ -262,7 +263,7 @@ static void printExceptionFromPhase(final PhaseStack stack, final Throwable e, f PhasePrinter.printPhaseStackWithException(stack, printer, e); printer.trace(System.err, SpongeCommon.getLogger(), Level.ERROR); - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose()) { PhasePrinter.printedExceptionsForState.add(context.state); } } @@ -274,7 +275,7 @@ static void printUnprocessedPhaseContextObjects(final PhaseStack stack, final IP } static void printRunawayPhase(final PhaseStack stack, final IPhaseState state, final PhaseContext context) { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose() && !PhasePrinter.hasPrintedAboutRunnawayPhases) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose() && !PhasePrinter.hasPrintedAboutRunnawayPhases) { // Avoiding spam logs. return; } @@ -286,13 +287,13 @@ static void printRunawayPhase(final PhaseStack stack, final IPhaseState state printer.addWrapped(60, "%s :", "Phases remaining"); PhasePrinter.printPhaseStackWithException(stack, printer, new Exception("RunawayPhase")); printer.trace(System.err, SpongeCommon.getLogger(), Level.ERROR); - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose() && PhasePrinter.printRunawayCount++ > SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().getMaximumRunawayCount()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose() && PhasePrinter.printRunawayCount++ > SpongeConfigs.getCommon().get().getPhaseTracker().getMaximumRunawayCount()) { PhasePrinter.hasPrintedAboutRunnawayPhases = true; } } static void printRunnawayPhaseCompletion(final PhaseStack stack, final IPhaseState state) { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose() && !PhasePrinter.hasPrintedAboutRunnawayPhases) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose() && !PhasePrinter.hasPrintedAboutRunnawayPhases) { // Avoiding spam logs. return; } @@ -306,7 +307,7 @@ static void printRunnawayPhaseCompletion(final PhaseStack stack, final IPhaseSta printer.add(" Phases Remaining:"); PhasePrinter.printPhaseStackWithException(stack, printer, new Exception("RunawayPhase")); printer.trace(System.err, SpongeCommon.getLogger(), Level.ERROR); - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose() && PhasePrinter.printRunawayCount++ > 3) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose() && PhasePrinter.printRunawayCount++ > 3) { PhasePrinter.hasPrintedAboutRunnawayPhases = true; } } @@ -318,7 +319,7 @@ static void generateVersionInfo(final PrettyPrinter printer) { } static void printIncorrectPhaseCompletion(final PhaseStack stack, final IPhaseState prevState, final IPhaseState state) { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose() && !PhasePrinter.completedIncorrectStates.isEmpty()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose() && !PhasePrinter.completedIncorrectStates.isEmpty()) { for (final Tuple, IPhaseState> tuple : PhasePrinter.completedIncorrectStates) { if ((tuple.getFirst().equals(prevState) && tuple.getSecond().equals(state))) { @@ -342,7 +343,7 @@ static void printIncorrectPhaseCompletion(final PhaseStack stack, final IPhaseSt printer.add(" Phases Remaining:"); PhasePrinter.printPhaseStackWithException(stack, printer, new Exception("Incorrect Phase Completion")); printer.trace(System.err, SpongeCommon.getLogger(), Level.ERROR); - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose()) { PhasePrinter.completedIncorrectStates.add(new Tuple<>(prevState, state)); } } @@ -368,7 +369,7 @@ static void printEmptyStackOnCompletion(final PhaseContext context) { printer.add(); PhasePrinter.generateVersionInfo(printer); printer.trace(System.err, SpongeCommon.getLogger(), Level.ERROR); - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose()) { PhasePrinter.hasPrintedEmptyOnce = true; } } @@ -402,14 +403,14 @@ static void printAsyncBlockChange(final TrackedWorldBridge mixinWorld, final Blo static void printAsyncEntitySpawn(final Entity entity) { // We aren't in the server thread at this point, and an entity is spawning on the server.... // We will DEFINITELY be doing bad things otherwise. We need to artificially capture here. - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().captureEntitiesAsync()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().captureEntitiesAsync()) { // Print a pretty warning about not capturing an async spawned entity, but don't care about spawning. - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose()) { return; } // Just checking if we've already printed once about it. // If we have, we don't want to print any more times. - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().verboseErrors() && PhasePrinter.hasPrintedAsyncEntities) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().verboseErrors() && PhasePrinter.hasPrintedAsyncEntities) { return; } // Otherwise, let's print out either the first time, or several more times. @@ -435,12 +436,12 @@ static void printAsyncEntitySpawn(final Entity entity) { PhaseTracker.ASYNC_CAPTURED_ENTITIES.add((net.minecraft.entity.Entity) entity); // At this point we can print an exception about it, if we are told to. // Print a pretty warning about not capturing an async spawned entity, but don't care about spawning. - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose()) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose()) { return; } // Just checking if we've already printed once about it. // If we have, we don't want to print any more times. - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().verboseErrors() && PhasePrinter.hasPrintedAsyncEntities) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().verboseErrors() && PhasePrinter.hasPrintedAsyncEntities) { return; } // Otherwise, let's print out either the first time, or several more times. @@ -463,8 +464,8 @@ static void printAsyncEntitySpawn(final Entity entity) { } static boolean checkMaxBlockProcessingDepth(final IPhaseState state, final PhaseContext context, final int currentDepth) { - final SpongeConfig globalConfigAdapter = SpongeCommon.getGlobalConfigAdapter(); - final PhaseTrackerCategory trackerConfig = globalConfigAdapter.getConfig().getPhaseTracker(); + final ConfigHandle globalConfigAdapter = SpongeConfigs.getCommon(); + final PhaseTrackerCategory trackerConfig = globalConfigAdapter.get().getPhaseTracker(); int maxDepth = trackerConfig.getMaxBlockProcessingDepth(); if (maxDepth == 100 && state == TickPhase.Tick.NEIGHBOR_NOTIFY) { maxDepth = 1000; diff --git a/src/main/java/org/spongepowered/common/event/tracking/PhaseTracker.java b/src/main/java/org/spongepowered/common/event/tracking/PhaseTracker.java index 5b8554974ac..03c3d8c79ec 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/PhaseTracker.java +++ b/src/main/java/org/spongepowered/common/event/tracking/PhaseTracker.java @@ -84,7 +84,8 @@ import org.spongepowered.common.bridge.entity.EntityBridge; import org.spongepowered.common.bridge.world.TrackedWorldBridge; import org.spongepowered.common.bridge.world.chunk.TrackedChunkBridge; -import org.spongepowered.common.config.category.PhaseTrackerCategory; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.common.PhaseTrackerCategory; import org.spongepowered.common.entity.EntityUtil; import org.spongepowered.common.entity.PlayerTracker; import org.spongepowered.common.event.ShouldFire; @@ -164,7 +165,7 @@ public static Block validateBlockForNeighborNotification(final ServerWorld world if (blockIn == null) { // If the block is null, check with the PhaseState to see if it can perform a safe way final PhaseContext currentContext = PhaseTracker.getInstance().getPhaseContext(); - final PhaseTrackerCategory trackerConfig = SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker(); + final PhaseTrackerCategory trackerConfig = SpongeConfigs.getCommon().get().getPhaseTracker(); if (currentContext.state == TickPhase.Tick.TILE_ENTITY) { // Try to save ourselves @@ -392,7 +393,7 @@ void switchToPhase(final IPhaseState state, final PhaseContext phaseContex checkNotNull(state, "State cannot be null!"); checkNotNull(phaseContext, "PhaseContext cannot be null!"); checkArgument(phaseContext.isComplete(), "PhaseContext must be complete!"); - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose()) { + if (SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose()) { if (this.stack.size() > 6) { if (this.stack.checkForRunaways(state, phaseContext)) { PhasePrinter.printRunawayPhase(this.stack, state, phaseContext); @@ -438,7 +439,7 @@ void completePhase(final PhaseContext context) { return; } - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose()) { + if (SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose()) { if (this.stack.checkForRunaways(GeneralPhase.Post.UNWINDING, null)) { // This printing is to detect possibilities of a phase not being cleared properly // and resulting in a "runaway" phase state accumulation. @@ -489,7 +490,7 @@ void completePhase(final PhaseContext context) { } private void checkPhaseContextProcessed(final IPhaseState state, final PhaseContext context) { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().isVerbose() && PhasePrinter.printedExceptionsForUnprocessedState.contains(state)) { + if (!SpongeConfigs.getCommon().get().getPhaseTracker().isVerbose() && PhasePrinter.printedExceptionsForUnprocessedState.contains(state)) { return; } diff --git a/src/main/java/org/spongepowered/common/inject/SpongeCommonModule.java b/src/main/java/org/spongepowered/common/inject/SpongeCommonModule.java index 431c582570f..251025e6d4e 100644 --- a/src/main/java/org/spongepowered/common/inject/SpongeCommonModule.java +++ b/src/main/java/org/spongepowered/common/inject/SpongeCommonModule.java @@ -47,7 +47,7 @@ import org.spongepowered.common.SpongePlatform; import org.spongepowered.common.asset.SpongeAssetManager; import org.spongepowered.common.command.manager.SpongeCommandManager; -import org.spongepowered.common.config.SpongeConfigManager; +import org.spongepowered.common.config.PluginConfigManager; import org.spongepowered.common.data.SpongeDataManager; import org.spongepowered.common.event.SpongeEventManager; import org.spongepowered.common.launch.Launcher; @@ -56,7 +56,7 @@ import org.spongepowered.common.registry.SpongeGameRegistry; import org.spongepowered.common.service.SpongeServiceProvider; import org.spongepowered.common.sql.SpongeSqlManager; -import org.spongepowered.common.util.metric.SpongeMetricsConfigManager; +import org.spongepowered.common.util.SpongeMetricsConfigManager; import javax.annotation.OverridingMethodsMustInvokeSuper; @@ -75,7 +75,7 @@ protected void configure() { this.bindAndExpose(PluginManager.class).toInstance(Launcher.getInstance().getPluginManager()); this.bindAndExpose(GameRegistry.class).to(SpongeGameRegistry.class); this.bindAndExpose(DataManager.class).to(SpongeDataManager.class); - this.bindAndExpose(ConfigManager.class).to(SpongeConfigManager.class); + this.bindAndExpose(ConfigManager.class).to(PluginConfigManager.class); this.bindAndExpose(MetricsConfigManager.class).to(SpongeMetricsConfigManager.class); this.bindAndExpose(SqlManager.class).to(SpongeSqlManager.class); this.bindAndExpose(ServiceProvider.class).to(SpongeServiceProvider.class); diff --git a/src/main/java/org/spongepowered/common/inject/provider/PluginConfigurationModule.java b/src/main/java/org/spongepowered/common/inject/provider/PluginConfigurationModule.java index d290d71076e..bd1e8eb6655 100644 --- a/src/main/java/org/spongepowered/common/inject/provider/PluginConfigurationModule.java +++ b/src/main/java/org/spongepowered/common/inject/provider/PluginConfigurationModule.java @@ -32,7 +32,7 @@ import ninja.leaping.configurate.loader.ConfigurationLoader; import org.spongepowered.api.config.ConfigDir; import org.spongepowered.api.config.DefaultConfig; -import org.spongepowered.common.config.SpongeConfigManager; +import org.spongepowered.common.config.PluginConfigManager; import org.spongepowered.plugin.PluginContainer; import java.io.File; @@ -73,7 +73,7 @@ public static class NonSharedDirAsPath implements Provider { @Override public Path get() { - return SpongeConfigManager.getPrivateRoot(this.container).getDirectory(); + return PluginConfigManager.getPrivateRoot(this.container).getDirectory(); } } @@ -103,7 +103,7 @@ public static class NonSharedPathAsPath implements Provider { @Override public Path get() { - return SpongeConfigManager.getPrivateRoot(this.container).getConfigPath(); + return PluginConfigManager.getPrivateRoot(this.container).getConfigPath(); } } @@ -133,7 +133,7 @@ static class SharedDirAsPath implements Provider { @Override public Path get() { - return SpongeConfigManager.getSharedRoot(this.container).getConfigPath(); + return PluginConfigManager.getSharedRoot(this.container).getConfigPath(); } } @@ -165,7 +165,7 @@ static class SharedCommentedConfigurationNode extends CommentedConfigurationNode @Override public ConfigurationLoader get() { - return SpongeConfigManager.getSharedRoot(this.container).getConfig(); + return PluginConfigManager.getSharedRoot(this.container).getConfig(); } } @@ -174,7 +174,7 @@ static class PrivateCommentedConfigurationNode extends CommentedConfigurationNod @Override public ConfigurationLoader get() { - return SpongeConfigManager.getPrivateRoot(this.container).getConfig(); + return PluginConfigManager.getPrivateRoot(this.container).getConfig(); } } diff --git a/src/main/java/org/spongepowered/common/profile/SpongeGameProfileManager.java b/src/main/java/org/spongepowered/common/profile/SpongeGameProfileManager.java index 864bb3a9647..4f5412534b8 100644 --- a/src/main/java/org/spongepowered/common/profile/SpongeGameProfileManager.java +++ b/src/main/java/org/spongepowered/common/profile/SpongeGameProfileManager.java @@ -34,6 +34,7 @@ import org.spongepowered.api.profile.GameProfileManager; import org.spongepowered.api.profile.property.ProfileProperty; import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.common.profile.query.GameProfileQuery; import org.spongepowered.common.profile.query.NameQuery; import org.spongepowered.common.profile.query.UniqueIdQuery; @@ -51,7 +52,6 @@ public final class SpongeGameProfileManager implements GameProfileManager { - private static final int LOOKUP_INTERVAL = SpongeCommon.getGlobalConfigAdapter().getConfig().getWorld().getGameProfileQueryTaskInterval(); private final Server server; private final GameProfileCache defaultCache; private final ExecutorService gameLookupExecutorService; @@ -79,7 +79,7 @@ public void lookupUserAsync(UUID uuid) { } try { - Thread.sleep(LOOKUP_INTERVAL * 1000); + Thread.sleep(SpongeConfigs.getCommon().get().getWorld().getGameProfileQueryTaskInterval() * 1000); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/src/main/java/org/spongepowered/common/relocate/co/aikar/timings/SpongeTimingsFactory.java b/src/main/java/org/spongepowered/common/relocate/co/aikar/timings/SpongeTimingsFactory.java index 37629be1ae1..4f3eedc7710 100644 --- a/src/main/java/org/spongepowered/common/relocate/co/aikar/timings/SpongeTimingsFactory.java +++ b/src/main/java/org/spongepowered/common/relocate/co/aikar/timings/SpongeTimingsFactory.java @@ -31,7 +31,8 @@ import com.google.common.collect.EvictingQueue; import net.kyori.adventure.audience.Audience; import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.category.TimingsCategory; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.common.TimingsCategory; import org.spongepowered.plugin.PluginContainer; import javax.annotation.Nullable; @@ -52,11 +53,11 @@ public final class SpongeTimingsFactory implements TimingsFactory { private final boolean moduleEnabled; public SpongeTimingsFactory() { - this.moduleEnabled = SpongeCommon.getGlobalConfigAdapter().getConfig().getModules().usePluginTimings(); + this.moduleEnabled = SpongeConfigs.getCommon().get().getModules().usePluginTimings(); } public TimingsFactory init() { - final TimingsCategory category = SpongeCommon.getGlobalConfigAdapter().getConfig().getTimings(); + final TimingsCategory category = SpongeConfigs.getCommon().get().getTimings(); TimingsManager.privacy = category.isServerNamePrivate(); TimingsManager.hiddenConfigs.addAll(category.getHiddenConfigEntries()); this.setVerboseTimingsEnabled(category.isVerbose()); diff --git a/src/main/java/org/spongepowered/common/relocate/co/aikar/timings/TimingsExport.java b/src/main/java/org/spongepowered/common/relocate/co/aikar/timings/TimingsExport.java index 88801d2efe4..197fd12cf2e 100644 --- a/src/main/java/org/spongepowered/common/relocate/co/aikar/timings/TimingsExport.java +++ b/src/main/java/org/spongepowered/common/relocate/co/aikar/timings/TimingsExport.java @@ -44,6 +44,7 @@ import org.spongepowered.api.network.RconConnection; import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.adventure.SpongeAdventure; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.common.relocate.co.aikar.util.JSONUtil; import org.spongepowered.common.relocate.co.aikar.util.JSONUtil.JsonObjectBuilder; @@ -170,14 +171,14 @@ static void reportTimings() { } builder.add("idmap", JSONUtil.objectBuilder() - .add("groups", JSONUtil.mapArrayToObject(TimingIdentifier.GROUP_MAP.values(), (group) -> + .add("groups", JSONUtil.mapArrayToObject(TimingIdentifier.GROUP_MAP.values(), (group) -> JSONUtil.singleObjectPair(group.id, group.name))) .add("handlers", handlersBuilder) - .add("worlds", JSONUtil.mapArrayToObject(TimingHistory.worldMap.entrySet(), (entry) -> + .add("worlds", JSONUtil.mapArrayToObject(TimingHistory.worldMap.entrySet(), (entry) -> JSONUtil.singleObjectPair(entry.getValue(), entry.getKey()))) - .add("tileentity", JSONUtil.mapArrayToObject(tileEntityTypeSet, (tileEntityType) -> + .add("tileentity", JSONUtil.mapArrayToObject(tileEntityTypeSet, (tileEntityType) -> JSONUtil.singleObjectPair(TimingsPls.getTileEntityId(tileEntityType), tileEntityType.getKey().toString()))) - .add("entity", JSONUtil.mapArrayToObject(entityTypeSet, (entityType) -> + .add("entity", JSONUtil.mapArrayToObject(entityTypeSet, (entityType) -> JSONUtil.singleObjectPair(TimingsPls.getEntityId(entityType), entityType.getKey().toString())))); // Information about loaded plugins @@ -194,7 +195,7 @@ static void reportTimings() { // Information on the users Config builder.add("config", JSONUtil.objectBuilder() - .add("sponge", serializeConfigNode(SpongeCommon.getGlobalConfigAdapter().getRootNode()))); + .add("sponge", serializeConfigNode(SpongeConfigs.getCommon().getNode()))); new TimingsExport(listeners, builder.build(), history).start(); } diff --git a/src/main/java/org/spongepowered/common/service/SpongeServiceProvider.java b/src/main/java/org/spongepowered/common/service/SpongeServiceProvider.java index f31f9463ddd..3804c143ccb 100644 --- a/src/main/java/org/spongepowered/common/service/SpongeServiceProvider.java +++ b/src/main/java/org/spongepowered/common/service/SpongeServiceProvider.java @@ -45,7 +45,8 @@ import org.spongepowered.api.service.permission.PermissionService; import org.spongepowered.api.service.whitelist.WhitelistService; import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.category.ServicesCategory; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.common.ServicesCategory; import org.spongepowered.common.event.SpongeEventManager; import org.spongepowered.common.event.lifecycle.ProvideServiceEventImpl; import org.spongepowered.common.launch.Launcher; @@ -172,7 +173,8 @@ public final void init() { throw new IllegalStateException("Services have already been initialised"); } - final ServicesCategory.ServicePluginSubCategory servicePluginSubCategory = SpongeCommon.getGlobalConfigAdapter().getConfig().getServicesCategory().getServicePlugin(); + final ServicesCategory.ServicePluginSubCategory servicePluginSubCategory = + SpongeConfigs.getCommon().get().getServicesCategory().getServicePlugin(); // We loop over all available services and try to discover each one. // This does NOT support third party service interfaces, only impls. diff --git a/src/main/java/org/spongepowered/common/sql/SpongeSqlManager.java b/src/main/java/org/spongepowered/common/sql/SpongeSqlManager.java index e621121d43e..2afe055f8e5 100644 --- a/src/main/java/org/spongepowered/common/sql/SpongeSqlManager.java +++ b/src/main/java/org/spongepowered/common/sql/SpongeSqlManager.java @@ -35,7 +35,7 @@ import com.zaxxer.hikari.HikariDataSource; import org.spongepowered.api.Sponge; import org.spongepowered.api.sql.SqlManager; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.plugin.PluginContainer; import javax.annotation.Nullable; @@ -268,7 +268,7 @@ private static String urlDecode(final String str) { @Override public Optional getConnectionUrlFromAlias(final String alias) { - return Optional.ofNullable(SpongeCommon.getGlobalConfigAdapter().getConfig().getSql().getAliases().get(alias)); + return Optional.ofNullable(SpongeConfigs.getCommon().get().getSql().getAliases().get(alias)); } } diff --git a/src/main/java/org/spongepowered/common/util/SpongeHooks.java b/src/main/java/org/spongepowered/common/util/SpongeHooks.java index fadeeb6cb42..317c5543064 100644 --- a/src/main/java/org/spongepowered/common/util/SpongeHooks.java +++ b/src/main/java/org/spongepowered/common/util/SpongeHooks.java @@ -24,7 +24,6 @@ */ package org.spongepowered.common.util; -import com.google.common.reflect.TypeToken; import it.unimi.dsi.fastutil.objects.Object2LongMap; import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; import net.minecraft.block.Block; @@ -39,25 +38,21 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.dimension.DimensionType; -import ninja.leaping.configurate.commented.CommentedConfigurationNode; import org.apache.logging.log4j.Level; import org.checkerframework.checker.nullness.qual.Nullable; -import org.spongepowered.api.ResourceKey; import org.spongepowered.api.block.BlockSnapshot; import org.spongepowered.api.block.BlockType; import org.spongepowered.api.data.Transaction; import org.spongepowered.api.entity.living.player.User; -import org.spongepowered.api.util.Tristate; import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.category.LoggingCategory; -import org.spongepowered.common.config.type.DimensionConfig; -import org.spongepowered.common.config.type.GeneralConfigBase; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.InheritableConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.inheritable.LoggingCategory; +import org.spongepowered.common.config.inheritable.BaseConfig; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.world.BlockChange; import org.spongepowered.math.vector.Vector3i; @@ -65,12 +60,9 @@ import java.lang.management.ManagementFactory; import java.lang.management.ThreadMXBean; import java.lang.reflect.Method; -import java.nio.file.Path; import java.text.MessageFormat; import java.util.List; -import java.util.Map; import java.util.Objects; -import java.util.concurrent.CompletableFuture; import javax.management.MBeanServer; @@ -90,8 +82,8 @@ public static void logSevere(final String msg, final Object... args) { SpongeCommon.getLogger().fatal(MessageFormat.format(msg, args)); } - public static void logStack(final SpongeConfig config) { - if (config.getConfig().getLogging().logWithStackTraces()) { + public static void logStack(final InheritableConfigHandle config) { + if (config.get().getLogging().logWithStackTraces()) { final Throwable ex = new Throwable(); ex.fillInStackTrace(); SpongeCommon.getLogger().catching(Level.INFO, ex); @@ -103,8 +95,8 @@ public static void logEntityDeath(@Nullable final Entity entity) { return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) entity.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().entityDeathLogging()) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) entity.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().entityDeathLogging()) { logInfo("Dimension: {0} setDead(): {1}", entity.getEntityWorld().getDimension().getType(), entity); logStack(configAdapter); } @@ -115,8 +107,8 @@ public static void logEntityDespawn(@Nullable final Entity entity, final String return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) entity.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().entityDespawnLogging()) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) entity.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().entityDespawnLogging()) { logInfo("Dimension: {0} Despawning ({1}): {2}", entity.getEntityWorld().getDimension().getType(), reason, entity); logStack(configAdapter); } @@ -133,25 +125,25 @@ public static void logEntitySpawn(@Nullable final Entity entity) { final ITextComponent spawnName = entity.getName(); - final SpongeConfig configAdapter = ((WorldInfoBridge) entity.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().entitySpawnLogging()) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) entity.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().entitySpawnLogging()) { logInfo("SPAWNED " + spawnName.getUnformattedComponentText() + " [Dimension: {1}]", entity.getEntityWorld().dimension.getType()); logStack(configAdapter); } } public static void logBlockTrack( - final World world, final Block block, final BlockPos pos, final User user, final boolean allowed) { + final net.minecraft.world.World world, final Block block, final BlockPos pos, final User user, final boolean allowed) { if (world.isRemote()) { return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().blockTrackLogging() && allowed) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().blockTrackLogging() && allowed) { logInfo("Tracking Block " + "[RootCause: {0}][Dimension: {1}][Block: {2}][Pos: {3}]", user.getName(), world.getDimension().getType(), ((BlockType) block).getKey(), pos); logStack(configAdapter); - } else if (configAdapter.getConfig().getLogging().blockTrackLogging() && !allowed) { + } else if (configAdapter.get().getLogging().blockTrackLogging() && !allowed) { logInfo("Blacklisted! Unable to track Block " + "[RootCause: {0}][Dimension: {1}][Block: {2}][Pos: {3}]", user.getName(), world.getDimension().getType(), @@ -160,14 +152,14 @@ public static void logBlockTrack( } } - public static void logBlockAction(final World world, @Nullable final BlockChange type, final Transaction transaction) { + public static void logBlockAction(final net.minecraft.world.World world, @Nullable final BlockChange type, final Transaction transaction) { if (world.isRemote()) { return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); - final LoggingCategory logging = configAdapter.getConfig().getLogging(); + final LoggingCategory logging = configAdapter.get().getLogging(); if (type != null && type.allowsLogging(logging)) { logInfo("Block " + type.name() + " [Dimension: {0}][OriginalState: {1}][NewState: {2}]", world.getDimension().getType(), @@ -177,39 +169,39 @@ public static void logBlockAction(final World world, @Nullable final BlockChange } } - public static void logChunkLoad(final World world, final Vector3i chunkPos) { + public static void logChunkLoad(final net.minecraft.world.World world, final Vector3i chunkPos) { if (world.isRemote()) { return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().chunkLoadLogging()) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().chunkLoadLogging()) { logInfo("Load Chunk in Dimension [{0}] ({1}, {2})", world.getDimension().getType(), chunkPos.getX(), chunkPos.getZ()); logStack(configAdapter); } } - public static void logChunkUnload(final World world, final Vector3i chunkPos) { + public static void logChunkUnload(final net.minecraft.world.World world, final Vector3i chunkPos) { if (world.isRemote()) { return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().chunkUnloadLogging()) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().chunkUnloadLogging()) { logInfo("Unload Chunk in Dimension [{0}] ({1}, {2})", world.getDimension().getType(), chunkPos.getX(), chunkPos.getZ()); logStack(configAdapter); } } - public static void logChunkGCQueueUnload(final World world, final Chunk chunk) { + public static void logChunkGCQueueUnload(final net.minecraft.world.World world, final Chunk chunk) { if (world.isRemote()) { return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().chunkGCQueueUnloadLogging()) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().chunkGCQueueUnloadLogging()) { logInfo("Chunk GC Queued Chunk in Dimension '{0}' ({2}, {3} for unload)", world.getDimension().getType(), chunk.getPos().x, chunk.getPos().z); logStack(configAdapter); @@ -221,8 +213,8 @@ public static void logExploitSignCommandUpdates(final PlayerEntity player, final return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) player.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().logExploitSignCommandUpdates) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) player.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().logExploitSignCommandUpdates) { logInfo("[EXPLOIT] Player '{0}' attempted to exploit sign in dimension '{1}' located at '{2}' with command '{3}'", player.getName(), tileEntity.getWorld().getDimension().getType(), @@ -237,8 +229,8 @@ public static void logExploitItemNameOverflow(final PlayerEntity player, final i return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) player.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().logExploitItemStackNameOverflow) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) player.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().logExploitItemStackNameOverflow) { logInfo("[EXPLOIT] Player '{0}' attempted to send a creative itemstack update with a display name length of '{1}' (Max allowed " + "length is 32767). This has been blocked to avoid server overflow.", player.getName(), @@ -252,8 +244,8 @@ public static void logExploitRespawnInvisibility(final PlayerEntity player) { return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) player.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().logExploitRespawnInvisibility) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) player.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().logExploitRespawnInvisibility) { logInfo("[EXPLOIT] Player '{0}' attempted to perform a respawn invisibility exploit to surrounding players.", player.getName()); logStack(configAdapter); @@ -265,12 +257,12 @@ public static boolean checkBoundingBoxSize(@Nullable final Entity entity, final return false; } - final SpongeConfig configAdapter = ((WorldInfoBridge) entity.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) entity.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); if (!(entity instanceof LivingEntity) || entity instanceof PlayerEntity || entity instanceof EnderDragonPartEntity) { return false; // only check living entities, so long as they are not a player or multipart entity } - final int maxBoundingBoxSize = configAdapter.getConfig().getEntity().getMaxBoundingBoxSize(); + final int maxBoundingBoxSize = configAdapter.get().getEntity().getMaxBoundingBoxSize(); if (maxBoundingBoxSize <= 0) { return false; } @@ -304,12 +296,12 @@ public static boolean checkEntitySpeed(@Nullable final Entity entity, final doub return false; } - final SpongeConfig configAdapter = ((WorldInfoBridge) entity.world.getWorldInfo()).bridge$getConfigAdapter(); - final int maxSpeed = configAdapter.getConfig().getEntity().getMaxSpeed(); + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) entity.world.getWorldInfo()).bridge$getConfigAdapter(); + final int maxSpeed = configAdapter.get().getEntity().getMaxSpeed(); if (maxSpeed > 0) { final double distance = x * x + z * z; if (distance > maxSpeed && !entity.isPassenger()) { - if (configAdapter.getConfig().getLogging().logEntitySpeedRemoval()) { + if (configAdapter.get().getLogging().logEntitySpeedRemoval()) { logInfo("Speed violation: {0} was over {1} - Removing Entity: {2}", distance, maxSpeed, entity); if (entity instanceof LivingEntity) { final LivingEntity livingEntity = (LivingEntity) entity; @@ -319,7 +311,7 @@ public static boolean checkEntitySpeed(@Nullable final Entity entity, final doub livingEntity.moveStrafing, livingEntity.moveForward); } - if (configAdapter.getConfig().getLogging().logWithStackTraces()) { + if (configAdapter.get().getLogging().logWithStackTraces()) { logInfo("Move offset: ({0}, {1}, {2})", x, y, z); logInfo("Motion: ({0}, {1}, {2})", entity.getMotion().x, entity.getMotion().y, entity.getMotion().z); logInfo("Entity: {0}", entity); @@ -346,11 +338,11 @@ public static void logEntitySize(@Nullable final Entity entity, final List list) return; } - final SpongeConfig configAdapter = ((WorldInfoBridge) entity.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); - if (!configAdapter.getConfig().getLogging().logEntityCollisionChecks()) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) entity.getEntityWorld().getWorldInfo()).bridge$getConfigAdapter(); + if (!configAdapter.get().getLogging().logEntityCollisionChecks()) { return; } - final int collisionWarnSize = configAdapter.getConfig().getEntity().getMaxCollisionSize(); + final int collisionWarnSize = configAdapter.get().getEntity().getMaxCollisionSize(); if (collisionWarnSize > 0 && (entity.getServer().getTickCounter() % 10) == 0 && list.size() >= collisionWarnSize) { final SpongeHooks.CollisionWarning warning = new SpongeHooks.CollisionWarning(entity.getEntityWorld().getDimension().getType(), entity); @@ -408,45 +400,11 @@ public static void dumpHeap(final File file, final boolean live) { } public static void enableThreadContentionMonitoring() { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getDebug().isEnableThreadContentionMonitoring()) { + if (!SpongeConfigs.getCommon().get().getDebug().isEnableThreadContentionMonitoring()) { return; } final ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); mbean.setThreadContentionMonitoringEnabled(true); } - public static SpongeConfig getOrLoadConfigAdapter(@Nullable final Path dimensionPath, @Nullable - final ResourceKey worldKey) { - if (worldKey != null) { - final org.spongepowered.api.world.server.ServerWorld apiWorld = SpongeCommon.getGame().getServer().getWorldManager().getWorld(worldKey) - .orElse(null); - if (apiWorld != null) { - return ((WorldInfoBridge) apiWorld.getProperties()).bridge$getConfigAdapter(); - } - } - - if (dimensionPath == null) { - // If no dimension type, go global - return SpongeCommon.getGlobalConfigAdapter(); - } - - // No in-memory config objects, lookup from disk. - final SpongeConfig dimensionConfigAdapter = new SpongeConfig<>(SpongeConfig.Type.DIMENSION, dimensionPath - .resolve("dimension.conf"), SpongeCommon.ECOSYSTEM_ID, SpongeCommon.getGlobalConfigAdapter(), false); - - if (worldKey != null) { - // TODO Minecraft 1.14 - Should drill it down by namespace zml.. - return new SpongeConfig<>(SpongeConfig.Type.WORLD, dimensionPath.resolve(worldKey.getValue()).resolve("world.conf"), - SpongeCommon.ECOSYSTEM_ID, dimensionConfigAdapter, false); - } - - return dimensionConfigAdapter; - } - - public static CompletableFuture savePluginsInMetricsConfig(final Map entries) { - return SpongeCommon.getGlobalConfigAdapter() - .updateSetting("metrics.plugin-states", entries, new TypeToken>() { - private static final long serialVersionUID = 190617916448550012L; - }); - } } diff --git a/src/main/java/org/spongepowered/common/util/metric/SpongeMetricsConfigManager.java b/src/main/java/org/spongepowered/common/util/SpongeMetricsConfigManager.java similarity index 63% rename from src/main/java/org/spongepowered/common/util/metric/SpongeMetricsConfigManager.java rename to src/main/java/org/spongepowered/common/util/SpongeMetricsConfigManager.java index 86beb8d75f1..b735ffcd77b 100644 --- a/src/main/java/org/spongepowered/common/util/metric/SpongeMetricsConfigManager.java +++ b/src/main/java/org/spongepowered/common/util/SpongeMetricsConfigManager.java @@ -22,28 +22,39 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.util.metric; +package org.spongepowered.common.util; import com.google.inject.Singleton; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; import org.spongepowered.api.util.Tristate; import org.spongepowered.api.util.metric.MetricsConfigManager; -import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.category.MetricsCategory; +import org.spongepowered.common.config.ConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.metrics.MetricsConfiguration; import org.spongepowered.plugin.PluginContainer; -@SuppressWarnings("deprecation") +import java.io.IOException; + @Singleton public class SpongeMetricsConfigManager implements MetricsConfigManager { + private final ConfigHandle metrics; + + public SpongeMetricsConfigManager() throws IOException, ObjectMappingException { + // This needs to be loaded after the global-inheritable configuration + // is loaded. That load is performed by the sponge non-inheritable + // configuration which is loaded way earlier in the lifecycle since it + // is used to configure mixin plugins. + metrics = SpongeConfigs.create(new MetricsConfiguration(), MetricsConfiguration.FILE_NAME); + } + @Override public Tristate getGlobalCollectionState() { - final MetricsCategory metricsCategory = SpongeCommon.getGlobalConfigAdapter().getConfig().getMetricsCategory(); - return metricsCategory.getGlobalCollectionState(); + return this.metrics.get().getGlobalCollectionState(); } @Override public Tristate getCollectionState(final PluginContainer container) { - final MetricsCategory metricsCategory = SpongeCommon.getGlobalConfigAdapter().getConfig().getMetricsCategory(); - return metricsCategory.getCollectionState(container); + return this.metrics.get().getGlobalCollectionState(); } } diff --git a/src/main/java/org/spongepowered/common/world/BlockChange.java b/src/main/java/org/spongepowered/common/world/BlockChange.java index 573655dc677..a4a0bd16b5a 100644 --- a/src/main/java/org/spongepowered/common/world/BlockChange.java +++ b/src/main/java/org/spongepowered/common/world/BlockChange.java @@ -33,7 +33,7 @@ import org.spongepowered.api.event.cause.Cause; import org.spongepowered.api.event.cause.EventContextKey; import org.spongepowered.api.event.cause.EventContextKeys; -import org.spongepowered.common.config.category.LoggingCategory; +import org.spongepowered.common.config.inheritable.LoggingCategory; public enum BlockChange { diff --git a/src/main/java/org/spongepowered/common/world/SpongeWorldArchetypeBuilder.java b/src/main/java/org/spongepowered/common/world/SpongeWorldArchetypeBuilder.java index 19cd1a0d6b4..b4e6890c28e 100644 --- a/src/main/java/org/spongepowered/common/world/SpongeWorldArchetypeBuilder.java +++ b/src/main/java/org/spongepowered/common/world/SpongeWorldArchetypeBuilder.java @@ -46,7 +46,6 @@ import org.spongepowered.api.world.teleport.PortalAgentTypes; import org.spongepowered.common.bridge.ResourceKeyBridge; import org.spongepowered.common.bridge.world.WorldSettingsBridge; -import org.spongepowered.common.bridge.world.dimension.DimensionTypeBridge; import org.spongepowered.common.world.dimension.SpongeDimensionType; import javax.annotation.Nullable; @@ -266,7 +265,7 @@ public SpongeWorldArchetypeBuilder reset() { this.enabled = true; this.loadOnStartup = true; this.keepSpawnLoaded = null; - this.generateSpawnOnLoad = this.dimensionType.getConfigAdapter().getConfig().getWorld().getGenerateSpawnOnLoad(); + this.generateSpawnOnLoad = true; this.generatorSettings = DataContainer.createNew(); this.pvpEnabled = true; this.commandsEnabled = true; diff --git a/src/main/java/org/spongepowered/common/world/dimension/SpongeDimensionType.java b/src/main/java/org/spongepowered/common/world/dimension/SpongeDimensionType.java index a1f09454c70..40e0a716863 100644 --- a/src/main/java/org/spongepowered/common/world/dimension/SpongeDimensionType.java +++ b/src/main/java/org/spongepowered/common/world/dimension/SpongeDimensionType.java @@ -31,19 +31,13 @@ import org.spongepowered.api.service.context.Context; import org.spongepowered.api.world.dimension.DimensionType; import org.spongepowered.common.SpongeCatalogType; -import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.type.DimensionConfig; -import java.nio.file.Path; import java.util.function.BiFunction; import java.util.function.BooleanSupplier; import java.util.function.Supplier; public final class SpongeDimensionType extends SpongeCatalogType implements DimensionType { - private final Path configPath; - private final SpongeConfig config; private final Context context; private final Supplier> dimensionFactory; private final BooleanSupplier hasSkyLight; @@ -53,9 +47,6 @@ public SpongeDimensionType(final ResourceKey key, final Supplier(SpongeConfig.Type.DIMENSION, this.configPath.resolve("dimension.conf"), - SpongeCommon.ECOSYSTEM_ID, SpongeCommon.getGlobalConfigAdapter(), false); this.context = new Context(Context.DIMENSION_KEY, key.getNamespace() + "." + key.getValue()); this.dimensionFactory = dimensionFactory; this.hasSkyLight = hasSkyLight; @@ -71,14 +62,6 @@ public Context getContext() { return this.context; } - public Path getConfigPath() { - return this.configPath; - } - - public SpongeConfig getConfigAdapter() { - return this.config; - } - public BiFunction getDimensionFactory() { return this.dimensionFactory.get(); } diff --git a/src/main/java/org/spongepowered/common/world/teleport/ConfigTeleportHelperFilter.java b/src/main/java/org/spongepowered/common/world/teleport/ConfigTeleportHelperFilter.java index 9c87b8a3bf0..7fd952edf5e 100644 --- a/src/main/java/org/spongepowered/common/world/teleport/ConfigTeleportHelperFilter.java +++ b/src/main/java/org/spongepowered/common/world/teleport/ConfigTeleportHelperFilter.java @@ -29,8 +29,8 @@ import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockType; import org.spongepowered.api.world.teleport.TeleportHelperFilter; -import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.category.TeleportHelperCategory; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.common.TeleportHelperCategory; import java.util.List; import java.util.Locale; @@ -57,7 +57,7 @@ public static void invalidateCache() { private static void updateCacheIfNecessary() { if (floorBlockTypes == null) { - TeleportHelperCategory teleportHelperCat = SpongeCommon.getGlobalConfigAdapter().getConfig().getTeleportHelper(); + TeleportHelperCategory teleportHelperCat = SpongeConfigs.getCommon().get().getTeleportHelper(); floorBlockTypes = teleportHelperCat.getUnsafeFloorBlockIds().stream() .map(x -> ResourceKey.resolve(x.toLowerCase(Locale.ENGLISH))) .map(x -> Sponge.getRegistry().getCatalogRegistry().get(BlockType.class, x).orElse(null)) diff --git a/src/main/java/org/spongepowered/common/world/teleport/SpongeTeleportHelper.java b/src/main/java/org/spongepowered/common/world/teleport/SpongeTeleportHelper.java index a19d227aa9f..838bc3bf3c5 100644 --- a/src/main/java/org/spongepowered/common/world/teleport/SpongeTeleportHelper.java +++ b/src/main/java/org/spongepowered/common/world/teleport/SpongeTeleportHelper.java @@ -35,8 +35,8 @@ import org.spongepowered.api.world.server.ServerWorld; import org.spongepowered.api.world.teleport.TeleportHelperFilter; import org.spongepowered.api.world.teleport.TeleportHelperFilters; -import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.bridge.world.chunk.ServerChunkProviderBridge; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.math.GenericMath; import org.spongepowered.math.vector.Vector3i; @@ -60,7 +60,7 @@ public Optional getSafeLocation(ServerLocation location, int hei final Set filters = Sets.newHashSet(additionalFilters); filters.add(filter); - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getTeleportHelper().isForceBlacklistOn()) { + if (SpongeConfigs.getCommon().get().getTeleportHelper().isForceBlacklistOn()) { // Always force this into the set if the user has requested it. filters.add(TeleportHelperFilters.CONFIG.get()); } diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/mcp/world/storage/WorldInfoMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/mcp/world/storage/WorldInfoMixin_API.java index 34b5004fcc3..89e162db662 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/mcp/world/storage/WorldInfoMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/mcp/world/storage/WorldInfoMixin_API.java @@ -62,14 +62,12 @@ import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; import org.spongepowered.common.data.persistence.NbtTranslator; import org.spongepowered.common.util.Constants; -import org.spongepowered.common.util.MissingImplementationException; import org.spongepowered.common.util.VecHelper; import org.spongepowered.math.vector.Vector3i; import java.io.IOException; import java.time.Duration; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -121,7 +119,7 @@ public abstract class WorldInfoMixin_API implements WorldProperties { @Shadow public abstract void shadow$setThunderTime(int time); @Shadow public abstract void shadow$setClearWeatherTime(int time); @Shadow public abstract int shadow$getClearWeatherTime(); - + @Override public ResourceKey getKey() { return ((ResourceKeyBridge) this).bridge$getKey(); diff --git a/src/mixins/java/org/spongepowered/common/mixin/bungee/network/handshake/ServerHandshakeNetHandlerMixin_Bungee.java b/src/mixins/java/org/spongepowered/common/mixin/bungee/network/handshake/ServerHandshakeNetHandlerMixin_Bungee.java index 00c5a804095..e8a36e19afb 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/bungee/network/handshake/ServerHandshakeNetHandlerMixin_Bungee.java +++ b/src/mixins/java/org/spongepowered/common/mixin/bungee/network/handshake/ServerHandshakeNetHandlerMixin_Bungee.java @@ -38,10 +38,10 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.bridge.network.NetworkManagerBridge_Bungee; import org.spongepowered.common.accessor.network.NetworkManagerAccessor; import org.spongepowered.common.accessor.network.handshake.client.CHandshakePacketAccessor; +import org.spongepowered.common.config.SpongeConfigs; import java.net.InetSocketAddress; @@ -54,7 +54,7 @@ public abstract class ServerHandshakeNetHandlerMixin_Bungee { @Inject(method = "processHandshake", at = @At(value = "HEAD"), cancellable = true) private void bungee$patchHandshake(CHandshakePacket packet, CallbackInfo ci) { - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getBungeeCord().getIpForwarding() && packet.getRequestedState().equals(ProtocolType.LOGIN)) { + if (SpongeConfigs.getCommon().get().getBungeeCord().getIpForwarding() && packet.getRequestedState().equals(ProtocolType.LOGIN)) { final String ip = ((CHandshakePacketAccessor) packet).accessor$getIp(); final String[] split = ip.split("\00\\|", 2)[0].split("\00"); // ignore any extra data diff --git a/src/mixins/java/org/spongepowered/common/mixin/bungee/network/handshake/client/CHandshakeMixin_Bungee.java b/src/mixins/java/org/spongepowered/common/mixin/bungee/network/handshake/client/CHandshakeMixin_Bungee.java index eb4d1f78733..dc9f28dc496 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/bungee/network/handshake/client/CHandshakeMixin_Bungee.java +++ b/src/mixins/java/org/spongepowered/common/mixin/bungee/network/handshake/client/CHandshakeMixin_Bungee.java @@ -29,7 +29,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; @Mixin(CHandshakePacket.class) public abstract class CHandshakeMixin_Bungee { @@ -37,8 +37,8 @@ public abstract class CHandshakeMixin_Bungee { @Redirect(method = "readPacketData", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketBuffer;readString(I)Ljava/lang/String;")) private String bungee$patchReadStringForPortForwarding(final PacketBuffer buf, final int value) { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getModules().usePluginBungeeCord() - || !SpongeCommon.getGlobalConfigAdapter().getConfig().getBungeeCord().getIpForwarding()) { + if (!SpongeConfigs.getCommon().get().getModules().usePluginBungeeCord() + || !SpongeConfigs.getCommon().get().getBungeeCord().getIpForwarding()) { return buf.readString(255); } return buf.readString(Short.MAX_VALUE); diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/block/BlockMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/block/BlockMixin.java index 4c59ce5f1e8..c018e1e1bf4 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/block/BlockMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/block/BlockMixin.java @@ -38,7 +38,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.registry.Registry; -import org.spongepowered.api.ResourceKey; import org.spongepowered.api.entity.EntityTypes; import org.spongepowered.api.event.CauseStackManager; import org.spongepowered.api.event.SpongeEventFactory; @@ -52,15 +51,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.bridge.ResourceKeyBridge; import org.spongepowered.common.bridge.TimingBridge; import org.spongepowered.common.bridge.TrackableBridge; import org.spongepowered.common.bridge.block.BlockBridge; import org.spongepowered.common.bridge.block.DyeColorBlockBridge; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.category.BlockTrackerCategory; -import org.spongepowered.common.config.category.BlockTrackerModCategory; -import org.spongepowered.common.config.type.TrackerConfig; +import org.spongepowered.common.config.ConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.tracker.BlockTrackerCategory; +import org.spongepowered.common.config.tracker.BlockTrackerModCategory; +import org.spongepowered.common.config.tracker.TrackerConfig; import org.spongepowered.common.event.ShouldFire; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.common.launch.Launcher; @@ -193,8 +192,8 @@ public abstract class BlockMixin implements BlockBridge, TrackableBridge, Timing @SuppressWarnings("ConstantConditions") @Override public void bridge$initializeTrackerState() { - final SpongeConfig trackerConfigAdapter = SpongeCommon.getTrackerConfigAdapter(); - final BlockTrackerCategory blockTrackerCat = trackerConfigAdapter.getConfig().getBlockTracker(); + final ConfigHandle trackerConfigAdapter = SpongeConfigs.getTracker(); + final BlockTrackerCategory blockTrackerCat = trackerConfigAdapter.get().getBlockTracker(); final ResourceLocation key = Registry.BLOCK.getKey((Block) (Object) this); final String modId = key.getNamespace(); final String name = key.getPath(); diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/block/LeavesBlockMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/block/LeavesBlockMixin.java index 1c523970c8d..514de2ed520 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/block/LeavesBlockMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/block/LeavesBlockMixin.java @@ -30,14 +30,15 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; @Mixin(LeavesBlock.class) public abstract class LeavesBlockMixin extends BlockMixin { + // TODO( @Inject(method = "ticksRandomly", at = @At("HEAD"), cancellable = true) private void impl$checkConfigForLeafTicking(BlockState state, CallbackInfoReturnable cir) { - if (!SpongeCommon.getGlobalConfigAdapter().getConfig().getWorld().getLeafDecay()) { + if (!SpongeConfigs.getCommon().get().getWorld().getLeafDecay()) { cir.setReturnValue(false); } } diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/entity/MobEntityMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/entity/MobEntityMixin.java index 168663d82ee..aca71273888 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/entity/MobEntityMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/entity/MobEntityMixin.java @@ -37,7 +37,6 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import org.objectweb.asm.Opcodes; -import org.spongepowered.api.Sponge; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.ai.goal.GoalExecutorTypes; import org.spongepowered.api.entity.living.Agent; @@ -266,7 +265,7 @@ public boolean attackEntityAsMob(net.minecraft.entity.Entity targetEntity) { @ModifyConstant(method = "checkDespawn", constant = @Constant(doubleValue = 16384.0D)) private double getHardDespawnRange(final double value) { if (!this.world.isRemote) { - return Math.pow(((WorldInfoBridge) this.world.getWorldInfo()).bridge$getConfigAdapter().getConfig().getEntity().getHardDespawnRange(), 2); + return Math.pow(((WorldInfoBridge) this.world.getWorldInfo()).bridge$getConfigAdapter().get().getEntity().getHardDespawnRange(), 2); } return value; } @@ -275,7 +274,7 @@ private double getHardDespawnRange(final double value) { @ModifyConstant(method = "checkDespawn", constant = @Constant(doubleValue = 1024.0D), expect = 2) private double getSoftDespawnRange(final double value) { if (!this.world.isRemote) { - return Math.pow(((WorldInfoBridge) this.world.getWorldInfo()).bridge$getConfigAdapter().getConfig().getEntity().getSoftDespawnRange(), 2); + return Math.pow(((WorldInfoBridge) this.world.getWorldInfo()).bridge$getConfigAdapter().get().getEntity().getSoftDespawnRange(), 2); } return value; } @@ -283,7 +282,7 @@ private double getSoftDespawnRange(final double value) { @ModifyConstant(method = "checkDespawn", constant = @Constant(intValue = 600)) private int getMinimumLifetime(final int value) { if (!this.world.isRemote) { - return ((WorldInfoBridge) this.world.getWorldInfo()).bridge$getConfigAdapter().getConfig().getEntity().getMinimumLife() * 20; + return ((WorldInfoBridge) this.world.getWorldInfo()).bridge$getConfigAdapter().get().getEntity().getMinimumLife() * 20; } return value; } diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/entity/item/ItemEntityMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/entity/item/ItemEntityMixin.java index fcbd7e41388..5345c5e3084 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/entity/item/ItemEntityMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/entity/item/ItemEntityMixin.java @@ -79,7 +79,7 @@ public abstract class ItemEntityMixin extends EntityMixin implements ItemEntityB return originalRadius; } if (this.impl$cachedRadius == -1) { - final double configRadius = ((WorldInfoBridge) this.world.getWorldInfo()).bridge$getConfigAdapter().getConfig().getWorld().getItemMergeRadius(); + final double configRadius = ((WorldInfoBridge) this.world.getWorldInfo()).bridge$getConfigAdapter().get().getWorld().getItemMergeRadius(); this.impl$cachedRadius = configRadius < 0 ? 0 : configRadius; } return this.impl$cachedRadius; @@ -186,7 +186,7 @@ public abstract class ItemEntityMixin extends EntityMixin implements ItemEntityB ) private void impl$fireExpireEntityEventTargetItem(final CallbackInfo ci) { if (!PhaseTracker.SERVER.onSidedThread() || this.shadow$getItem().isEmpty()) { - // In the rare case the first if block is actually at the end of the method instruction list, we don't want to + // In the rare case the first if block is actually at the end of the method instruction list, we don't want to // erroneously be calling this twice. return; } diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/tileentity/TileEntityTypeMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/tileentity/TileEntityTypeMixin.java index f8cef7fd595..9448c7f0b2e 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/tileentity/TileEntityTypeMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/tileentity/TileEntityTypeMixin.java @@ -34,10 +34,11 @@ import org.spongepowered.common.bridge.ResourceKeyBridge; import org.spongepowered.common.bridge.TrackableBridge; import org.spongepowered.common.bridge.tileentity.TileEntityTypeBridge; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.category.BlockEntityTrackerCategory; -import org.spongepowered.common.config.category.BlockEntityTrackerModCategory; -import org.spongepowered.common.config.type.TrackerConfig; +import org.spongepowered.common.config.ConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.tracker.BlockEntityTrackerCategory; +import org.spongepowered.common.config.tracker.BlockEntityTrackerModCategory; +import org.spongepowered.common.config.tracker.TrackerConfig; import org.spongepowered.plugin.PluginContainer; @Mixin(TileEntityType.class) @@ -66,8 +67,8 @@ public abstract class TileEntityTypeMixin implements ResourceKeyBridge, Trackabl final TrackableBridge trackableBridge = (TrackableBridge) tileEntityType; - final SpongeConfig trackerConfigAdapter = SpongeCommon.getTrackerConfigAdapter(); - final BlockEntityTrackerCategory blockEntityTracker = trackerConfigAdapter.getConfig().getBlockEntityTracker(); + final ConfigHandle trackerConfigAdapter = SpongeConfigs.getTracker(); + final BlockEntityTrackerCategory blockEntityTracker = trackerConfigAdapter.get().getBlockEntityTracker(); BlockEntityTrackerModCategory modCapturing = blockEntityTracker.getModMappings().get(plugin.getMetadata().getId()); diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/world/storage/WorldInfoMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/world/storage/WorldInfoMixin.java index 0eed4774503..a344d2e4018 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/world/storage/WorldInfoMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/world/storage/WorldInfoMixin.java @@ -33,7 +33,6 @@ import net.minecraft.network.play.server.SServerDifficultyPacket; import net.minecraft.world.Difficulty; import net.minecraft.world.GameType; -import net.minecraft.world.World; import net.minecraft.world.WorldSettings; import net.minecraft.world.WorldType; import net.minecraft.world.dimension.DimensionType; @@ -60,15 +59,16 @@ import org.spongepowered.common.bridge.world.WorldBridge; import org.spongepowered.common.bridge.world.dimension.DimensionTypeBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.category.WorldCategory; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.InheritableConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.util.Constants; import org.spongepowered.common.world.dimension.SpongeDimensionType; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -92,12 +92,7 @@ public abstract class WorldInfoMixin implements ResourceKeyBridge, WorldInfoBrid private UUID impl$uniqueId; private SpongeDimensionType impl$logicType; - private SpongeConfig impl$configAdapter; - private boolean impl$enabled; - private boolean impl$pvp; - private boolean impl$loadOnStartup = true; - private boolean impl$keepSpawnLoaded; - private boolean impl$generateSpawnOnLoad; + private InheritableConfigHandle impl$configAdapter; private boolean impl$generateBonusChest; private boolean impl$modCreated; @Nullable private PortalAgentType impl$portalAgentType; @@ -124,27 +119,6 @@ public abstract class WorldInfoMixin implements ResourceKeyBridge, WorldInfoBrid this.impl$key = key; } - @Override - public boolean bridge$createWorldConfig() { - if (this.impl$configAdapter != null) { - return false; - } - - if (this.bridge$isValid()) { - this.impl$configAdapter = - new SpongeConfig<>(SpongeConfig.Type.WORLD, ((DimensionTypeBridge) this.impl$dimensionType).bridge$getSpongeDimensionType().getConfigPath() - .resolve(this.levelName) - .resolve("world.conf"), - SpongeCommon.ECOSYSTEM_ID, - ((DimensionTypeBridge) this.impl$dimensionType).bridge$getSpongeDimensionType().getConfigAdapter(), - false); - } else { - this.impl$configAdapter = SpongeConfig.newDummyConfig(SpongeConfig.Type.WORLD); - } - - return true; - } - @Override public boolean bridge$isValid() { final String levelName = this.shadow$getWorldName(); @@ -210,7 +184,7 @@ public abstract class WorldInfoMixin implements ResourceKeyBridge, WorldInfoBrid public void bridge$updatePlayersForDifficulty() { ServerWorld serverWorld = null; for (final org.spongepowered.api.world.server.ServerWorld world : Sponge.getServer().getWorldManager().getWorlds()) { - final World mcWorld = (World) world; + final net.minecraft.world.World mcWorld = (net.minecraft.world.World) world; if (!((WorldBridge) mcWorld).bridge$isFake() && mcWorld.getWorldInfo() == (Object) this) { serverWorld = (ServerWorld) world; break; @@ -228,22 +202,22 @@ public abstract class WorldInfoMixin implements ResourceKeyBridge, WorldInfoBrid @Override public boolean bridge$isEnabled() { - return this.impl$enabled; + return this.bridge$getConfigAdapter().get().getWorld().isWorldEnabled(); } @Override public void bridge$setEnabled(boolean state) { - this.impl$enabled = state; + this.bridge$getConfigAdapter().get().getWorld().setWorldEnabled(state); } @Override public boolean bridge$isPVPEnabled() { - return this.impl$pvp; + return this.bridge$getConfigAdapter().get().getWorld().getPVPEnabled(); } @Override public void bridge$setPVPEnabled(boolean state) { - this.impl$pvp = state; + this.bridge$getConfigAdapter().get().getWorld().setPVPEnabled(state); } @Override @@ -258,32 +232,32 @@ public abstract class WorldInfoMixin implements ResourceKeyBridge, WorldInfoBrid @Override public boolean bridge$doesLoadOnStartup() { - return this.impl$loadOnStartup; + return this.bridge$getConfigAdapter().get().getWorld().getLoadOnStartup(); } @Override public void bridge$setLoadOnStartup(boolean state) { - this.impl$loadOnStartup = state; + this.bridge$getConfigAdapter().get().getWorld().setLoadOnStartup(state); } @Override public boolean bridge$doesKeepSpawnLoaded() { - return this.impl$keepSpawnLoaded; + return this.bridge$getConfigAdapter().get().getWorld().getKeepSpawnLoaded(); } @Override public void bridge$setKeepSpawnLoaded(boolean state) { - this.impl$keepSpawnLoaded = state; + this.bridge$getConfigAdapter().get().getWorld().setKeepSpawnLoaded(state); } @Override public boolean bridge$doesGenerateSpawnOnLoad() { - return this.impl$generateSpawnOnLoad; + return this.bridge$getConfigAdapter().get().getWorld().getGenerateSpawnOnLoad(); } @Override public void bridge$setGenerateSpawnOnLoad(boolean state) { - this.impl$generateSpawnOnLoad = state; + this.bridge$getConfigAdapter().get().getWorld().setGenerateSpawnOnLoad(state); } @Override @@ -315,13 +289,22 @@ public abstract class WorldInfoMixin implements ResourceKeyBridge, WorldInfoBrid } @Override - public SpongeConfig bridge$getConfigAdapter() { + public InheritableConfigHandle bridge$getConfigAdapter() { if (this.impl$configAdapter == null) { - this.bridge$createWorldConfig(); + if (this.bridge$isValid()) { + return SpongeConfigs.createWorld(this.bridge$getLogicType(), this.bridge$getKey()); + } else { + return SpongeConfigs.createDetached(); + } } return this.impl$configAdapter; } + @Override + public void bridge$setConfigAdapter(InheritableConfigHandle adapter) { + this.impl$configAdapter = Objects.requireNonNull(adapter, "adapter"); + } + @Override public DimensionType bridge$getDimensionType() { return this.impl$dimensionType; @@ -346,14 +329,9 @@ public abstract class WorldInfoMixin implements ResourceKeyBridge, WorldInfoBrid @Override public void bridge$saveConfig() { - final WorldCategory worldCat = this.impl$configAdapter.getConfig().getWorld(); - // TODO 1.14 - Set the properties on the config adapter - worldCat.setWorldEnabled(this.impl$enabled); - worldCat.setLoadOnStartup(this.impl$loadOnStartup); - worldCat.setGenerateSpawnOnLoad(this.impl$generateSpawnOnLoad); - worldCat.setKeepSpawnLoaded(this.impl$keepSpawnLoaded); - worldCat.setPVPEnabled(this.impl$pvp); - this.impl$configAdapter.save(); + if (this.impl$configAdapter != null) { + this.impl$configAdapter.save(); + } } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/entitycollision/block/BlockMixin_EntityCollision.java b/src/mixins/java/org/spongepowered/common/mixin/entitycollision/block/BlockMixin_EntityCollision.java index 324eacc2204..cffa2d13867 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/entitycollision/block/BlockMixin_EntityCollision.java +++ b/src/mixins/java/org/spongepowered/common/mixin/entitycollision/block/BlockMixin_EntityCollision.java @@ -25,17 +25,17 @@ package org.spongepowered.common.mixin.entitycollision.block; import net.minecraft.block.Block; -import net.minecraft.world.World; import org.spongepowered.api.ResourceKey; import org.spongepowered.api.block.BlockType; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.category.CollisionModCategory; -import org.spongepowered.common.config.category.EntityCollisionCategory; -import org.spongepowered.common.config.type.GlobalConfig; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.ConfigHandle; +import org.spongepowered.common.config.InheritableConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.common.CommonConfig; +import org.spongepowered.common.config.inheritable.CollisionModCategory; +import org.spongepowered.common.config.inheritable.EntityCollisionCategory; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.bridge.entitycollision.CollisionCapabilityBridge; @Mixin(Block.class) @@ -70,28 +70,26 @@ public abstract class BlockMixin_EntityCollision implements CollisionCapabilityB } @Override - public void collision$initializeCollisionState(World world) { - final SpongeConfig worldConfigAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); - final SpongeConfig globalConfigAdapter = SpongeCommon.getGlobalConfigAdapter(); - final EntityCollisionCategory worldCollCat = worldConfigAdapter.getConfig().getEntityCollisionCategory(); - final EntityCollisionCategory globalCollCat = globalConfigAdapter.getConfig().getEntityCollisionCategory(); + public void collision$initializeCollisionState(net.minecraft.world.World world) { + final InheritableConfigHandle worldConfigAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); + final ConfigHandle globalConfigAdapter = SpongeConfigs.getCommon(); + final EntityCollisionCategory worldCollCat = worldConfigAdapter.get().getEntityCollisionCategory(); this.collision$setMaxCollisions(worldCollCat.getMaxEntitiesWithinAABB()); - + boolean requiresSave = false; String[] ids = ((BlockType) this).getKey().toString().split(":"); String modId = ids[0]; String name = ids[1]; - CollisionModCategory worldCollMod = worldCollCat.getModList().get(modId); - CollisionModCategory globalCollMod = globalCollCat.getModList().get(modId); - if (worldCollMod == null && worldCollCat.autoPopulateData()) { - globalCollMod = new CollisionModCategory(modId); - globalCollCat.getModList().put(modId, globalCollMod); - globalCollMod.getBlockList().put(name, this.collision$getMaxCollisions()); - globalConfigAdapter.save(); - return; - } else if (worldCollMod != null) { + final CollisionModCategory worldCollMod = worldConfigAdapter.getOrCreateValue(s -> s.getEntityCollisionCategory().getModList().get(modId), + c -> { + // TODO: finish after populating? + final CollisionModCategory globalCollision = new CollisionModCategory(modId); + c.getEntityCollisionCategory().getModList().put(modId, globalCollision); + globalCollision.getBlockList().put(name, this.collision$getMaxCollisions()); + }, worldCollCat.autoPopulateData()); + if (worldCollMod != null) { if (!worldCollMod.isEnabled()) { this.collision$setMaxCollisions(-1); return; @@ -105,7 +103,7 @@ public abstract class BlockMixin_EntityCollision implements CollisionCapabilityB // entity overrides Integer blockMaxCollision = worldCollMod.getBlockList().get(name); if (blockMaxCollision == null && worldCollCat.autoPopulateData()) { - globalCollMod.getBlockList().put(name, this.collision$getMaxCollisions()); + worldCollMod.getBlockList().put(name, this.collision$getMaxCollisions()); requiresSave = true; } else if (blockMaxCollision != null) { this.collision$setMaxCollisions(blockMaxCollision); diff --git a/src/mixins/java/org/spongepowered/common/mixin/entitycollision/entity/EntityMixin_EntityCollision.java b/src/mixins/java/org/spongepowered/common/mixin/entitycollision/entity/EntityMixin_EntityCollision.java index 837afbfe74d..c3fdab49295 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/entitycollision/entity/EntityMixin_EntityCollision.java +++ b/src/mixins/java/org/spongepowered/common/mixin/entitycollision/entity/EntityMixin_EntityCollision.java @@ -26,7 +26,6 @@ import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.ItemStack; -import net.minecraft.world.World; import org.spongepowered.api.ResourceKey; import org.spongepowered.api.entity.Entity; import org.spongepowered.asm.mixin.Mixin; @@ -34,27 +33,28 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.bridge.world.WorldBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.category.CollisionModCategory; -import org.spongepowered.common.config.category.EntityCollisionCategory; -import org.spongepowered.common.config.type.GlobalConfig; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.ConfigHandle; +import org.spongepowered.common.config.InheritableConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.common.CommonConfig; +import org.spongepowered.common.config.inheritable.CollisionModCategory; +import org.spongepowered.common.config.inheritable.EntityCollisionCategory; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.bridge.entitycollision.CollisionCapabilityBridge; @Mixin(value = net.minecraft.entity.Entity.class, priority = 1002) public abstract class EntityMixin_EntityCollision implements CollisionCapabilityBridge { - @Shadow public abstract World shadow$getEntityWorld(); + @Shadow public abstract net.minecraft.world.World shadow$getEntityWorld(); private ResourceKey entityCollision$key; private int entityCollision$maxCollisions = 8; private boolean entityCollision$refreshCache = false; @Inject(method = "", at = @At("RETURN")) - private void collisions$InjectActivationInformation(net.minecraft.entity.EntityType type, World world, CallbackInfo ci) { + private void collisions$InjectActivationInformation(net.minecraft.entity.EntityType type, net.minecraft.world.World world, CallbackInfo ci) { if (world != null && !((WorldBridge) world).bridge$isFake() && ((WorldInfoBridge) world.getWorldInfo()).bridge$isValid()) { if ((net.minecraft.entity.Entity) (Object) this instanceof ItemEntity) { final ItemEntity item = (ItemEntity) (Object) this; @@ -87,24 +87,23 @@ public abstract class EntityMixin_EntityCollision implements CollisionCapability } @Override - public void collision$initializeCollisionState(final World world) { - final SpongeConfig worldConfigAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); - final SpongeConfig globalConfigAdapter = SpongeCommon.getGlobalConfigAdapter(); - final EntityCollisionCategory worldCollCat = worldConfigAdapter.getConfig().getEntityCollisionCategory(); - final EntityCollisionCategory globalCollCat = globalConfigAdapter.getConfig().getEntityCollisionCategory(); + public void collision$initializeCollisionState(final net.minecraft.world.World world) { + final InheritableConfigHandle worldConfigAdapter = ((WorldInfoBridge) world.getWorldInfo()).bridge$getConfigAdapter(); + final ConfigHandle globalConfigAdapter = SpongeConfigs.getCommon(); + final CollisionModCategory worldCollMod = + worldConfigAdapter.getOrCreateValue(s -> s.getEntityCollisionCategory().getModList().get(this.entityCollision$key.getNamespace()), + c -> { + // TODO: save after populating? + final CollisionModCategory globalCollision = new CollisionModCategory(this.entityCollision$key.getNamespace()); + c.getEntityCollisionCategory().getModList().put(this.entityCollision$key.getNamespace(), globalCollision); + globalCollision.getEntityList().put(this.entityCollision$key.getNamespace(), this.collision$getMaxCollisions()); + }, worldConfigAdapter.get().getEntityCollisionCategory().autoPopulateData()); + final EntityCollisionCategory worldCollCat = worldConfigAdapter.get().getEntityCollisionCategory(); this.collision$setMaxCollisions(worldCollCat.getMaxEntitiesWithinAABB()); boolean requiresSave = false; - final CollisionModCategory worldCollMod = worldCollCat.getModList().get(this.entityCollision$key.getNamespace()); - CollisionModCategory globalCollMod = globalCollCat.getModList().get(this.entityCollision$key.getNamespace()); - if (worldCollMod == null && worldCollCat.autoPopulateData()) { - globalCollMod = new CollisionModCategory(this.entityCollision$key.getNamespace()); - globalCollCat.getModList().put(this.entityCollision$key.getNamespace(), globalCollMod); - globalCollMod.getEntityList().put(this.entityCollision$key.getValue(), this.collision$getMaxCollisions()); - globalConfigAdapter.save(); - return; - } else if (worldCollMod != null) { + if (worldCollMod != null) { if (!worldCollMod.isEnabled()) { this.collision$setMaxCollisions(-1); return; @@ -127,7 +126,8 @@ public abstract class EntityMixin_EntityCollision implements CollisionCapability // entity overrides if (entityMaxCollision == null && worldCollCat.autoPopulateData()) { - globalCollMod.getEntityList().put(this.entityCollision$key.getValue(), this.collision$getMaxCollisions()); + // TODO(zml): Populate better + //globalCollMod.getEntityList().put(this.entityCollision$key.getValue(), this.collision$getMaxCollisions()); requiresSave = true; } else if (entityMaxCollision != null) { this.collision$setMaxCollisions(entityMaxCollision); diff --git a/src/mixins/java/org/spongepowered/common/mixin/movementcheck/network/play/ServerPlayNetHandlerMixin_MovementCheck.java b/src/mixins/java/org/spongepowered/common/mixin/movementcheck/network/play/ServerPlayNetHandlerMixin_MovementCheck.java index 7daee767b46..1a7b1971abf 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/movementcheck/network/play/ServerPlayNetHandlerMixin_MovementCheck.java +++ b/src/mixins/java/org/spongepowered/common/mixin/movementcheck/network/play/ServerPlayNetHandlerMixin_MovementCheck.java @@ -27,20 +27,23 @@ import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.network.play.ServerPlayNetHandler; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.ModifyConstant; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Slice; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; @Mixin(ServerPlayNetHandler.class) public abstract class ServerPlayNetHandlerMixin_MovementCheck { + @Shadow public ServerPlayerEntity player; + @Redirect(method = "processPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;isInvulnerableDimensionChange()Z", ordinal = 0)) private boolean movementCheck$onPlayerMovedTooQuicklyCheck(ServerPlayerEntity player) { - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getMovementChecks().playerMovedTooQuickly()) { + if (SpongeConfigs.getForWorld(this.player.world).get().getMovementChecks().playerMovedTooQuickly()) { return player.isInvulnerableDimensionChange(); } return true; // The 'moved too quickly' check only executes if isInvulnerableDimensionChange return false @@ -49,7 +52,7 @@ public abstract class ServerPlayNetHandlerMixin_MovementCheck { @Redirect(method = "processPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;isInvulnerableDimensionChange()Z", ordinal = 1)) private boolean movementCheck$onMovedWronglyCheck(ServerPlayerEntity player) { - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getMovementChecks().movedWrongly()) { + if (SpongeConfigs.getForWorld(this.player.world).get().getMovementChecks().movedWrongly()) { return player.isInvulnerableDimensionChange(); } return true; // The 'moved too quickly' check only executes if isInvulnerableDimensionChange return false @@ -61,7 +64,7 @@ public abstract class ServerPlayNetHandlerMixin_MovementCheck { to = @At(value = "INVOKE", target = "Lnet/minecraft/network/play/ServerPlayNetHandler;func_217264_d()Z", ordinal = 0)) ) private double movementCheck$onVehicleMovedTooQuicklyCheck(double val) { - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getMovementChecks().playerVehicleMovedTooQuickly()) { + if (SpongeConfigs.getForWorld(this.player.world).get().getMovementChecks().playerVehicleMovedTooQuickly()) { return val; } return Double.NaN; // The 'vehicle moved too quickly' check only executes if the squared difference of the motion vectors lengths is greater than 100 @@ -81,7 +84,7 @@ public abstract class ServerPlayNetHandlerMixin_MovementCheck { remap = false) )) private double movementCheck$onMovedWronglySecond(double val) { - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getMovementChecks().movedWrongly()) { + if (SpongeConfigs.getForWorld(this.player.world).get().getMovementChecks().movedWrongly()) { return val; } return Double.NaN; // The second 'moved wrongly' check only executes if the length of the movement vector is greater than 0.0625D diff --git a/src/mixins/java/org/spongepowered/common/mixin/plugin/BungeeCordPlugin.java b/src/mixins/java/org/spongepowered/common/mixin/plugin/BungeeCordPlugin.java index 97cea1948a7..0bf0f92cfbd 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/BungeeCordPlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/BungeeCordPlugin.java @@ -27,7 +27,7 @@ import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; import java.util.List; import java.util.Set; @@ -45,7 +45,7 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - final boolean useBunge = SpongeCommon.getGlobalConfigAdapter().getConfig().getModules().usePluginBungeeCord(); + final boolean useBunge = SpongeConfigs.getCommon().get().getModules().usePluginBungeeCord(); final boolean contains = mixinClassName.contains("mixin.bungee"); return !(!useBunge && contains); } diff --git a/src/mixins/java/org/spongepowered/common/mixin/plugin/ConcurrentCheckPlugin.java b/src/mixins/java/org/spongepowered/common/mixin/plugin/ConcurrentCheckPlugin.java index c6cf5601ca5..961942c42ed 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/ConcurrentCheckPlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/ConcurrentCheckPlugin.java @@ -27,7 +27,7 @@ import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; import java.util.List; import java.util.Set; @@ -47,9 +47,9 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { if ("org.spongepowered.common.mixin.concurrentchecks.ClassInheritanceMultiMapMixin".equals(mixinClassName)) { - return SpongeCommon.getGlobalConfigAdapter().getConfig().getDebug().doConcurrentEntityChecks(); + return SpongeConfigs.getCommon().get().getDebug().doConcurrentEntityChecks(); } else if ("org.spongepowered.common.mixin.invalid.concurrentchecks.PlayerChunkMapMixin_ConcurrentChecks".equals(mixinClassName)) { - return SpongeCommon.getGlobalConfigAdapter().getConfig().getDebug().doConcurrentChunkMapChecks(); + return SpongeConfigs.getCommon().get().getDebug().doConcurrentChunkMapChecks(); } return true; } diff --git a/src/mixins/java/org/spongepowered/common/mixin/plugin/CorePlugin.java b/src/mixins/java/org/spongepowered/common/mixin/plugin/CorePlugin.java index 4d741435e11..873f0d2cde0 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/CorePlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/CorePlugin.java @@ -25,23 +25,16 @@ package org.spongepowered.common.mixin.plugin; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.apache.logging.log4j.Level; -import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.util.PrettyPrinter; import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.util.MissingImplementationException; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.ListIterator; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; diff --git a/src/mixins/java/org/spongepowered/common/mixin/plugin/ExploitPlugin.java b/src/mixins/java/org/spongepowered/common/mixin/plugin/ExploitPlugin.java index 9bdeafe1a01..a57fb2dd3ac 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/ExploitPlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/ExploitPlugin.java @@ -29,9 +29,9 @@ import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.util.PrettyPrinter; -import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.category.ExploitCategory; -import org.spongepowered.common.config.type.GlobalConfig; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.common.ExploitCategory; +import org.spongepowered.common.config.common.CommonConfig; import java.util.List; import java.util.Map; @@ -53,7 +53,7 @@ public String getRefMapperConfig() { public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { String[] className = mixinClassName.split("_"); String end = className[className.length - 1]; - final GlobalConfig globalConfig = SpongeCommon.getGlobalConfigAdapter().getConfig(); + final CommonConfig globalConfig = SpongeConfigs.getCommon().get(); if (globalConfig.getModules().useExploitPatches()) { final Function function = mixinEnabledMappings.get(end); if (function == null) { diff --git a/src/mixins/java/org/spongepowered/common/mixin/plugin/MovementCheckPlugin.java b/src/mixins/java/org/spongepowered/common/mixin/plugin/MovementCheckPlugin.java index cb60801919e..1b1532d83ff 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/MovementCheckPlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/MovementCheckPlugin.java @@ -27,7 +27,7 @@ import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; import java.util.List; import java.util.Set; @@ -46,7 +46,7 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return SpongeCommon.getGlobalConfigAdapter().getConfig().getModules().useMovementChecks(); + return SpongeConfigs.getCommon().get().getModules().useMovementChecks(); } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/plugin/OptimizationPlugin.java b/src/mixins/java/org/spongepowered/common/mixin/plugin/OptimizationPlugin.java index 10a9f67b581..ef8a365c5a2 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/OptimizationPlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/OptimizationPlugin.java @@ -30,8 +30,9 @@ import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.util.PrettyPrinter; import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.category.OptimizationCategory; -import org.spongepowered.common.config.type.GlobalConfig; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.common.OptimizationCategory; +import org.spongepowered.common.config.common.CommonConfig; import java.util.List; import java.util.Map; @@ -51,7 +52,7 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - final GlobalConfig globalConfig = SpongeCommon.getGlobalConfigAdapter().getConfig(); + final CommonConfig globalConfig = SpongeConfigs.getCommon().get(); if (globalConfig.getModules().useOptimizations()) { final Function optimizationCategoryBooleanFunction = mixinEnabledMappings.get(mixinClassName); if (optimizationCategoryBooleanFunction == null) { @@ -97,7 +98,7 @@ public void postApply(String targetClassName, ClassNode targetClass, String mixi return optimization.usePandaRedstone() && !optimization.useEigenRedstone(); }; // So that any additional optimizations can be added in succession. - private static final Map> mixinEnabledMappings = ImmutableMap.> builder() + private static final Map> mixinEnabledMappings = ImmutableMap.> builder() .put("org.spongepowered.common.mixin.optimization.SpongeImplHooksMixin_Item_Pre_Merge", OptimizationCategory::doDropsPreMergeItemDrops) .put("org.spongepowered.common.mixin.optimization.mcp.enchantment.EnchantmentHelperMixin_No_Source_Leak", diff --git a/src/mixins/java/org/spongepowered/common/mixin/plugin/RealTimePlugin.java b/src/mixins/java/org/spongepowered/common/mixin/plugin/RealTimePlugin.java index 2f3ec57a85c..853bbb8016e 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/RealTimePlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/RealTimePlugin.java @@ -27,7 +27,7 @@ import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; import java.util.List; import java.util.Set; @@ -45,7 +45,7 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return SpongeCommon.getGlobalConfigAdapter().getConfig().getModules().usePluginRealTime(); + return SpongeConfigs.getCommon().get().getModules().usePluginRealTime(); } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/plugin/entityactivation/EntityActivationRangePlugin.java b/src/mixins/java/org/spongepowered/common/mixin/plugin/entityactivation/EntityActivationRangePlugin.java index 97825f528f6..01b0253ebf1 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/entityactivation/EntityActivationRangePlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/entityactivation/EntityActivationRangePlugin.java @@ -27,7 +27,7 @@ import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; import java.util.ArrayList; import java.util.List; @@ -48,7 +48,7 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return SpongeCommon.getGlobalConfigAdapter().getConfig().getModules().usePluginEntityActivation(); + return SpongeConfigs.getCommon().get().getModules().usePluginEntityActivation(); } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/plugin/entitycollision/EntityCollisionPlugin.java b/src/mixins/java/org/spongepowered/common/mixin/plugin/entitycollision/EntityCollisionPlugin.java index 20812c5ea3f..8b07265c977 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/entitycollision/EntityCollisionPlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/entitycollision/EntityCollisionPlugin.java @@ -27,7 +27,7 @@ import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; import java.util.ArrayList; import java.util.List; @@ -48,7 +48,7 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return SpongeCommon.getGlobalConfigAdapter().getConfig().getModules().usePluginEntityCollisions(); + return SpongeConfigs.getCommon().get().getModules().usePluginEntityCollisions(); } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/plugin/tileentityactivation/TileEntityActivationPlugin.java b/src/mixins/java/org/spongepowered/common/mixin/plugin/tileentityactivation/TileEntityActivationPlugin.java index c2c07287dd3..82c96951e1a 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/tileentityactivation/TileEntityActivationPlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/tileentityactivation/TileEntityActivationPlugin.java @@ -27,7 +27,7 @@ import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; -import org.spongepowered.common.SpongeCommon; +import org.spongepowered.common.config.SpongeConfigs; import java.util.ArrayList; import java.util.List; @@ -48,7 +48,7 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return SpongeCommon.getGlobalConfigAdapter().getConfig().getModules().usePluginTileEntityActivation(); + return SpongeConfigs.getCommon().get().getModules().usePluginTileEntityActivation(); } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/tracker/world/chunk/ChunkMixin_CreatorTracked.java b/src/mixins/java/org/spongepowered/common/mixin/tracker/world/chunk/ChunkMixin_CreatorTracked.java index efc58ad9735..2c07b0c82de 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/tracker/world/chunk/ChunkMixin_CreatorTracked.java +++ b/src/mixins/java/org/spongepowered/common/mixin/tracker/world/chunk/ChunkMixin_CreatorTracked.java @@ -30,7 +30,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.World; import org.apache.logging.log4j.Level; import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.api.Server; @@ -49,8 +48,9 @@ import org.spongepowered.common.bridge.world.WorldBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; import org.spongepowered.common.bridge.world.chunk.ChunkBridge; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.InheritableConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.entity.PlayerTracker; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.common.event.tracking.phase.generation.GenerationPhase; @@ -67,8 +67,8 @@ @Mixin(value = net.minecraft.world.chunk.Chunk.class) public abstract class ChunkMixin_CreatorTracked implements ChunkBridge { - - @Shadow public abstract World shadow$getWorld(); + + @Shadow public abstract net.minecraft.world.World shadow$getWorld(); @Shadow public abstract ChunkPos shadow$getPos(); @Shadow public abstract Map shadow$getTileEntityMap(); @@ -90,7 +90,7 @@ public abstract class ChunkMixin_CreatorTracked implements ChunkBridge { } // Update TE tracking cache // We must always check for a TE as a mod block may not implement ITileEntityProvider if a TE exists - // Note: We do not check SpongeImplHooks.hasBlockTileEntity(block, state) as neighbor notifications do not + // Note: We do not check SpongeImplHooks.hasBlockTileEntity(block, state) as neighbor notifications do not // include blockstate. final TileEntity tileEntity = this.shadow$getTileEntityMap().get(pos); if (tileEntity != null) { @@ -110,9 +110,9 @@ public abstract class ChunkMixin_CreatorTracked implements ChunkBridge { } } - final SpongeConfig configAdapter = ((WorldInfoBridge) this.shadow$getWorld().getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().blockTrackLogging()) { - if (!configAdapter.getConfig().getBlockTracking().getBlockBlacklist().contains(((BlockType) block).getKey().toString())) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) this.shadow$getWorld().getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().blockTrackLogging()) { + if (!configAdapter.get().getBlockTracking().getBlockBlacklist().contains(((BlockType) block).getKey().getFormatted())) { SpongeHooks.logBlockTrack(this.shadow$getWorld(), block, pos, user, true); } else { SpongeHooks.logBlockTrack(this.shadow$getWorld(), block, pos, user, false); @@ -263,7 +263,7 @@ public abstract class ChunkMixin_CreatorTracked implements ChunkBridge { final UUID uuid = (((WorldInfoBridge) this.shadow$getWorld().getWorldInfo()).bridge$getUniqueIdForIndex(creatorIndex)).orElse(null); if (uuid != null) { // Verify id is valid and not invalid - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getWorld().getInvalidLookupUuids().contains(uuid)) { + if (SpongeConfigs.getCommon().get().getWorld().getInvalidLookupUuids().contains(uuid)) { this.tracker$trackedIntBlockPositions.remove(key); return Optional.empty(); } @@ -401,7 +401,7 @@ public abstract class ChunkMixin_CreatorTracked implements ChunkBridge { } private SpongeUserManager getUserManager() { - final World world = this.shadow$getWorld(); + final net.minecraft.world.World world = this.shadow$getWorld(); if (world == null || ((WorldBridge) world).bridge$isFake()) { return null; } diff --git a/src/mixins/java/org/spongepowered/common/mixin/tracker/world/server/ChunkManagerMixin_Tracker.java b/src/mixins/java/org/spongepowered/common/mixin/tracker/world/server/ChunkManagerMixin_Tracker.java index e1271e4c9c7..52c0a3b9c19 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/tracker/world/server/ChunkManagerMixin_Tracker.java +++ b/src/mixins/java/org/spongepowered/common/mixin/tracker/world/server/ChunkManagerMixin_Tracker.java @@ -42,8 +42,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.util.PrettyPrinter; import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.SpongeImplHooks; import org.spongepowered.common.bridge.world.WorldBridge; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.common.event.tracking.PhasePrinter; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.common.event.tracking.phase.generation.GenerationPhase; @@ -59,7 +59,7 @@ public abstract class ChunkManagerMixin_Tracker { at = @At(value = "NEW", args = "class=java/lang/IllegalStateException", remap = false)) private IllegalStateException impl$reportEntityAlreadyTrackedWithWorld(final String string, final Entity entityIn) { final IllegalStateException exception = new IllegalStateException(String.format("Entity %s is already tracked for world: %s", entityIn, this.world.getWorldInfo().getWorldName())); - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getPhaseTracker().verboseErrors()) { + if (SpongeConfigs.getCommon().get().getPhaseTracker().verboseErrors()) { PhasePrinter.printMessageWithCaughtException(PhaseTracker.getInstance(), "Exception tracking entity", "An entity that was already tracked was added to the tracker!", exception); } return exception; diff --git a/src/mixins/java/org/spongepowered/common/mixin/tracking/world/ChunkMixin_Tracker.java b/src/mixins/java/org/spongepowered/common/mixin/tracking/world/ChunkMixin_Tracker.java index 64782c319ce..5671ee86610 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/tracking/world/ChunkMixin_Tracker.java +++ b/src/mixins/java/org/spongepowered/common/mixin/tracking/world/ChunkMixin_Tracker.java @@ -29,7 +29,6 @@ import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import org.spongepowered.api.Server; import org.spongepowered.api.block.BlockType; import org.spongepowered.api.entity.living.player.User; @@ -37,14 +36,14 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.SpongeImplHooks; import org.spongepowered.common.bridge.CreatorTrackedBridge; import org.spongepowered.common.bridge.world.WorldBridge; import org.spongepowered.common.bridge.world.chunk.ChunkBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.type.WorldConfig; +import org.spongepowered.common.config.InheritableConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.entity.PlayerTracker; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.common.profile.SpongeGameProfileManager; @@ -62,10 +61,10 @@ @Mixin(value = net.minecraft.world.chunk.Chunk.class) public abstract class ChunkMixin_Tracker implements ChunkBridge { - + @Shadow @Final private Map tileEntities; - @Shadow public abstract World shadow$getWorld(); + @Shadow public abstract net.minecraft.world.World shadow$getWorld(); private Map trackerImpl$trackedIntBlockPositions = new HashMap<>(); private Map trackerImpl$trackedShortBlockPositions = new HashMap<>(); @@ -85,7 +84,7 @@ public abstract class ChunkMixin_Tracker implements ChunkBridge { } // Update TE tracking cache // We must always check for a TE as a mod block may not implement ITileEntityProvider if a TE exists - // Note: We do not check SpongeImplHooks.hasBlockTileEntity(block, state) as neighbor notifications do not + // Note: We do not check SpongeImplHooks.hasBlockTileEntity(block, state) as neighbor notifications do not // include blockstate. final TileEntity tileEntity = this.tileEntities.get(pos); if (tileEntity != null) { @@ -105,9 +104,9 @@ public abstract class ChunkMixin_Tracker implements ChunkBridge { } } - final SpongeConfig configAdapter = ((WorldInfoBridge) this.shadow$getWorld().getWorldInfo()).bridge$getConfigAdapter(); - if (configAdapter.getConfig().getLogging().blockTrackLogging()) { - if (!configAdapter.getConfig().getBlockTracking().getBlockBlacklist().contains(((BlockType) block).getKey().toString())) { + final InheritableConfigHandle configAdapter = ((WorldInfoBridge) this.shadow$getWorld().getWorldInfo()).bridge$getConfigAdapter(); + if (configAdapter.get().getLogging().blockTrackLogging()) { + if (!configAdapter.get().getBlockTracking().getBlockBlacklist().contains(((BlockType) block).getKey().toString())) { SpongeHooks.logBlockTrack(this.shadow$getWorld(), block, pos, user, true); } else { SpongeHooks.logBlockTrack(this.shadow$getWorld(), block, pos, user, false); @@ -258,7 +257,7 @@ public abstract class ChunkMixin_Tracker implements ChunkBridge { final UUID uuid = (((WorldInfoBridge) this.shadow$getWorld().getWorldInfo()).bridge$getUniqueIdForIndex(creatorIndex)).orElse(null); if (uuid != null) { // Verify id is valid and not invalid - if (SpongeCommon.getGlobalConfigAdapter().getConfig().getWorld().getInvalidLookupUuids().contains(uuid)) { + if (SpongeConfigs.getCommon().get().getWorld().getInvalidLookupUuids().contains(uuid)) { this.trackerImpl$trackedIntBlockPositions.remove(key); return Optional.empty(); } @@ -355,7 +354,7 @@ public abstract class ChunkMixin_Tracker implements ChunkBridge { } private SpongeUserManager getUserManager() { - final World world = this.shadow$getWorld(); + final net.minecraft.world.World world = this.shadow$getWorld(); if (world == null || ((WorldBridge) world).bridge$isFake()) { return null; } diff --git a/vanilla/src/main/java/org/spongepowered/vanilla/world/VanillaWorldManager.java b/vanilla/src/main/java/org/spongepowered/vanilla/world/VanillaWorldManager.java index 473cc64ecc8..a6fcc36b96f 100644 --- a/vanilla/src/main/java/org/spongepowered/vanilla/world/VanillaWorldManager.java +++ b/vanilla/src/main/java/org/spongepowered/vanilla/world/VanillaWorldManager.java @@ -64,14 +64,14 @@ import org.spongepowered.common.bridge.world.WorldSettingsBridge; import org.spongepowered.common.bridge.world.dimension.DimensionTypeBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.SpongeConfig; -import org.spongepowered.common.config.type.GeneralConfigBase; +import org.spongepowered.common.config.InheritableConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.common.accessor.util.registry.SimpleRegistryAccessor; import org.spongepowered.common.accessor.world.dimension.DimensionTypeAccessor; +import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.common.user.SpongeUserManager; import org.spongepowered.common.util.Constants; -import org.spongepowered.common.util.SpongeHooks; import org.spongepowered.common.world.dimension.SpongeDimensionType; import org.spongepowered.common.world.server.SpongeWorldManager; import org.spongepowered.common.world.server.WorldRegistration; @@ -138,12 +138,12 @@ public WorldInfo getInfo(final DimensionType dimensionType) { public Optional getWorld(final ResourceKey key) { Preconditions.checkNotNull(key); - return (Optional< org.spongepowered.api.world.server.ServerWorld>) (Object) Optional.ofNullable(this.worlds.get(key)); + return (Optional) (Object) Optional.ofNullable(this.worlds.get(key)); } @Override public Collection getWorlds() { - return Collections.unmodifiableCollection((Collection< org.spongepowered.api.world.server.ServerWorld>) (Object) this.worldsByType.values()); + return Collections.unmodifiableCollection((Collection) (Object) this.worldsByType.values()); } @Override @@ -315,10 +315,10 @@ public void loadAllWorlds(final String saveName, final String levelName, final l MinecraftServerAccessor_Vanilla.accessor$getLogger().info("Loading World '{}' ({}/{})", key, logicType.getKey().getFormatted(), dimensionType.getId()); + final InheritableConfigHandle configAdapter = SpongeConfigs.createWorld(logicType, key); if (!isDefaultWorld) { - final SpongeConfig configAdapter = SpongeHooks.getOrLoadConfigAdapter(logicType.getConfigPath(), key); - if (!configAdapter.getConfig().getWorld().isWorldEnabled()) { - SpongeCommon.getLogger().warn("World '{}' ({}/{}) has been disabled in the configuration. " + if (!configAdapter.get().getWorld().isWorldEnabled()) { + MinecraftServerAccessor_Vanilla.accessor$getLogger().warn("World '{}' ({}/{}) has been disabled in the configuration. " + "World will not be loaded...", key, logicType.getKey().getFormatted(), dimensionType.getId()); continue; } @@ -358,6 +358,7 @@ public void loadAllWorlds(final String saveName, final String levelName, final l } worldInfo = new WorldInfo(defaultSettings, isDefaultWorld ? saveName : this.getDirectoryName(key)); } + ((WorldInfoBridge) worldInfo).bridge$setConfigAdapter(configAdapter); ((ResourceKeyBridge) worldInfo).bridge$setKey(worldRegistration.getKey()); ((WorldInfoBridge) worldInfo).bridge$setDimensionType(dimensionType); @@ -367,6 +368,7 @@ public void loadAllWorlds(final String saveName, final String levelName, final l PhaseTracker.getCauseStackManager().getCurrentCause(), (WorldArchetype) (Object) defaultSettings, (WorldProperties) worldInfo)); } else { + ((WorldInfoBridge) worldInfo).bridge$setConfigAdapter(configAdapter); worldInfo.setWorldName(isDefaultWorld ? saveName : this.getDirectoryName(key)); // This may be an existing world created before Sponge was installed, handle accordingly @@ -395,7 +397,6 @@ public void loadAllWorlds(final String saveName, final String levelName, final l continue; } - infoBridge.bridge$createWorldConfig(); final IChunkStatusListener chunkStatusListener = ((MinecraftServerAccessor_Vanilla) this.server).accessor$getChunkStatusListenerFactory().create(11); diff --git a/vanilla/src/mixins/java/org/spongepowered/vanilla/mixin/core/client/MinecraftMixin_Vanilla.java b/vanilla/src/mixins/java/org/spongepowered/vanilla/mixin/core/client/MinecraftMixin_Vanilla.java index 8f1457075c4..3074e2bfa26 100644 --- a/vanilla/src/mixins/java/org/spongepowered/vanilla/mixin/core/client/MinecraftMixin_Vanilla.java +++ b/vanilla/src/mixins/java/org/spongepowered/vanilla/mixin/core/client/MinecraftMixin_Vanilla.java @@ -37,6 +37,8 @@ import org.spongepowered.common.SpongeBootstrap; import org.spongepowered.common.SpongeLifecycle; import org.spongepowered.common.bridge.client.MinecraftBridge; +import org.spongepowered.common.config.ConfigHandle; +import org.spongepowered.common.config.SpongeConfigs; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.vanilla.client.VanillaClient; @@ -63,6 +65,9 @@ public abstract class MinecraftMixin_Vanilla implements VanillaClient { @Inject(method = "init", at = @At("RETURN")) private void vanilla$callStartedEngineAndLoadedGame(CallbackInfo ci) { + // Save config now that registries have been initialized + ConfigHandle.setSaveSuppressed(false); + final SpongeLifecycle lifecycle = SpongeBootstrap.getLifecycle(); lifecycle.callStartedEngineEvent(this); diff --git a/vanilla/src/mixins/java/org/spongepowered/vanilla/mixin/core/server/dedicated/DedicatedServerMixin_Vanilla.java b/vanilla/src/mixins/java/org/spongepowered/vanilla/mixin/core/server/dedicated/DedicatedServerMixin_Vanilla.java index c079e1c2a71..92677f93394 100644 --- a/vanilla/src/mixins/java/org/spongepowered/vanilla/mixin/core/server/dedicated/DedicatedServerMixin_Vanilla.java +++ b/vanilla/src/mixins/java/org/spongepowered/vanilla/mixin/core/server/dedicated/DedicatedServerMixin_Vanilla.java @@ -42,6 +42,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.common.SpongeBootstrap; import org.spongepowered.common.SpongeLifecycle; +import org.spongepowered.common.config.ConfigHandle; import org.spongepowered.vanilla.VanillaServer; import java.io.File; @@ -60,6 +61,9 @@ public DedicatedServerMixin_Vanilla(File p_i50590_1_, Proxy p_i50590_2_, DataFix @Override public void run() { + // Save config now that registries have been initialized + ConfigHandle.setSaveSuppressed(false); + final SpongeLifecycle lifecycle = SpongeBootstrap.getLifecycle(); lifecycle.establishRegistries(); diff --git a/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/Main.java b/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/Main.java index c6783708c34..9930a34e4d9 100644 --- a/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/Main.java +++ b/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/Main.java @@ -55,6 +55,8 @@ public static void main(final String[] args) throws IOException { final String implementationVersion = PluginEnvironment.class.getPackage().getImplementationVersion(); Main.pluginEnvironment.getBlackboard().getOrCreate(PluginKeys.VERSION, () -> implementationVersion == null ? "dev" : implementationVersion); Main.pluginEnvironment.getBlackboard().getOrCreate(PluginKeys.BASE_DIRECTORY, () -> gameDirectory); + // Pass sponge base directory to SpongeConfigs + System.setProperty("org.spongepowered.common.baseDir", gameDirectory.toString()); final Path modsDirectory = gameDirectory.resolve("mods"); if (Files.notExists(modsDirectory)) { Files.createDirectories(modsDirectory); diff --git a/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/bootstrap/AbstractSpongeLaunchHandler.java b/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/bootstrap/AbstractSpongeLaunchHandler.java index 59f1b7fc620..62a16694e83 100644 --- a/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/bootstrap/AbstractSpongeLaunchHandler.java +++ b/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/bootstrap/AbstractSpongeLaunchHandler.java @@ -57,6 +57,11 @@ public abstract class AbstractSpongeLaunchHandler implements ILaunchHandlerServi * be to exclude {@code "org.neptune."}. */ protected static final List EXCLUDED_PACKAGES = Arrays.asList( + // Libraries + //"ninja.leaping.configurate.", + + // Implementation + //"org.spongepowered.vanilla.launch." ); @Override