Skip to content

Commit

Permalink
Improves config.yml reading and saving.
Browse files Browse the repository at this point in the history
Can handle lower-case game mode naming.

May help #64
  • Loading branch information
tastybento committed Sep 24, 2020
1 parent 26ef3d3 commit 25277a0
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/main/java/world/bentobox/greenhouses/Greenhouses.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,28 @@ public void onEnable() {
recipes = new RecipeManager(this);
// Load manager
manager = new GreenhouseManager(this);
// Clear
this.activeWorlds.clear();
// Register commands for
getPlugin().getAddonsManager().getGameModeAddons().stream()
.filter(gm -> settings.getGameModes().contains(gm.getDescription().getName()))
.filter(gm -> settings.getGameModes().stream().anyMatch(gm.getDescription().getName()::equalsIgnoreCase))
.forEach(gm -> {
// Register command
gm.getPlayerCommand().ifPresent(playerCmd -> new UserCommand(this, playerCmd));
// Log
this.log("Hooking into " + gm.getDescription().getName());
// Store active world
activeWorlds.add(gm.getOverWorld());
});
// Register greenhouse manager
this.registerListener(manager);
// Register protection flag with BentoBox
getPlugin().getFlagsManager().registerFlag(this, GREENHOUSES);

if (this.activeWorlds.isEmpty()) {
this.logError("Greenhouses could not hook into any game modes! Check config.yml");
this.setState(State.DISABLED);
} else {
// Register greenhouse manager
this.registerListener(manager);
// Register protection flag with BentoBox
getPlugin().getFlagsManager().registerFlag(this, GREENHOUSES);
}
}

/* (non-Javadoc)
Expand All @@ -88,9 +96,6 @@ public void onDisable() {
manager.saveGreenhouses();
if (manager.getEcoMgr() != null) manager.getEcoMgr().cancel();
}
if (settings != null) {
new Config<>(this, Settings.class).saveConfigObject(settings);
}
}

/**
Expand Down

0 comments on commit 25277a0

Please sign in to comment.