Fix config tests

This commit is contained in:
Ben Woo 2023-08-31 14:14:55 +08:00
parent 4ff1663353
commit 55b21bf17e
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
3 changed files with 8 additions and 10 deletions

View File

@ -54,7 +54,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
private ServiceLocator serviceLocator;
@Inject
private MVCoreConfig config;
private Provider<MVCoreConfig> configProvider;
@Inject
private Provider<MVWorldManager> worldManagerProvider;
@Inject
@ -101,7 +101,8 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
initializeDependencyInjection();
// Load our configs first as we need them for everything else.
if (config == null || !config.isLoaded()) {
var config = configProvider.get();
if (!config.isLoaded()) {
Logging.severe("Your configs were not loaded.");
Logging.severe("Please check your configs and restart the server.");
this.getServer().getPluginManager().disablePlugin(this);
@ -169,7 +170,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
}
private boolean shouldShowConfig() {
return !config.getSilentStart();
return !configProvider.get().getSilentStart();
}
private void loadEconomist() {
@ -273,14 +274,14 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
private void logEnableMessage() {
Logging.config("Version %s (API v%s) Enabled - By %s", this.getDescription().getVersion(), PROTOCOL, getAuthors());
if (config.isShowingDonateMessage()) {
if (configProvider.get().isShowingDonateMessage()) {
Logging.config("Help dumptruckman keep this project alive. Become a patron! https://www.patreon.com/dumptruckman");
Logging.config("One time donations are also appreciated: https://www.paypal.me/dumptruckman");
}
}
private void loadPlaceholderAPIIntegration() {
if (config.isRegisterPapiHook()
if (configProvider.get().isRegisterPapiHook()
&& getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
Try.run(() -> serviceLocator.createAndInitialize(MultiverseCorePlaceholders.class))
.onFailure(e -> {
@ -365,7 +366,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
*/
@Override
public boolean saveAllConfigs() {
return config.save()
return configProvider.get().save()
&& worldManagerProvider.get().saveWorldsConfig()
&& anchorManagerProvider.get().saveAnchors();
}

View File

@ -107,9 +107,6 @@ abstract class FileConfigHandle<C extends FileConfiguration> extends GenericConf
public static abstract class Builder<C extends FileConfiguration, B extends Builder<C, B>> extends GenericConfigHandle.Builder<C, B> {
protected @NotNull Path configPath;
protected @Nullable Logger logger;
protected @Nullable NodeGroup nodes;
protected @Nullable ConfigMigrator migrator;
protected Builder(@NotNull Path configPath) {
this.configPath = configPath;

View File

@ -39,7 +39,7 @@ class ConfigTest : TestWithMockBukkit() {
fun `Old config is migrated`() {
val oldConfig = getResourceAsText("/old_config.yml")
assertNotNull(oldConfig)
File(Path.of(multiverseCore.dataFolder.absolutePath, "config.yml").absolutePathString()).writeText(oldConfig)
multiverseCore.dataFolder.toPath().resolve("config.yml").toFile().writeText(oldConfig)
assertTrue(config.load())
assertTrue(config.save())