Skip to content

Commit

Permalink
Reorganize config, make it work in mixin plugins (#3090)
Browse files Browse the repository at this point in the history
A bunch of rearrangement to better sort out which options are available
per-world, and which options are global only.

Adds a usable versioning system.
  • Loading branch information
zml2008 authored Jul 31, 2020
1 parent 2387690 commit ad94e11
Show file tree
Hide file tree
Showing 120 changed files with 1,466 additions and 1,205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,4 +150,4 @@ protected void initializeStructureData(final World worldIn)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 5 additions & 38 deletions src/main/java/org/spongepowered/common/SpongeCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,10 +58,7 @@ public final class SpongeCommon {
);

// Can't @Inject these because they are referenced before everything is initialized
@Nullable private static SpongeConfig<GlobalConfig> globalConfigAdapter;
@Nullable private static SpongeConfig<TrackerConfig> trackerConfigAdapter;
@Nullable private static SpongeConfig<CustomDataConfig> customDataConfigAdapter;
@Nullable private static SpongeConfigSaveManager configSaveManager;
@Nullable private static InheritableConfigHandle<GlobalConfig> globalConfigAdapter;

@Inject @Nullable private static SpongeGame game;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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<GlobalConfig> 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<CustomDataConfig> 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<TrackerConfig> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -105,9 +105,9 @@ public interface WorldInfoBridge {

Optional<UUID> bridge$getUniqueIdForIndex(int index);

@Nullable SpongeConfig<WorldConfig> bridge$getConfigAdapter();
@Nullable InheritableConfigHandle<WorldConfig> bridge$getConfigAdapter();

boolean bridge$createWorldConfig();
void bridge$setConfigAdapter(final InheritableConfigHandle<WorldConfig> adapter);

void bridge$saveConfig();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>We assume this is a versioned transformation. Configurate 4.0 will be
* able to enforce this.</p>
*
* <p>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.</p>
*
* @return A transformation instance
*/
default ConfigurationTransformation getTransformation() {
return EMPTY_VERSIONED;
}
}
Loading

0 comments on commit ad94e11

Please sign in to comment.