From ad28fa1645f3d3782641ab37f9585db88a9ab768 Mon Sep 17 00:00:00 2001 From: Zach Levis Date: Sat, 22 Aug 2020 13:43:00 -0700 Subject: [PATCH 1/4] Isolate early configuration classes into their own source set --- build.gradle.kts | 54 +++- .../spongepowered/common/launch/Launcher.java | 2 +- .../spongepowered/common/SpongeCommon.java | 4 +- .../bridge/world/storage/WorldInfoBridge.java | 2 +- .../command/manager/SpongeCommandManager.java | 2 +- .../common/config/SpongeConfigs.java | 259 ------------------ .../common/config/SpongeGameConfigs.java | 147 ++++++++++ .../config/customdata/CustomDataConfig.java | 2 +- .../config/metrics/MetricsConfiguration.java | 7 +- .../common/config/tracker/TrackerConfig.java | 7 +- .../data/provider/entity/PaintingData.java | 4 +- .../entity/living/human/HumanEntity.java | 4 +- .../common/event/tracking/PhaseContext.java | 2 +- .../common/event/tracking/PhasePrinter.java | 4 +- .../common/event/tracking/PhaseTracker.java | 2 +- .../profile/SpongeGameProfileManager.java | 2 +- .../aikar/timings/SpongeTimingsFactory.java | 2 +- .../co/aikar/timings/TimingsExport.java | 2 +- .../common/service/SpongeServiceProvider.java | 2 +- .../common/sql/SpongeSqlManager.java | 2 +- .../common/util/SpongeHooks.java | 4 +- .../util/SpongeMetricsConfigManager.java | 4 +- .../teleport/ConfigTeleportHelperFilter.java | 2 +- .../world/teleport/SpongeTeleportHelper.java | 2 +- ...ServerHandshakeNetHandlerMixin_Bungee.java | 2 +- .../client/CHandshakeMixin_Bungee.java | 2 +- .../mixin/core/block/LeavesBlockMixin.java | 2 +- .../core/server/MinecraftServerMixin.java | 5 +- .../core/tileentity/TileEntityTypeMixin.java | 6 +- .../core/world/storage/WorldInfoMixin.java | 12 +- .../block/BlockMixin_EntityCollision.java | 6 +- .../entity/EntityMixin_EntityCollision.java | 6 +- ...rverPlayNetHandlerMixin_MovementCheck.java | 10 +- .../common/mixin/plugin/BungeeCordPlugin.java | 2 +- .../mixin/plugin/ConcurrentCheckPlugin.java | 2 +- .../common/mixin/plugin/ExploitPlugin.java | 2 +- .../mixin/plugin/MovementCheckPlugin.java | 2 +- .../mixin/plugin/OptimizationPlugin.java | 2 +- .../common/mixin/plugin/RealTimePlugin.java | 2 +- .../EntityActivationRangePlugin.java | 2 +- .../EntityCollisionPlugin.java | 2 +- .../TileEntityActivationPlugin.java | 2 +- .../tracker/world/ChunkMixin_Tracker.java | 4 +- .../chunk/ChunkMixin_CreatorTracked.java | 4 +- .../server/ChunkManagerMixin_Tracker.java | 2 +- .../config/common/BrokenModCategory.java | 0 .../config/common/BungeeCordCategory.java | 0 .../config/common/CommandsCategory.java | 0 .../config/common/CommandsHiddenCategory.java | 0 .../common/config/common/CommonConfig.java | 19 +- .../common/config/common/DebugCategory.java | 0 .../config/common/EigenRedstoneCategory.java | 0 .../common/config/common/ExploitCategory.java | 0 .../common/config/common/GeneralCategory.java | 8 + .../common/config/common/ModuleCategory.java | 0 .../config/common/OptimizationCategory.java | 2 +- .../config/common/PermissionCategory.java | 0 .../config/common/PhaseTrackerCategory.java | 2 +- .../config/common/ServicesCategory.java | 0 .../common/config/common/SqlCategory.java | 0 .../config/common/StructureModCategory.java | 0 .../config/common/StructureSaveCategory.java | 0 .../config/common/TeleportHelperCategory.java | 0 .../common/config/common/TimingsCategory.java | 0 .../common/config/common/WorldCategory.java | 0 .../common/config/core}/Config.java | 2 +- .../common/config/core}/ConfigHandle.java | 27 +- ...FileMovingConfigurationTransformation.java | 2 +- .../config/core}/InheritableConfigHandle.java | 8 +- .../common/config/core/SpongeConfigs.java | 169 ++++++++++++ .../common/config/inheritable/BaseConfig.java | 2 +- .../BlockEntityActivationCategory.java | 0 .../BlockEntityActivationModCategory.java | 0 .../inheritable/CollisionModCategory.java | 0 .../EntityActivationModCategory.java | 0 .../EntityActivationRangeCategory.java | 0 .../config/inheritable/EntityCategory.java | 0 .../inheritable/EntityCollisionCategory.java | 0 .../config/inheritable/GlobalConfig.java | 7 +- .../config/inheritable/LoggingCategory.java | 0 .../inheritable/MovementChecksCategory.java | 0 .../inheritable/PlayerBlockTracker.java | 0 .../config/inheritable/SpawnerCategory.java | 0 .../config/inheritable/WorldCategory.java | 3 +- .../config/inheritable/WorldConfig.java | 0 .../common}/plugin/loader/PluginEngine.java | 2 +- .../plugin/loader/VanillaPluginEngine.java | 2 +- .../vanilla/world/VanillaWorldManager.java | 6 +- .../core/client/MinecraftMixin_Vanilla.java | 2 +- .../DedicatedServerMixin_Vanilla.java | 2 +- .../vanilla/modlauncher/Main.java | 4 +- .../AbstractVanillaLaunchHandler.java | 14 +- 92 files changed, 502 insertions(+), 384 deletions(-) delete mode 100644 src/main/java/org/spongepowered/common/config/SpongeConfigs.java create mode 100644 src/main/java/org/spongepowered/common/config/SpongeGameConfigs.java rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/BrokenModCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/BungeeCordCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/CommandsCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/CommandsHiddenCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/CommonConfig.java (93%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/DebugCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/EigenRedstoneCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/ExploitCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/GeneralCategory.java (90%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/ModuleCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/OptimizationCategory.java (99%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/PermissionCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java (99%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/ServicesCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/SqlCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/StructureModCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/StructureSaveCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/TeleportHelperCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/TimingsCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/common/WorldCategory.java (100%) rename src/{main/java/org/spongepowered/common/config => prelaunch/java/org/spongepowered/common/config/core}/Config.java (97%) rename src/{main/java/org/spongepowered/common/config => prelaunch/java/org/spongepowered/common/config/core}/ConfigHandle.java (91%) rename src/{main/java/org/spongepowered/common/config => prelaunch/java/org/spongepowered/common/config/core}/FileMovingConfigurationTransformation.java (98%) rename src/{main/java/org/spongepowered/common/config => prelaunch/java/org/spongepowered/common/config/core}/InheritableConfigHandle.java (96%) create mode 100644 src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/BaseConfig.java (98%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/BlockEntityActivationCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/BlockEntityActivationModCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/CollisionModCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/EntityActivationModCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/EntityActivationRangeCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/EntityCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/EntityCollisionCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/GlobalConfig.java (92%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/LoggingCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/MovementChecksCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/PlayerBlockTracker.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/SpawnerCategory.java (100%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/WorldCategory.java (98%) rename src/{main => prelaunch}/java/org/spongepowered/common/config/inheritable/WorldConfig.java (100%) rename src/{launch/java/org/spongepowered/common/launch => prelaunch/java/org/spongepowered/common}/plugin/loader/PluginEngine.java (96%) diff --git a/build.gradle.kts b/build.gradle.kts index f772f34f072..071e3ed69e7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -114,11 +114,27 @@ tasks { } from(launch.get().output) } + val prelaunchJar by registering(Jar::class) { + getArchiveClassifier().set("prelaunch") + manifest { + attributes(mapOf( + "Specification-Title" to "SpongeCommon", + "Specification-Vendor" to "SpongePowered", + "Specification-Version" to apiProject.version, + "Implementation-Title" to project.name, + "Implementation-Version" to generateImplementationVersionString(apiProject.version as String, minecraftVersion, recommendedVersion), + "Implementation-Vendor" to "SpongePowered" +// "Implementation-Timestamp" to Instant.now().format("yyyy-MM-dd'T'HH:mm:ssZ") + )) + } + from(prelaunch.get().output) + } reobf { create("mixinsJar") create("accessorsJar") create("launchJar") + // TODO: does prelaunch need to be here? it has no reference to obf classes } } @@ -128,18 +144,23 @@ version = generateImplementationVersionString(apiProject.version as String, mine // Configurations val minecraftConfig by configurations.named("minecraft") +val prelaunchConfig by configurations.register("preLaunch") + val launchConfig by configurations.register("launch") { extendsFrom(minecraftConfig) + extendsFrom(prelaunchConfig) } val accessorsConfig by configurations.register("accessors") { extendsFrom(minecraftConfig) extendsFrom(launchConfig) } val mixinsConfig by configurations.register("mixins") { + extendsFrom(prelaunchConfig) extendsFrom(launchConfig) extendsFrom(minecraftConfig) } val modlauncherConfig by configurations.register("modlauncher") { + extendsFrom(prelaunchConfig) extendsFrom(launchConfig) extendsFrom(minecraftConfig) } @@ -147,7 +168,14 @@ val modlauncherConfig by configurations.register("modlauncher") { // create the sourcesets val main by sourceSets +val prelaunch by sourceSets.registering { + applyNamedDependencyOnOutput(originProject = project, sourceAdding = this, targetSource = main, implProject = project, dependencyConfigName = main.implementationConfigurationName) + project.dependencies { + mixinsConfig(this@registering.output) + } +} val launch by sourceSets.registering { + applyNamedDependencyOnOutput(originProject = project, sourceAdding = prelaunch.get(), targetSource = this, implProject = project, dependencyConfigName = this.implementationConfigurationName) project.dependencies { mixinsConfig(this@registering.output) } @@ -163,6 +191,7 @@ val accessors by sourceSets.registering { } val mixins by sourceSets.registering { applyNamedDependencyOnOutput(originProject = project, sourceAdding = launch.get(), targetSource = this, implProject = project, dependencyConfigName = this.implementationConfigurationName) + applyNamedDependencyOnOutput(originProject = project, sourceAdding = prelaunch.get(), targetSource = this, implProject = project, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = project, sourceAdding = accessors.get(), targetSource = this, implProject = project, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = project, sourceAdding = main, targetSource = this, implProject = project, dependencyConfigName = this.implementationConfigurationName) } @@ -212,13 +241,17 @@ dependencies { launchConfig("com.google.code.gson:gson:2.8.0") launchConfig("org.ow2.asm:asm-tree:6.2") launchConfig("org.ow2.asm:asm-util:6.2") - launchConfig("org.apache.logging.log4j:log4j-api:2.11.2") - launchConfig("org.spongepowered:configurate-core:3.7.1") - launchConfig("org.spongepowered:configurate-hocon:3.7.1") - launchConfig("org.spongepowered:configurate-json:3.7.1") - launchConfig("org.apache.logging.log4j:log4j-core:2.11.2") add(launch.get().implementationConfigurationName, launchConfig) + // Prelaunch -- initialization that needs to occur without game access + prelaunchConfig("org.spongepowered:plugin-spi:0.1.1-SNAPSHOT") + prelaunchConfig("org.apache.logging.log4j:log4j-api:2.11.2") + prelaunchConfig("org.spongepowered:configurate-core:3.7.1") + prelaunchConfig("org.spongepowered:configurate-hocon:3.7.1") + prelaunchConfig("org.spongepowered:configurate-json:3.7.1") + prelaunchConfig("org.apache.logging.log4j:log4j-core:2.11.2") + add(prelaunch.get().implementationConfigurationName, prelaunchConfig) + // Annotation Processor "accessorsAnnotationProcessor"("org.spongepowered:mixin:$mixinVersion:processor") "mixinsAnnotationProcessor"("org.spongepowered:mixin:$mixinVersion:processor") @@ -399,16 +432,19 @@ project("SpongeVanilla") { // implementation (compile) dependencies applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = accessors.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = launch.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) + applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = prelaunch.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) } val vanillaLaunch by sourceSets.register("launch") { // implementation (compile) dependencies applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = launch.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) + applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = prelaunch.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = main, targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = vanillaProject, sourceAdding = this, targetSource = vanillaMain, implProject = vanillaProject, dependencyConfigName = vanillaMain.implementationConfigurationName) } val vanillaAccessors by sourceSets.register("accessors") { // implementation (compile) dependencies applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = launch.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) + applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = prelaunch.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = accessors.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = vanillaProject, sourceAdding = this, targetSource = vanillaMain, implProject = vanillaProject, dependencyConfigName = vanillaMain.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = vanillaProject, sourceAdding = vanillaLaunch, targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) @@ -419,6 +455,7 @@ project("SpongeVanilla") { applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = accessors.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = vanillaProject, sourceAdding = vanillaAccessors, targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = launch.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) + applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = prelaunch.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = main, targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = vanillaProject, sourceAdding = vanillaMain, targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = vanillaProject, sourceAdding = vanillaLaunch, targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) @@ -427,6 +464,7 @@ project("SpongeVanilla") { // implementation (compile) dependencies applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = launch.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = vanillaProject, sourceAdding = vanillaLaunch, targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) + applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = prelaunch.get(), targetSource = this, implProject = vanillaProject, dependencyConfigName = this.implementationConfigurationName) // runtime dependencies - literally add the rest of the project, because we want to launch the game applyNamedDependencyOnOutput(originProject = vanillaProject, sourceAdding = vanillaMixins, targetSource = this, implProject = vanillaProject, dependencyConfigName = this.runtimeConfigurationName) applyNamedDependencyOnOutput(originProject = vanillaProject, sourceAdding = vanillaAccessors, targetSource = this, implProject = vanillaProject, dependencyConfigName = this.runtimeConfigurationName) @@ -642,6 +680,7 @@ project("SpongeVanilla") { from(commonProject.tasks.getByName("mixinsJar")) from(commonProject.tasks.getByName("accessorsJar")) from(commonProject.tasks.getByName("launchJar")) + from(commonProject.tasks.getByName("prelaunchJar")) from(jar) from(vanillaLaunchJar) from(vanillaModLauncherJar) @@ -670,6 +709,7 @@ project("SpongeVanilla") { from(commonProject.tasks.getByName("mixinsJar")) from(commonProject.tasks.getByName("accessorsJar")) from(commonProject.tasks.getByName("launchJar")) + from(commonProject.tasks.getByName("prelaunchJar")) from(jar) from(vanillaLaunchJar) from(vanillaModLauncherJar) @@ -769,16 +809,19 @@ if (spongeForge != null) { // implementation (compile) dependencies applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = accessors.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = launch.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) + applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = prelaunch.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) } val forgeLaunch by sourceSets.register("launch") { // implementation (compile) dependencies applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = launch.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) + applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = prelaunch.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = main, targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = forgeProject, sourceAdding = this, targetSource = forgeMain, implProject = forgeProject, dependencyConfigName = forgeMain.implementationConfigurationName) } val forgeAccessors by sourceSets.register("accessors") { // implementation (compile) dependencies applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = launch.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) + applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = prelaunch.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = accessors.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = forgeProject, sourceAdding = this, targetSource = forgeMain, implProject = forgeProject, dependencyConfigName = forgeMain.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = forgeProject, sourceAdding = forgeLaunch, targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) @@ -789,6 +832,7 @@ if (spongeForge != null) { applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = accessors.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = forgeProject, sourceAdding = forgeAccessors, targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = launch.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) + applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = prelaunch.get(), targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = commonProject, sourceAdding = main, targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = forgeProject, sourceAdding = forgeMain, targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) applyNamedDependencyOnOutput(originProject = forgeProject, sourceAdding = forgeLaunch, targetSource = this, implProject = forgeProject, dependencyConfigName = this.implementationConfigurationName) diff --git a/src/launch/java/org/spongepowered/common/launch/Launcher.java b/src/launch/java/org/spongepowered/common/launch/Launcher.java index bf125e41132..22ae5c7dde8 100644 --- a/src/launch/java/org/spongepowered/common/launch/Launcher.java +++ b/src/launch/java/org/spongepowered/common/launch/Launcher.java @@ -30,7 +30,7 @@ import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.common.launch.plugin.DummyPluginContainer; -import org.spongepowered.common.launch.plugin.loader.PluginEngine; +import org.spongepowered.common.plugin.loader.PluginEngine; import org.spongepowered.common.launch.plugin.SpongePluginManager; import org.spongepowered.plugin.PluginContainer; import org.spongepowered.plugin.PluginKeys; diff --git a/src/main/java/org/spongepowered/common/SpongeCommon.java b/src/main/java/org/spongepowered/common/SpongeCommon.java index 855197b485d..9e67c5ab831 100644 --- a/src/main/java/org/spongepowered/common/SpongeCommon.java +++ b/src/main/java/org/spongepowered/common/SpongeCommon.java @@ -32,8 +32,8 @@ import org.spongepowered.api.Sponge; import org.spongepowered.api.event.Event; import org.spongepowered.api.util.Direction; -import org.spongepowered.common.config.InheritableConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.InheritableConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.inheritable.GlobalConfig; import org.spongepowered.common.launch.Launcher; import org.spongepowered.common.registry.SpongeGameRegistry; 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 79309424660..ab1610873bf 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 @@ -29,7 +29,7 @@ import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.server.ServerWorld; import org.spongepowered.api.world.SerializationBehavior; -import org.spongepowered.common.config.InheritableConfigHandle; +import org.spongepowered.common.config.core.InheritableConfigHandle; import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.world.dimension.SpongeDimensionType; 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 0e4605b01d1..717859bc3d3 100644 --- a/src/main/java/org/spongepowered/common/command/manager/SpongeCommandManager.java +++ b/src/main/java/org/spongepowered/common/command/manager/SpongeCommandManager.java @@ -74,7 +74,7 @@ import org.spongepowered.common.command.registrar.SpongeParameterizedCommandRegistrar; import org.spongepowered.common.command.registrar.tree.builder.RootCommandTreeNode; import org.spongepowered.common.command.sponge.SpongeCommand; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.event.ShouldFire; import org.spongepowered.common.event.lifecycle.RegisterCommandEventImpl; import org.spongepowered.common.event.tracking.PhaseTracker; diff --git a/src/main/java/org/spongepowered/common/config/SpongeConfigs.java b/src/main/java/org/spongepowered/common/config/SpongeConfigs.java deleted file mode 100644 index 13b6e02597b..00000000000 --- a/src/main/java/org/spongepowered/common/config/SpongeConfigs.java +++ /dev/null @@ -1,259 +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.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/SpongeGameConfigs.java b/src/main/java/org/spongepowered/common/config/SpongeGameConfigs.java new file mode 100644 index 00000000000..da6cb2e8ae7 --- /dev/null +++ b/src/main/java/org/spongepowered/common/config/SpongeGameConfigs.java @@ -0,0 +1,147 @@ +/* + * 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.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; +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.bridge.world.storage.WorldInfoBridge; +import org.spongepowered.common.config.core.ConfigHandle; +import org.spongepowered.common.config.core.InheritableConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; +import org.spongepowered.common.config.customdata.CustomDataConfig; +import org.spongepowered.common.config.inheritable.WorldConfig; +import org.spongepowered.common.config.tracker.TrackerConfig; +import org.spongepowered.common.world.server.SpongeWorldManager; + +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.concurrent.CompletableFuture; + +/** + * SpongeCommon configurations that need to interact with game state + */ +public class SpongeGameConfigs { + + static final Logger LOGGER = LogManager.getLogger(); + + static ConfigHandle trackerConfigAdapter; + static ConfigHandle customDataConfigAdapter; + + 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 (customDataConfigAdapter == null) { + customDataConfigAdapter = SpongeConfigs.create(new CustomDataConfig(), CustomDataConfig.FILE_NAME); + } + return customDataConfigAdapter; + } + + public static ConfigHandle getTracker() { + if (trackerConfigAdapter == null) { + trackerConfigAdapter = SpongeConfigs.create(new TrackerConfig(), TrackerConfig.FILE_NAME); + } + return 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(); + } + + public static InheritableConfigHandle createWorld(final @Nullable DimensionType legacyType, final ResourceKey world) { + // Path format: config/sponge/worlds//.conf + final Path configPath = SpongeConfigs.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 = SpongeConfigs.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 { + @SuppressWarnings("deprecation") // deprecated to discourage usage outside of this method + 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 SpongeConfigs.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/customdata/CustomDataConfig.java b/src/main/java/org/spongepowered/common/config/customdata/CustomDataConfig.java index d6f0a649b60..f23f3e03963 100644 --- a/src/main/java/org/spongepowered/common/config/customdata/CustomDataConfig.java +++ b/src/main/java/org/spongepowered/common/config/customdata/CustomDataConfig.java @@ -25,7 +25,7 @@ package org.spongepowered.common.config.customdata; import ninja.leaping.configurate.objectmapping.Setting; -import org.spongepowered.common.config.Config; +import org.spongepowered.common.config.core.Config; public final class CustomDataConfig implements Config { diff --git a/src/main/java/org/spongepowered/common/config/metrics/MetricsConfiguration.java b/src/main/java/org/spongepowered/common/config/metrics/MetricsConfiguration.java index 9e933a99595..d66dbf6c557 100644 --- a/src/main/java/org/spongepowered/common/config/metrics/MetricsConfiguration.java +++ b/src/main/java/org/spongepowered/common/config/metrics/MetricsConfiguration.java @@ -28,19 +28,18 @@ 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.common.config.core.Config; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.plugin.PluginContainer; import java.util.Collections; import java.util.HashMap; import java.util.Map; -// TODO: migration -- `sponge/metrics` from old `global.conf` - @ConfigSerializable public class MetricsConfiguration implements Config { - public static String FILE_NAME = "metrics.conf"; + public static String FILE_NAME = SpongeConfigs.METRICS_NAME; @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.") diff --git a/src/main/java/org/spongepowered/common/config/tracker/TrackerConfig.java b/src/main/java/org/spongepowered/common/config/tracker/TrackerConfig.java index 6d1f8925190..063c21f6537 100644 --- a/src/main/java/org/spongepowered/common/config/tracker/TrackerConfig.java +++ b/src/main/java/org/spongepowered/common/config/tracker/TrackerConfig.java @@ -25,15 +25,10 @@ package org.spongepowered.common.config.tracker; import ninja.leaping.configurate.objectmapping.Setting; -import org.spongepowered.common.config.Config; -import org.spongepowered.common.config.ConfigHandle; +import org.spongepowered.common.config.core.Config; import org.spongepowered.common.event.tracking.IPhaseState; import org.spongepowered.common.event.tracking.PhaseContext; -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"; 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 17cef4b9fb3..901c215c676 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,7 +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.config.SpongeGameConfigs; import org.spongepowered.common.data.provider.DataProviderRegistrator; import java.util.ArrayList; @@ -80,7 +80,7 @@ public static void register(final DataProviderRegistrator registrator) { for (final ServerPlayerEntity player : players) { SpongeCommon.getServerScheduler().submit(Task.builder() .plugin(SpongeCommon.getPlugin()) - .delayTicks(SpongeConfigs.getForWorld(h.world).get().getEntity().getPaintingRespawnDelay()) + .delayTicks(SpongeGameConfigs.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/living/human/HumanEntity.java b/src/main/java/org/spongepowered/common/entity/living/human/HumanEntity.java index 61d81fcea8f..c6a10f56fa8 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,7 +69,7 @@ import org.spongepowered.common.accessor.network.play.server.SPlayerListItemPacketAccessor; import org.spongepowered.common.accessor.network.play.server.SSpawnPlayerPacketAccessor; import org.spongepowered.common.bridge.data.DataCompoundHolder; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.SpongeGameConfigs; import org.spongepowered.common.util.Constants; import java.util.ArrayList; @@ -340,7 +340,7 @@ private boolean updateFakeProfileWithSkin(final UUID skin) { } public void removeFromTabListDelayed(@Nullable final ServerPlayerEntity player, final SPlayerListItemPacket removePacket) { - final int delay = SpongeConfigs.getForWorld(this.world).get().getEntity().getHumanPlayerListRemoveDelay(); + final int delay = SpongeGameConfigs.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 0f920d50884..f4d9683d49b 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/PhaseContext.java +++ b/src/main/java/org/spongepowered/common/event/tracking/PhaseContext.java @@ -44,7 +44,7 @@ import org.spongepowered.api.event.EventContextKeys; import org.spongepowered.common.block.SpongeBlockSnapshot; import org.spongepowered.common.bridge.inventory.container.TrackedInventoryBridge; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.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; 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 e8ff1247869..4751cfc936b 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/PhasePrinter.java +++ b/src/main/java/org/spongepowered/common/event/tracking/PhasePrinter.java @@ -34,8 +34,8 @@ import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.bridge.world.ServerWorldBridge; import org.spongepowered.common.bridge.world.TrackedWorldBridge; -import org.spongepowered.common.config.ConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.ConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.common.CommonConfig; import org.spongepowered.common.config.common.PhaseTrackerCategory; import org.spongepowered.common.util.PrettyPrinter; 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 6ebbfca3e52..ed2ee483b51 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/PhaseTracker.java +++ b/src/main/java/org/spongepowered/common/event/tracking/PhaseTracker.java @@ -68,7 +68,7 @@ import org.spongepowered.common.accessor.world.server.ServerWorldAccessor; import org.spongepowered.common.bridge.CreatorTrackedBridge; import org.spongepowered.common.bridge.entity.EntityBridge; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.common.PhaseTrackerCategory; import org.spongepowered.common.entity.EntityUtil; import org.spongepowered.common.event.ShouldFire; diff --git a/src/main/java/org/spongepowered/common/profile/SpongeGameProfileManager.java b/src/main/java/org/spongepowered/common/profile/SpongeGameProfileManager.java index 4f5412534b8..625f6a9a4db 100644 --- a/src/main/java/org/spongepowered/common/profile/SpongeGameProfileManager.java +++ b/src/main/java/org/spongepowered/common/profile/SpongeGameProfileManager.java @@ -34,7 +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.config.core.SpongeConfigs; import org.spongepowered.common.profile.query.GameProfileQuery; import org.spongepowered.common.profile.query.NameQuery; import org.spongepowered.common.profile.query.UniqueIdQuery; 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 4f3eedc7710..e6dad611e07 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,7 @@ import com.google.common.collect.EvictingQueue; import net.kyori.adventure.audience.Audience; import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.common.TimingsCategory; import org.spongepowered.plugin.PluginContainer; 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 197fd12cf2e..6c1266f00a9 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,7 +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.config.core.SpongeConfigs; import org.spongepowered.common.relocate.co.aikar.util.JSONUtil; import org.spongepowered.common.relocate.co.aikar.util.JSONUtil.JsonObjectBuilder; diff --git a/src/main/java/org/spongepowered/common/service/SpongeServiceProvider.java b/src/main/java/org/spongepowered/common/service/SpongeServiceProvider.java index cecab87c91b..75ef779ddf7 100644 --- a/src/main/java/org/spongepowered/common/service/SpongeServiceProvider.java +++ b/src/main/java/org/spongepowered/common/service/SpongeServiceProvider.java @@ -45,7 +45,7 @@ import org.spongepowered.api.service.permission.PermissionService; import org.spongepowered.api.service.whitelist.WhitelistService; import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.common.ServicesCategory; import org.spongepowered.common.event.SpongeEventManager; import org.spongepowered.common.event.lifecycle.ProvideServiceEventImpl; diff --git a/src/main/java/org/spongepowered/common/sql/SpongeSqlManager.java b/src/main/java/org/spongepowered/common/sql/SpongeSqlManager.java index 2afe055f8e5..2c5ec62d8ef 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.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.plugin.PluginContainer; import javax.annotation.Nullable; diff --git a/src/main/java/org/spongepowered/common/util/SpongeHooks.java b/src/main/java/org/spongepowered/common/util/SpongeHooks.java index 317c5543064..d9404d3b174 100644 --- a/src/main/java/org/spongepowered/common/util/SpongeHooks.java +++ b/src/main/java/org/spongepowered/common/util/SpongeHooks.java @@ -48,8 +48,8 @@ import org.spongepowered.api.entity.living.player.User; import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.InheritableConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.InheritableConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.inheritable.LoggingCategory; import org.spongepowered.common.config.inheritable.BaseConfig; import org.spongepowered.common.config.inheritable.WorldConfig; diff --git a/src/main/java/org/spongepowered/common/util/SpongeMetricsConfigManager.java b/src/main/java/org/spongepowered/common/util/SpongeMetricsConfigManager.java index b735ffcd77b..f2532d9ec55 100644 --- a/src/main/java/org/spongepowered/common/util/SpongeMetricsConfigManager.java +++ b/src/main/java/org/spongepowered/common/util/SpongeMetricsConfigManager.java @@ -28,8 +28,8 @@ import ninja.leaping.configurate.objectmapping.ObjectMappingException; import org.spongepowered.api.util.Tristate; import org.spongepowered.api.util.metric.MetricsConfigManager; -import org.spongepowered.common.config.ConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.ConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.metrics.MetricsConfiguration; import org.spongepowered.plugin.PluginContainer; 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 7fd952edf5e..a6189a9a4ec 100644 --- a/src/main/java/org/spongepowered/common/world/teleport/ConfigTeleportHelperFilter.java +++ b/src/main/java/org/spongepowered/common/world/teleport/ConfigTeleportHelperFilter.java @@ -29,7 +29,7 @@ import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockType; import org.spongepowered.api.world.teleport.TeleportHelperFilter; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.common.TeleportHelperCategory; import java.util.List; 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 9a27a097487..0122d29fefe 100644 --- a/src/main/java/org/spongepowered/common/world/teleport/SpongeTeleportHelper.java +++ b/src/main/java/org/spongepowered/common/world/teleport/SpongeTeleportHelper.java @@ -36,7 +36,7 @@ import org.spongepowered.api.world.teleport.TeleportHelperFilter; import org.spongepowered.api.world.teleport.TeleportHelperFilters; import org.spongepowered.common.bridge.world.chunk.ServerChunkProviderBridge; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.math.GenericMath; import org.spongepowered.math.vector.Vector3i; 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 e8a36e19afb..e5a31660a15 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 @@ -41,7 +41,7 @@ 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 org.spongepowered.common.config.core.SpongeConfigs; import java.net.InetSocketAddress; 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 dc9f28dc496..e7ae6d05c8b 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.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; @Mixin(CHandshakePacket.class) public abstract class CHandshakeMixin_Bungee { 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 514de2ed520..2182324c1cb 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,7 +30,7 @@ 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.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; @Mixin(LeavesBlock.class) public abstract class LeavesBlockMixin extends BlockMixin { diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/server/MinecraftServerMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/server/MinecraftServerMixin.java index c212f8104cd..905cc0d2f7b 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/server/MinecraftServerMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/server/MinecraftServerMixin.java @@ -32,7 +32,6 @@ import net.minecraft.util.concurrent.TickDelayedTask; import net.minecraft.world.Difficulty; import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.storage.SessionLockException; import org.apache.logging.log4j.Logger; import org.spongepowered.api.event.Cause; import org.spongepowered.api.resourcepack.ResourcePack; @@ -55,8 +54,8 @@ import org.spongepowered.common.bridge.server.management.PlayerProfileCacheBridge; import org.spongepowered.common.bridge.world.ServerWorldBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.InheritableConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.InheritableConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.common.relocate.co.aikar.timings.TimingsManager; 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 762a62021b8..9b34da6eeaa 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,8 +34,8 @@ import org.spongepowered.common.bridge.ResourceKeyBridge; import org.spongepowered.common.bridge.TrackableBridge; import org.spongepowered.common.bridge.tileentity.TileEntityTypeBridge; -import org.spongepowered.common.config.ConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.SpongeGameConfigs; +import org.spongepowered.common.config.core.ConfigHandle; import org.spongepowered.common.config.tracker.BlockEntityTrackerCategory; import org.spongepowered.common.config.tracker.BlockEntityTrackerModCategory; import org.spongepowered.common.config.tracker.TrackerConfig; @@ -63,7 +63,7 @@ public abstract class TileEntityTypeMixin implements ResourceKeyBridge, TileEnti final TrackableBridge trackableBridge = (TrackableBridge) tileEntityType; - final ConfigHandle trackerConfigAdapter = SpongeConfigs.getTracker(); + final ConfigHandle trackerConfigAdapter = SpongeGameConfigs.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 860276de802..69dd6f52e52 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 @@ -34,30 +34,25 @@ import net.minecraft.server.MinecraftServer; 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; import net.minecraft.world.server.ServerWorld; import net.minecraft.world.storage.DerivedWorldInfo; import net.minecraft.world.storage.WorldInfo; -import org.apache.logging.log4j.Level; import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.api.ResourceKey; import org.spongepowered.api.Sponge; import org.spongepowered.api.world.SerializationBehavior; import org.spongepowered.api.world.SerializationBehaviors; -import org.spongepowered.api.world.WorldArchetype; import org.spongepowered.api.world.dimension.DimensionTypes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.util.PrettyPrinter; import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.SpongeServer; import org.spongepowered.common.accessor.server.MinecraftServerAccessor; @@ -65,8 +60,9 @@ import org.spongepowered.common.bridge.world.WorldBridge; import org.spongepowered.common.bridge.world.WorldSettingsBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.InheritableConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.InheritableConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; +import org.spongepowered.common.config.SpongeGameConfigs; import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.util.Constants; import org.spongepowered.common.world.dimension.SpongeDimensionType; @@ -334,7 +330,7 @@ public void setDifficulty(Difficulty newDifficulty) { public InheritableConfigHandle bridge$getConfigAdapter() { if (this.impl$configAdapter == null) { if (this.bridge$isValid()) { - return SpongeConfigs.createWorld(this.bridge$getLogicType(), this.bridge$getKey()); + return SpongeGameConfigs.createWorld(this.bridge$getLogicType(), this.bridge$getKey()); } else { return SpongeConfigs.createDetached(); } 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 cffa2d13867..13af7688187 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 @@ -29,9 +29,9 @@ import org.spongepowered.api.block.BlockType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.ConfigHandle; -import org.spongepowered.common.config.InheritableConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.ConfigHandle; +import org.spongepowered.common.config.core.InheritableConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.common.CommonConfig; import org.spongepowered.common.config.inheritable.CollisionModCategory; import org.spongepowered.common.config.inheritable.EntityCollisionCategory; 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 c3fdab49295..d7beb1cd64c 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 @@ -35,9 +35,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.common.bridge.world.WorldBridge; import org.spongepowered.common.bridge.world.storage.WorldInfoBridge; -import org.spongepowered.common.config.ConfigHandle; -import org.spongepowered.common.config.InheritableConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.ConfigHandle; +import org.spongepowered.common.config.core.InheritableConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.common.CommonConfig; import org.spongepowered.common.config.inheritable.CollisionModCategory; import org.spongepowered.common.config.inheritable.EntityCollisionCategory; 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 1a7b1971abf..21aef0117e1 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 @@ -33,7 +33,7 @@ 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.config.SpongeConfigs; +import org.spongepowered.common.config.SpongeGameConfigs; @Mixin(ServerPlayNetHandler.class) public abstract class ServerPlayNetHandlerMixin_MovementCheck { @@ -43,7 +43,7 @@ public abstract class ServerPlayNetHandlerMixin_MovementCheck { @Redirect(method = "processPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;isInvulnerableDimensionChange()Z", ordinal = 0)) private boolean movementCheck$onPlayerMovedTooQuicklyCheck(ServerPlayerEntity player) { - if (SpongeConfigs.getForWorld(this.player.world).get().getMovementChecks().playerMovedTooQuickly()) { + if (SpongeGameConfigs.getForWorld(this.player.world).get().getMovementChecks().playerMovedTooQuickly()) { return player.isInvulnerableDimensionChange(); } return true; // The 'moved too quickly' check only executes if isInvulnerableDimensionChange return false @@ -52,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 (SpongeConfigs.getForWorld(this.player.world).get().getMovementChecks().movedWrongly()) { + if (SpongeGameConfigs.getForWorld(this.player.world).get().getMovementChecks().movedWrongly()) { return player.isInvulnerableDimensionChange(); } return true; // The 'moved too quickly' check only executes if isInvulnerableDimensionChange return false @@ -64,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 (SpongeConfigs.getForWorld(this.player.world).get().getMovementChecks().playerVehicleMovedTooQuickly()) { + if (SpongeGameConfigs.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 @@ -84,7 +84,7 @@ public abstract class ServerPlayNetHandlerMixin_MovementCheck { remap = false) )) private double movementCheck$onMovedWronglySecond(double val) { - if (SpongeConfigs.getForWorld(this.player.world).get().getMovementChecks().movedWrongly()) { + if (SpongeGameConfigs.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 0bf0f92cfbd..9b9012ca4cd 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.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import java.util.List; import java.util.Set; 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 961942c42ed..21fee9b38a0 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.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import java.util.List; import java.util.Set; 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 a57fb2dd3ac..39f27529f2c 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/ExploitPlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/ExploitPlugin.java @@ -29,7 +29,7 @@ import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.util.PrettyPrinter; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.common.ExploitCategory; import org.spongepowered.common.config.common.CommonConfig; 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 1b1532d83ff..4dc719b9371 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.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import java.util.List; import java.util.Set; 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 ef8a365c5a2..4a7c3dcc34d 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/plugin/OptimizationPlugin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/plugin/OptimizationPlugin.java @@ -30,7 +30,7 @@ import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.util.PrettyPrinter; import org.spongepowered.common.SpongeCommon; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.common.OptimizationCategory; import org.spongepowered.common.config.common.CommonConfig; 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 853bbb8016e..3c2b7f6f515 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.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import java.util.List; import java.util.Set; 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 01b0253ebf1..b2d3c2c27ac 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.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import java.util.ArrayList; import java.util.List; 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 8b07265c977..7cbc1aab318 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.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import java.util.ArrayList; import java.util.List; 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 82c96951e1a..5370ca0b7e7 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.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import java.util.ArrayList; import java.util.List; diff --git a/src/mixins/java/org/spongepowered/common/mixin/tracker/world/ChunkMixin_Tracker.java b/src/mixins/java/org/spongepowered/common/mixin/tracker/world/ChunkMixin_Tracker.java index 688103ef44e..040907fe0dc 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/tracker/world/ChunkMixin_Tracker.java +++ b/src/mixins/java/org/spongepowered/common/mixin/tracker/world/ChunkMixin_Tracker.java @@ -42,8 +42,8 @@ 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.InheritableConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.InheritableConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.entity.PlayerTracker; import org.spongepowered.common.event.tracking.PhaseTracker; 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 0035237ad10..7892b0d6676 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 @@ -48,8 +48,8 @@ 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.InheritableConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.InheritableConfigHandle; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.entity.PlayerTracker; import org.spongepowered.common.event.tracking.PhaseTracker; 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 eb1f5c82642..641a2497cb4 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 @@ -43,7 +43,7 @@ import org.spongepowered.asm.util.PrettyPrinter; import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.bridge.world.WorldBridge; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.event.tracking.PhasePrinter; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.common.event.tracking.phase.generation.GenerationPhase; diff --git a/src/main/java/org/spongepowered/common/config/common/BrokenModCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/BrokenModCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/BrokenModCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/BrokenModCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/BungeeCordCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/BungeeCordCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/BungeeCordCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/BungeeCordCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/CommandsCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/CommandsCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/CommandsCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/CommandsCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/CommandsHiddenCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/CommandsHiddenCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/CommandsHiddenCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/CommandsHiddenCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/CommonConfig.java b/src/prelaunch/java/org/spongepowered/common/config/common/CommonConfig.java similarity index 93% rename from src/main/java/org/spongepowered/common/config/common/CommonConfig.java rename to src/prelaunch/java/org/spongepowered/common/config/common/CommonConfig.java index e412d500e4e..329b28ed7d4 100644 --- a/src/main/java/org/spongepowered/common/config/common/CommonConfig.java +++ b/src/prelaunch/java/org/spongepowered/common/config/common/CommonConfig.java @@ -24,18 +24,12 @@ */ package org.spongepowered.common.config.common; -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.Config; -import org.spongepowered.common.util.IpSet; +import org.spongepowered.common.config.core.Config; -import java.net.InetAddress; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Predicate; /** * Sponge's core configuration. @@ -66,7 +60,7 @@ public class CommonConfig implements Config { private ModuleCategory mixins = new ModuleCategory(); @Setting("ip-sets") - private Map> ipSets = new HashMap<>(); + private Map> ipSets = new HashMap<>(); @Setting(value = "bungeecord") private BungeeCordCategory bungeeCord = new BungeeCordCategory(); @@ -136,9 +130,6 @@ public ServicesCategory getServicesCategory() { return this.servicesCategory; } - public Map> getIpSets() { - return ImmutableMap.copyOf(Maps.transformValues(this.ipSets, Predicates::and)); - } public ExploitCategory getExploits() { return this.exploits; @@ -148,9 +139,15 @@ public OptimizationCategory getOptimizations() { return this.optimizations; } + /* TODO(zml): Reimplement this when bringing in SpongeContextCalculator from invalid + public Map> getIpSets() { + return ImmutableMap.copyOf(Maps.transformValues(this.ipSets, Predicates::and)); + } + public Predicate getIpSet(String name) { return this.ipSets.containsKey(name) ? Predicates.and(this.ipSets.get(name)) : null; } + */ public PhaseTrackerCategory getPhaseTracker() { return this.causeTracker; diff --git a/src/main/java/org/spongepowered/common/config/common/DebugCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/DebugCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/DebugCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/DebugCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/EigenRedstoneCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/EigenRedstoneCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/EigenRedstoneCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/EigenRedstoneCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/ExploitCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/ExploitCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/ExploitCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/ExploitCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/GeneralCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/GeneralCategory.java similarity index 90% rename from src/main/java/org/spongepowered/common/config/common/GeneralCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/GeneralCategory.java index b9490581177..e914c6c9623 100644 --- a/src/main/java/org/spongepowered/common/config/common/GeneralCategory.java +++ b/src/prelaunch/java/org/spongepowered/common/config/common/GeneralCategory.java @@ -26,6 +26,9 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; +import org.spongepowered.common.config.core.SpongeConfigs; +import org.spongepowered.plugin.PluginEnvironment; +import org.spongepowered.plugin.PluginKeys; @ConfigSerializable public class GeneralCategory { @@ -69,4 +72,9 @@ public String configDir() { public void setConfigDir(String configDir) { this.configDir = configDir; } + private static String parsePlaceholders(final String input) { + final PluginEnvironment env = SpongeConfigs.getPluginEnvironment(); + env.getBlackboard().get(PluginKeys.PLUGIN_DIRECTORIES); + return input; + } } diff --git a/src/main/java/org/spongepowered/common/config/common/ModuleCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/ModuleCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/ModuleCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/ModuleCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/OptimizationCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/OptimizationCategory.java similarity index 99% rename from src/main/java/org/spongepowered/common/config/common/OptimizationCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/OptimizationCategory.java index 27c54d49604..4ecd467deec 100644 --- a/src/main/java/org/spongepowered/common/config/common/OptimizationCategory.java +++ b/src/prelaunch/java/org/spongepowered/common/config/common/OptimizationCategory.java @@ -121,7 +121,7 @@ public class OptimizationCategory { 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 = true; //Launcher.getInstance().isVanilla(); // TODO: how to get this info even earlier + this.preItemDropMerge = true; //Launcher.getInstance().isVanilla(); // TODO: expose this in the PluginEnvironment if necessary } diff --git a/src/main/java/org/spongepowered/common/config/common/PermissionCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/PermissionCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/PermissionCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/PermissionCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java similarity index 99% rename from src/main/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java index 2ad0b4bae3b..5e9af31f1ee 100644 --- a/src/main/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java +++ b/src/prelaunch/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java @@ -177,7 +177,7 @@ public Map getAutoFixedTiles() { } private boolean isVanilla() { - return true; //Launcher.getInstance().isVanilla(); // TODO: access earlier + return true; //Launcher.getInstance().isVanilla(); // TODO: expose this in the PluginEnvironment if necessary } public void setAutoFixedTiles(Map autoFixedTiles) { diff --git a/src/main/java/org/spongepowered/common/config/common/ServicesCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/ServicesCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/ServicesCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/ServicesCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/SqlCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/SqlCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/SqlCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/SqlCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/StructureModCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/StructureModCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/StructureModCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/StructureModCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/StructureSaveCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/StructureSaveCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/StructureSaveCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/StructureSaveCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/TeleportHelperCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/TeleportHelperCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/TeleportHelperCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/TeleportHelperCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/TimingsCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/TimingsCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/TimingsCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/TimingsCategory.java diff --git a/src/main/java/org/spongepowered/common/config/common/WorldCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/WorldCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/common/WorldCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/common/WorldCategory.java diff --git a/src/main/java/org/spongepowered/common/config/Config.java b/src/prelaunch/java/org/spongepowered/common/config/core/Config.java similarity index 97% rename from src/main/java/org/spongepowered/common/config/Config.java rename to src/prelaunch/java/org/spongepowered/common/config/core/Config.java index 4138df33260..26d74366143 100644 --- a/src/main/java/org/spongepowered/common/config/Config.java +++ b/src/prelaunch/java/org/spongepowered/common/config/core/Config.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; +package org.spongepowered.common.config.core; import ninja.leaping.configurate.transformation.ConfigurationTransformation; diff --git a/src/main/java/org/spongepowered/common/config/ConfigHandle.java b/src/prelaunch/java/org/spongepowered/common/config/core/ConfigHandle.java similarity index 91% rename from src/main/java/org/spongepowered/common/config/ConfigHandle.java rename to src/prelaunch/java/org/spongepowered/common/config/core/ConfigHandle.java index c4f83b9f430..5bbb3162d50 100644 --- a/src/main/java/org/spongepowered/common/config/ConfigHandle.java +++ b/src/prelaunch/java/org/spongepowered/common/config/core/ConfigHandle.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; +package org.spongepowered.common.config.core; import static java.util.Objects.requireNonNull; @@ -36,13 +36,14 @@ 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.Callable; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; import java.util.concurrent.ForkJoinPool; import java.util.function.UnaryOperator; @@ -128,7 +129,7 @@ public T get() { public CompletableFuture updateAndSave(final UnaryOperator updater) { final T updated = requireNonNull(updater, "updater").apply(this.mapper.getInstance()); - return Functional.asyncFailableFuture(() -> { + return asyncFailableFuture(() -> { // TODO: Force one save at a time this.save(); return updated; @@ -147,7 +148,7 @@ void load() throws IOException, ObjectMappingException { } protected final void doVersionUpdate() { - final boolean wasEmpty = this.node.getValue() == null; // TODO(Configurate 3.7) isEmpty + final boolean wasEmpty = this.node.isEmpty(); final CommentedConfigurationNode versionNode = this.node.getNode(VERSION_PATH); final int existingVersion = versionNode.getInt(-1); this.mapper.getInstance().getTransformation().apply(this.node); @@ -155,7 +156,7 @@ protected final void doVersionUpdate() { if (!wasEmpty && newVersion > existingVersion) { LOGGER.info("Updated {} from version {} to {}", this.mapper.getInstance(), existingVersion, newVersion); } - versionNode.setComment(VERSION_COMMENT); // TODO(Configurate 3.7) setCommentIfAbsent + versionNode.setCommentIfAbsent(VERSION_COMMENT); this.node.getNode(VERSION_PATH).setValue(versionNode); // workaround for some weird issue, can remove @configurate 4.0 } @@ -203,7 +204,7 @@ private CommentedConfigurationNode getSetting(String key) { } public CompletableFuture updateSetting(String key, Object value) { - return Functional.asyncFailableFuture(() -> { + return asyncFailableFuture(() -> { CommentedConfigurationNode upd = this.getSetting(key); this.mapper.populate(this.node); this.save(); @@ -212,7 +213,7 @@ public CompletableFuture updateSetting(String key, O } public CompletableFuture updateSetting(String key, V value, TypeToken token) { - return Functional.asyncFailableFuture(() -> { + return asyncFailableFuture(() -> { CommentedConfigurationNode upd = this.getSetting(key); upd.setValue(token, value); this.mapper.populate(this.node); @@ -221,6 +222,18 @@ public CompletableFuture updateSetting(String ke }, ForkJoinPool.commonPool()); } + private static CompletableFuture asyncFailableFuture(final Callable action, final Executor executor) { + final CompletableFuture future = new CompletableFuture<>(); + executor.execute(() -> { + try { + future.complete(action.call()); + } catch (Exception ex) { + future.completeExceptionally(ex); + } + }); + return future; + } + public ConfigurationNode getNode() { return this.node; } diff --git a/src/main/java/org/spongepowered/common/config/FileMovingConfigurationTransformation.java b/src/prelaunch/java/org/spongepowered/common/config/core/FileMovingConfigurationTransformation.java similarity index 98% rename from src/main/java/org/spongepowered/common/config/FileMovingConfigurationTransformation.java rename to src/prelaunch/java/org/spongepowered/common/config/core/FileMovingConfigurationTransformation.java index 6d1f4189b1b..b51b28bb0a4 100644 --- a/src/main/java/org/spongepowered/common/config/FileMovingConfigurationTransformation.java +++ b/src/prelaunch/java/org/spongepowered/common/config/core/FileMovingConfigurationTransformation.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; +package org.spongepowered.common.config.core; import com.google.common.collect.ImmutableSet; import ninja.leaping.configurate.ConfigurationNode; diff --git a/src/main/java/org/spongepowered/common/config/InheritableConfigHandle.java b/src/prelaunch/java/org/spongepowered/common/config/core/InheritableConfigHandle.java similarity index 96% rename from src/main/java/org/spongepowered/common/config/InheritableConfigHandle.java rename to src/prelaunch/java/org/spongepowered/common/config/core/InheritableConfigHandle.java index 6926b295fe7..4f90e690fe2 100644 --- a/src/main/java/org/spongepowered/common/config/InheritableConfigHandle.java +++ b/src/prelaunch/java/org/spongepowered/common/config/core/InheritableConfigHandle.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; +package org.spongepowered.common.config.core; import ninja.leaping.configurate.Types; import ninja.leaping.configurate.ValueType; @@ -54,12 +54,12 @@ public class InheritableConfigHandle extends ConfigHandle< */ private CommentedConfigurationNode mergedNode; - InheritableConfigHandle(final T instance, final @Nullable InheritableConfigHandle parent) { + public InheritableConfigHandle(final T instance, final @Nullable InheritableConfigHandle parent) { super(instance); this.parent = parent; } - InheritableConfigHandle(final T instance, + public InheritableConfigHandle(final T instance, final ConfigurationLoader loader, final @Nullable InheritableConfigHandle parent) { super(instance, loader); @@ -97,7 +97,7 @@ public void load() throws IOException, ObjectMappingException { // make a copy of the file data this.mergedNode = this.node.copy(); } else { - this.mergedNode = SimpleCommentedConfigurationNode.root(SpongeConfigs.OPTIONS); + this.mergedNode = CommentedConfigurationNode.root(SpongeConfigs.OPTIONS); } // merge with settings from parent diff --git a/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java b/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java new file mode 100644 index 00000000000..86211b0fcf3 --- /dev/null +++ b/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java @@ -0,0 +1,169 @@ +/* + * 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.core; + +import ninja.leaping.configurate.ConfigurationOptions; +import ninja.leaping.configurate.hocon.HoconConfigurationLoader; +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.spongepowered.common.config.common.CommonConfig; +import org.spongepowered.common.config.inheritable.GlobalConfig; +import org.spongepowered.common.config.inheritable.WorldConfig; +import org.spongepowered.plugin.PluginEnvironment; +import org.spongepowered.plugin.PluginKeys; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + +/** + * Common utility methods for sponge configurations and necessary helpers for early init. + */ +public class SpongeConfigs { + + public static final String METRICS_NAME = "metrics.conf"; + + 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() + .withHeader(HEADER) + .withShouldCopyDefaults(true); + + static final Logger LOGGER = LogManager.getLogger(); + + private static final Object initLock = new Object(); + private static @MonotonicNonNull PluginEnvironment environment; + private static Path configDir; + + private static ConfigHandle sponge; + private static InheritableConfigHandle global; + + public static void initialize(final PluginEnvironment environment) { + if (SpongeConfigs.environment != null) { + throw new IllegalArgumentException("Cannot initialize SpongeConfigs twice!"); + } + SpongeConfigs.environment = environment; + } + + public static PluginEnvironment getPluginEnvironment() { + if (SpongeConfigs.environment == null) { + throw new IllegalStateException("SpongeConfigs has not yet been initialized with a PluginEnvironment"); + } + return SpongeConfigs.environment; + } + + public static Path getDirectory() { + if (SpongeConfigs.configDir == null) { + SpongeConfigs.configDir = getPluginEnvironment().getBlackboard() + .get(PluginKeys.BASE_DIRECTORY) + .orElseThrow(() -> new IllegalStateException("No base directory was set")) + .resolve("config") + .resolve("sponge"); + } + 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; + } + + + // 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) { + 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); + } + } + + @Deprecated // Only world-specific configurations should be accessed, see SpongeGameConfigs + public 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()); + } + +} diff --git a/src/main/java/org/spongepowered/common/config/inheritable/BaseConfig.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/BaseConfig.java similarity index 98% rename from src/main/java/org/spongepowered/common/config/inheritable/BaseConfig.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/BaseConfig.java index 0e675bff1a3..10cb1f1fa10 100644 --- a/src/main/java/org/spongepowered/common/config/inheritable/BaseConfig.java +++ b/src/prelaunch/java/org/spongepowered/common/config/inheritable/BaseConfig.java @@ -26,7 +26,7 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.transformation.ConfigurationTransformation; -import org.spongepowered.common.config.Config; +import org.spongepowered.common.config.core.Config; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/spongepowered/common/config/inheritable/BlockEntityActivationCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/BlockEntityActivationCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/BlockEntityActivationCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/BlockEntityActivationCategory.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/BlockEntityActivationModCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/BlockEntityActivationModCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/BlockEntityActivationModCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/BlockEntityActivationModCategory.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/CollisionModCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/CollisionModCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/CollisionModCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/CollisionModCategory.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/EntityActivationModCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/EntityActivationModCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/EntityActivationModCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/EntityActivationModCategory.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/EntityActivationRangeCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/EntityActivationRangeCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/EntityActivationRangeCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/EntityActivationRangeCategory.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/EntityCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/EntityCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/EntityCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/EntityCategory.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/EntityCollisionCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/EntityCollisionCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/EntityCollisionCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/EntityCollisionCategory.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/GlobalConfig.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/GlobalConfig.java similarity index 92% rename from src/main/java/org/spongepowered/common/config/inheritable/GlobalConfig.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/GlobalConfig.java index 023b2919598..d84de2839fc 100644 --- a/src/main/java/org/spongepowered/common/config/inheritable/GlobalConfig.java +++ b/src/prelaunch/java/org/spongepowered/common/config/inheritable/GlobalConfig.java @@ -26,10 +26,9 @@ 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.core.FileMovingConfigurationTransformation; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.common.config.common.CommonConfig; -import org.spongepowered.common.config.metrics.MetricsConfiguration; import java.util.Set; @@ -80,7 +79,7 @@ protected ConfigurationTransformation buildInitialToOne() { 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) + SpongeConfigs.createLoader(SpongeConfigs.getDirectory().resolve(SpongeConfigs.METRICS_NAME)), true) ); } } diff --git a/src/main/java/org/spongepowered/common/config/inheritable/LoggingCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/LoggingCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/LoggingCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/LoggingCategory.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/MovementChecksCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/MovementChecksCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/MovementChecksCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/MovementChecksCategory.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/PlayerBlockTracker.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/PlayerBlockTracker.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/PlayerBlockTracker.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/PlayerBlockTracker.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/SpawnerCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/SpawnerCategory.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/SpawnerCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/SpawnerCategory.java diff --git a/src/main/java/org/spongepowered/common/config/inheritable/WorldCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java similarity index 98% rename from src/main/java/org/spongepowered/common/config/inheritable/WorldCategory.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java index 98cd40bd796..f68a5676629 100644 --- a/src/main/java/org/spongepowered/common/config/inheritable/WorldCategory.java +++ b/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java @@ -26,7 +26,6 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; -import org.spongepowered.common.launch.Launcher; import java.util.HashMap; import java.util.Map; @@ -112,7 +111,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 = true; //Launcher.getInstance().isVanilla(); // TODO: figure out how to access this information even earlier + this.denyChunkRequests = true; //Launcher.getInstance().isVanilla(); // TODO: expose this in the plugin environment if necessary } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/org/spongepowered/common/config/inheritable/WorldConfig.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldConfig.java similarity index 100% rename from src/main/java/org/spongepowered/common/config/inheritable/WorldConfig.java rename to src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldConfig.java diff --git a/src/launch/java/org/spongepowered/common/launch/plugin/loader/PluginEngine.java b/src/prelaunch/java/org/spongepowered/common/plugin/loader/PluginEngine.java similarity index 96% rename from src/launch/java/org/spongepowered/common/launch/plugin/loader/PluginEngine.java rename to src/prelaunch/java/org/spongepowered/common/plugin/loader/PluginEngine.java index 588adc0ae6a..cd8860ee313 100644 --- a/src/launch/java/org/spongepowered/common/launch/plugin/loader/PluginEngine.java +++ b/src/prelaunch/java/org/spongepowered/common/plugin/loader/PluginEngine.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.launch.plugin.loader; +package org.spongepowered.common.plugin.loader; import org.spongepowered.plugin.PluginEnvironment; diff --git a/vanilla/src/launch/java/org/spongepowered/vanilla/launch/plugin/loader/VanillaPluginEngine.java b/vanilla/src/launch/java/org/spongepowered/vanilla/launch/plugin/loader/VanillaPluginEngine.java index aed966decdd..04baff84a00 100644 --- a/vanilla/src/launch/java/org/spongepowered/vanilla/launch/plugin/loader/VanillaPluginEngine.java +++ b/vanilla/src/launch/java/org/spongepowered/vanilla/launch/plugin/loader/VanillaPluginEngine.java @@ -25,7 +25,7 @@ package org.spongepowered.vanilla.launch.plugin.loader; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import org.spongepowered.common.launch.plugin.loader.PluginEngine; +import org.spongepowered.common.plugin.loader.PluginEngine; import org.spongepowered.plugin.PluginCandidate; import org.spongepowered.plugin.PluginEnvironment; import org.spongepowered.plugin.PluginLanguageService; 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 31c0c9a07af..2c4653ac90d 100644 --- a/vanilla/src/main/java/org/spongepowered/vanilla/world/VanillaWorldManager.java +++ b/vanilla/src/main/java/org/spongepowered/vanilla/world/VanillaWorldManager.java @@ -67,10 +67,10 @@ 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.InheritableConfigHandle; -import org.spongepowered.common.config.SpongeConfigs; +import org.spongepowered.common.config.core.InheritableConfigHandle; import org.spongepowered.common.accessor.util.registry.SimpleRegistryAccessor; import org.spongepowered.common.accessor.world.dimension.DimensionTypeAccessor; +import org.spongepowered.common.config.SpongeGameConfigs; import org.spongepowered.common.config.inheritable.WorldConfig; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.common.user.SpongeUserManager; @@ -562,7 +562,7 @@ 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); + final InheritableConfigHandle configAdapter = SpongeGameConfigs.createWorld(logicType, key); if (!isDefaultWorld) { if (!configAdapter.get().getWorld().isWorldEnabled()) { MinecraftServerAccessor_Vanilla.accessor$getLogger().warn("World '{}' ({}/{}) has been disabled in the configuration. " 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 bdb5b541d97..20cbff77414 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,7 +37,7 @@ 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.core.ConfigHandle; import org.spongepowered.common.event.tracking.PhaseTracker; import org.spongepowered.vanilla.client.VanillaClient; 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 bcc49d9b443..7ec0dff088a 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,7 +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.common.config.core.ConfigHandle; import org.spongepowered.vanilla.VanillaServer; import java.io.File; 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 c032dcca558..651be09a147 100644 --- a/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/Main.java +++ b/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/Main.java @@ -31,6 +31,7 @@ import joptsimple.util.PathConverter; import joptsimple.util.PathProperties; import org.spongepowered.vanilla.launch.plugin.loader.VanillaPluginEngine; +import org.spongepowered.common.config.core.SpongeConfigs; import org.spongepowered.vanilla.modlauncher.util.ArgumentList; import org.spongepowered.plugin.PluginEnvironment; import org.spongepowered.plugin.PluginKeys; @@ -56,8 +57,6 @@ public static void main(final String[] args) throws IOException { final PluginEnvironment pluginEnvironment = new PluginEnvironment(); pluginEnvironment.getBlackboard().getOrCreate(PluginKeys.VERSION, () -> implementationVersion == null ? "dev" : implementationVersion); 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); @@ -65,6 +64,7 @@ public static void main(final String[] args) throws IOException { // TODO Read in plugin directories from CLI/Config pluginEnvironment.getBlackboard().getOrCreate(PluginKeys.PLUGIN_DIRECTORIES, () -> Arrays.asList(modsDirectory, gameDirectory.resolve("plugins"))); + SpongeConfigs.initialize(pluginEnvironment); Main.pluginEngine = new VanillaPluginEngine(pluginEnvironment); final ArgumentList lst = ArgumentList.from(args); diff --git a/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/bootstrap/AbstractVanillaLaunchHandler.java b/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/bootstrap/AbstractVanillaLaunchHandler.java index cb6ce4ef131..e3f10f001aa 100644 --- a/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/bootstrap/AbstractVanillaLaunchHandler.java +++ b/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/bootstrap/AbstractVanillaLaunchHandler.java @@ -67,8 +67,20 @@ public abstract class AbstractVanillaLaunchHandler implements ILaunchHandlerServ * be to exclude {@code "org.neptune."}. */ protected static final List EXCLUDED_PACKAGES = Arrays.asList( + // Configs + "org.spongepowered.common.config.core.", + "org.spongepowered.common.config.common.", + "org.spongepowered.common.config.inheritable.", + // configurate 3 + "com.google.common.reflect.TypeToken", + "ninja.leaping.configurate.", + // configurate 4 (coming soon) + "io.leangen.geantyref.", + "org.spongepowered.configurate.", + + // Plugin loading "org.spongepowered.plugin.", - "org.spongepowered.common.launch.plugin.loader.", + "org.spongepowered.common.plugin.loader.", "org.spongepowered.vanilla.launch.plugin.loader." ); From 54231ab838610e8256853dec1d27da033c544784 Mon Sep 17 00:00:00 2001 From: Zach Levis Date: Sat, 22 Aug 2020 14:41:36 -0700 Subject: [PATCH 2/4] config: Correctly parse tokens for config dir and plugin dir --- .../spongepowered/common/SpongeCommon.java | 3 +- .../common/config/common/GeneralCategory.java | 34 ++-- .../common/config/core/SpongeConfigs.java | 3 +- .../config/core/TokenHoldingString.java | 147 ++++++++++++++++++ 4 files changed, 172 insertions(+), 15 deletions(-) create mode 100644 src/prelaunch/java/org/spongepowered/common/config/core/TokenHoldingString.java diff --git a/src/main/java/org/spongepowered/common/SpongeCommon.java b/src/main/java/org/spongepowered/common/SpongeCommon.java index 9e67c5ab831..490a23e0152 100644 --- a/src/main/java/org/spongepowered/common/SpongeCommon.java +++ b/src/main/java/org/spongepowered/common/SpongeCommon.java @@ -45,6 +45,7 @@ import javax.annotation.Nullable; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; @Singleton @@ -106,7 +107,7 @@ public static Path getGameDirectory() { } public static Path getPluginConfigDirectory() { - return SpongeCommon.getGameDirectory().resolve(SpongeConfigs.getCommon().get().getGeneral().configDir()); + return Paths.get(SpongeConfigs.getCommon().get().getGeneral().configDir()); } public static Path getSpongeConfigDirectory() { diff --git a/src/prelaunch/java/org/spongepowered/common/config/common/GeneralCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/GeneralCategory.java index e914c6c9623..d8d1997c507 100644 --- a/src/prelaunch/java/org/spongepowered/common/config/common/GeneralCategory.java +++ b/src/prelaunch/java/org/spongepowered/common/config/common/GeneralCategory.java @@ -27,9 +27,21 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.spongepowered.common.config.core.SpongeConfigs; +import org.spongepowered.common.config.core.TokenHoldingString; +import org.spongepowered.plugin.Blackboard; import org.spongepowered.plugin.PluginEnvironment; import org.spongepowered.plugin.PluginKeys; +import java.nio.file.Path; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + @ConfigSerializable public class GeneralCategory { @@ -42,7 +54,7 @@ public class GeneralCategory { + "is going to search for a plugins folder in the mods directory. \n" + "If you wish for the plugins folder to reside in the root game \n" + "directory, change the value to \"${CANONICAL_GAME_DIR}/plugins\".") - private String pluginsDir = "${CANONICAL_MODS_DIR}/plugins"; + private TokenHoldingString pluginsDir = TokenHoldingString.of("${CANONICAL_MODS_DIR}/plugins"); @Setting(value = "config-dir", comment = "The directory for Sponge plugin configurations, relative to the \n" + "execution root or specified as an absolute path. \n" + "Note that the default: \"${CANONICAL_GAME_DIR}/config\" \n" @@ -51,30 +63,26 @@ public class GeneralCategory { + "directory, change the value to, for example, \"${CANONICAL_CONFIG_DIR}/sponge/plugins\". \n" + "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"; + private TokenHoldingString configDir = TokenHoldingString.of("${CANONICAL_GAME_DIR}/config"); public boolean getFileIoThreadSleep() { return this.fileIOThreadSleep; } public String pluginsDir() { - return this.pluginsDir; + return this.pluginsDir.getParsed(); } - public void setPluginsDir(String pluginsDir) { - this.pluginsDir = pluginsDir; + public void setPluginsDir(final String pluginsDir) { + this.pluginsDir = TokenHoldingString.of(pluginsDir); } public String configDir() { - return this.configDir; + return this.configDir.getParsed(); } - public void setConfigDir(String configDir) { - this.configDir = configDir; - } - private static String parsePlaceholders(final String input) { - final PluginEnvironment env = SpongeConfigs.getPluginEnvironment(); - env.getBlackboard().get(PluginKeys.PLUGIN_DIRECTORIES); - return input; + public void setConfigDir(final String configDir) { + this.configDir = TokenHoldingString.of(configDir); } + } diff --git a/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java b/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java index 86211b0fcf3..329983bb5d6 100644 --- a/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java +++ b/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java @@ -56,7 +56,8 @@ public class SpongeConfigs { static final ConfigurationOptions OPTIONS = ConfigurationOptions.defaults() .withHeader(HEADER) - .withShouldCopyDefaults(true); + .withShouldCopyDefaults(true) + .withSerializers(collection -> collection.register(TokenHoldingString.SERIALIZER)); static final Logger LOGGER = LogManager.getLogger(); diff --git a/src/prelaunch/java/org/spongepowered/common/config/core/TokenHoldingString.java b/src/prelaunch/java/org/spongepowered/common/config/core/TokenHoldingString.java new file mode 100644 index 00000000000..18086179d74 --- /dev/null +++ b/src/prelaunch/java/org/spongepowered/common/config/core/TokenHoldingString.java @@ -0,0 +1,147 @@ +/* + * 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.core; + +import com.google.common.reflect.TypeToken; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; +import ninja.leaping.configurate.objectmapping.serialize.ScalarSerializer; +import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; +import org.spongepowered.plugin.Blackboard; +import org.spongepowered.plugin.PluginEnvironment; +import org.spongepowered.plugin.PluginKeys; + +import java.nio.file.Path; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Holder for a string value that is parsed for environment variables. + */ +public class TokenHoldingString { + + static final ScalarSerializer SERIALIZER = new Serializer(); + + private static final Pattern TOKEN_MATCH = Pattern.compile("\\$\\{([^}]+)}"); + + private static final Map> TOKENS = new HashMap<>(); + + static { + TokenHoldingString.register("CANONICAL_GAME_DIR", PluginKeys.BASE_DIRECTORY); + TokenHoldingString.register("CANONICAL_MODS_DIR", env -> { + // TODO: this is wrong, need to decide what configurability will be provided. + final List directories = env.getBlackboard().get(PluginKeys.PLUGIN_DIRECTORIES).orElse(Collections.emptyList()); + return directories.isEmpty() ? null : directories.get(0).toString(); + }); + } + + /** + * Create and parse a string. + * + * @param input Input value maybe with tokens + * @return holder + */ + public static TokenHoldingString of(final String input) { + return new TokenHoldingString(input, TokenHoldingString.parsePlaceholders(input)); + } + + private static void register(final String token, final Blackboard.Key getter) { + register(token, env -> { + final Object value = env.getBlackboard().get(getter).orElse(null); + return value == null ? null : value.toString(); + }); + } + + private static void register(final String token, final Function getter) { + TOKENS.put(token.toLowerCase(Locale.ROOT), getter); + } + + /** + * Parse an environment variable-style placeholder syntax. + * + *

Variable names are case-insensitive, and detected with the + * {@link #TOKEN_MATCH} expression.

+ * + * @param input input string + * @return string with placeholders replaced + */ + private static String parsePlaceholders(final String input) { + final PluginEnvironment env = SpongeConfigs.getPluginEnvironment(); + final Matcher matcher = TOKEN_MATCH.matcher(input); + if (!matcher.find()) { + return input; + } + final StringBuffer result = new StringBuffer(); + do { + final String token = matcher.group(1); + final Function replacer = TOKENS.get(token.toLowerCase()); + final String replaced = replacer == null ? "" : replacer.apply(env); + matcher.appendReplacement(result, replaced == null ? "" : replaced); + } while (matcher.find()); + matcher.appendTail(result); + return result.toString(); + } + + private final String plainValue; + private final String parsedValue; + + private TokenHoldingString(final String plain, final String parsed) { + this.plainValue = plain; + this.parsedValue = parsed; + } + + public String getPlain() { + return this.plainValue; + } + + public String getParsed() { + return this.parsedValue; + } + + static class Serializer extends ScalarSerializer { + + Serializer() { + super(TokenHoldingString.class); + } + + @Override + public TokenHoldingString deserialize(TypeToken type, Object obj) throws ObjectMappingException { + return TokenHoldingString.of(obj.toString()); + } + + @Override + public Object serialize(TokenHoldingString item, Predicate> typeSupported) { + return item.getPlain(); + } + + } + +} From 8d73fab8becdab86593d4d0dc4d34c8b594f6cfe Mon Sep 17 00:00:00 2001 From: Zach Levis Date: Sat, 22 Aug 2020 15:15:56 -0700 Subject: [PATCH 3/4] config: Add a vanilla environment key --- .../common/config/common/OptimizationCategory.java | 4 +++- .../common/config/common/PhaseTrackerCategory.java | 3 ++- .../org/spongepowered/common/config/core/SpongeConfigs.java | 3 +++ .../common/config/inheritable/WorldCategory.java | 3 ++- .../java/org/spongepowered/vanilla/modlauncher/Main.java | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/prelaunch/java/org/spongepowered/common/config/common/OptimizationCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/OptimizationCategory.java index 4ecd467deec..f588d5cbd69 100644 --- a/src/prelaunch/java/org/spongepowered/common/config/common/OptimizationCategory.java +++ b/src/prelaunch/java/org/spongepowered/common/config/common/OptimizationCategory.java @@ -26,6 +26,8 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; +import org.spongepowered.common.config.core.SpongeConfigs; +import org.spongepowered.plugin.PluginEnvironment; @ConfigSerializable public class OptimizationCategory { @@ -121,7 +123,7 @@ public class OptimizationCategory { 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 = true; //Launcher.getInstance().isVanilla(); // TODO: expose this in the PluginEnvironment if necessary + this.preItemDropMerge = SpongeConfigs.getPluginEnvironment().getBlackboard().get(SpongeConfigs.IS_VANILLA_PLATFORM).orElse(true); } diff --git a/src/prelaunch/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java b/src/prelaunch/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java index 5e9af31f1ee..c3144962975 100644 --- a/src/prelaunch/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java +++ b/src/prelaunch/java/org/spongepowered/common/config/common/PhaseTrackerCategory.java @@ -26,6 +26,7 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; +import org.spongepowered.common.config.core.SpongeConfigs; import java.util.HashMap; import java.util.Map; @@ -177,7 +178,7 @@ public Map getAutoFixedTiles() { } private boolean isVanilla() { - return true; //Launcher.getInstance().isVanilla(); // TODO: expose this in the PluginEnvironment if necessary + return SpongeConfigs.getPluginEnvironment().getBlackboard().get(SpongeConfigs.IS_VANILLA_PLATFORM).orElse(true); } public void setAutoFixedTiles(Map autoFixedTiles) { diff --git a/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java b/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java index 329983bb5d6..ce55d06be2e 100644 --- a/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java +++ b/src/prelaunch/java/org/spongepowered/common/config/core/SpongeConfigs.java @@ -33,6 +33,7 @@ import org.spongepowered.common.config.common.CommonConfig; import org.spongepowered.common.config.inheritable.GlobalConfig; import org.spongepowered.common.config.inheritable.WorldConfig; +import org.spongepowered.plugin.Blackboard; import org.spongepowered.plugin.PluginEnvironment; import org.spongepowered.plugin.PluginKeys; @@ -45,6 +46,8 @@ */ public class SpongeConfigs { + public static final Blackboard.Key IS_VANILLA_PLATFORM = Blackboard.Key.of("is_vanilla", Boolean.class); + public static final String METRICS_NAME = "metrics.conf"; static final String HEADER = "\n" diff --git a/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java index f68a5676629..e94636cda72 100644 --- a/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java +++ b/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java @@ -26,6 +26,7 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; +import org.spongepowered.common.config.core.SpongeConfigs; import java.util.HashMap; import java.util.Map; @@ -111,7 +112,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 = true; //Launcher.getInstance().isVanilla(); // TODO: expose this in the plugin environment if necessary + this.denyChunkRequests = SpongeConfigs.getPluginEnvironment().getBlackboard().get(SpongeConfigs.IS_VANILLA_PLATFORM).orElse(true); } catch (Exception e) { e.printStackTrace(); } 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 651be09a147..799a5683fe9 100644 --- a/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/Main.java +++ b/vanilla/src/modlauncher/java/org/spongepowered/vanilla/modlauncher/Main.java @@ -63,6 +63,7 @@ public static void main(final String[] args) throws IOException { } // TODO Read in plugin directories from CLI/Config pluginEnvironment.getBlackboard().getOrCreate(PluginKeys.PLUGIN_DIRECTORIES, () -> Arrays.asList(modsDirectory, gameDirectory.resolve("plugins"))); + pluginEnvironment.getBlackboard().getOrCreate(SpongeConfigs.IS_VANILLA_PLATFORM, () -> true); SpongeConfigs.initialize(pluginEnvironment); Main.pluginEngine = new VanillaPluginEngine(pluginEnvironment); From 104f49327076910345842b1a31eb6b15057881b9 Mon Sep 17 00:00:00 2001 From: Zach Levis Date: Sat, 22 Aug 2020 16:04:22 -0700 Subject: [PATCH 4/4] config: Add new version for portal agent change --- .../common/config/inheritable/BaseConfig.java | 12 +++++++++++- .../common/config/inheritable/WorldCategory.java | 3 --- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/prelaunch/java/org/spongepowered/common/config/inheritable/BaseConfig.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/BaseConfig.java index 10cb1f1fa10..0affbb11601 100644 --- a/src/prelaunch/java/org/spongepowered/common/config/inheritable/BaseConfig.java +++ b/src/prelaunch/java/org/spongepowered/common/config/inheritable/BaseConfig.java @@ -98,8 +98,18 @@ public MovementChecksCategory getMovementChecks() { @Override public ConfigurationTransformation getTransformation() { return ConfigurationTransformation.versionedBuilder() + .addVersion(2, this.buildOneToTwo()) // move everything out of sponge subcategory - .addVersion(1, buildInitialToOne()) + .addVersion(1, this.buildInitialToOne()) + .build(); + } + + protected ConfigurationTransformation buildOneToTwo() { + return ConfigurationTransformation.builder() + .addAction(new Object[] { "world", "portal-agents" }, (path, value) -> { + value.setValue(null); + return null; + }) .build(); } diff --git a/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java b/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java index e94636cda72..0b23c582855 100644 --- a/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java +++ b/src/prelaunch/java/org/spongepowered/common/config/inheritable/WorldCategory.java @@ -28,9 +28,6 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.spongepowered.common.config.core.SpongeConfigs; -import java.util.HashMap; -import java.util.Map; - @ConfigSerializable public class WorldCategory {