Improves config.yml reading and saving.

Can handle lower-case game mode naming.

May help https://github.com/BentoBoxWorld/Greenhouses/issues/64
This commit is contained in:
tastybento 2020-09-24 11:56:00 -07:00
parent 26ef3d3a24
commit 25277a09c7
1 changed files with 14 additions and 9 deletions

View File

@ -63,20 +63,28 @@ public class Greenhouses extends Addon {
recipes = new RecipeManager(this); recipes = new RecipeManager(this);
// Load manager // Load manager
manager = new GreenhouseManager(this); manager = new GreenhouseManager(this);
// Clear
this.activeWorlds.clear();
// Register commands for // Register commands for
getPlugin().getAddonsManager().getGameModeAddons().stream() getPlugin().getAddonsManager().getGameModeAddons().stream()
.filter(gm -> settings.getGameModes().contains(gm.getDescription().getName())) .filter(gm -> settings.getGameModes().stream().anyMatch(gm.getDescription().getName()::equalsIgnoreCase))
.forEach(gm -> { .forEach(gm -> {
// Register command // Register command
gm.getPlayerCommand().ifPresent(playerCmd -> new UserCommand(this, playerCmd)); gm.getPlayerCommand().ifPresent(playerCmd -> new UserCommand(this, playerCmd));
// Log
this.log("Hooking into " + gm.getDescription().getName());
// Store active world // Store active world
activeWorlds.add(gm.getOverWorld()); activeWorlds.add(gm.getOverWorld());
}); });
// Register greenhouse manager if (this.activeWorlds.isEmpty()) {
this.registerListener(manager); this.logError("Greenhouses could not hook into any game modes! Check config.yml");
// Register protection flag with BentoBox this.setState(State.DISABLED);
getPlugin().getFlagsManager().registerFlag(this, GREENHOUSES); } else {
// Register greenhouse manager
this.registerListener(manager);
// Register protection flag with BentoBox
getPlugin().getFlagsManager().registerFlag(this, GREENHOUSES);
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -88,9 +96,6 @@ public class Greenhouses extends Addon {
manager.saveGreenhouses(); manager.saveGreenhouses();
if (manager.getEcoMgr() != null) manager.getEcoMgr().cancel(); if (manager.getEcoMgr() != null) manager.getEcoMgr().cancel();
} }
if (settings != null) {
new Config<>(this, Settings.class).saveConfigObject(settings);
}
} }
/** /**