Greenhouses/src/main/java/world/bentobox/greenhouses/Greenhouses.java

102 lines
2.9 KiB
Java
Raw Normal View History

2019-01-19 16:52:04 +01:00
package world.bentobox.greenhouses;
import java.util.ArrayList;
import java.util.List;
2019-01-26 20:10:30 +01:00
import org.bukkit.Material;
2019-01-19 16:52:04 +01:00
import org.bukkit.World;
import world.bentobox.bentobox.api.addons.Addon;
2019-01-22 00:44:01 +01:00
import world.bentobox.bentobox.api.configuration.Config;
2019-01-26 20:10:30 +01:00
import world.bentobox.bentobox.api.flags.Flag;
2019-01-22 00:44:01 +01:00
import world.bentobox.greenhouses.managers.GreenhouseManager;
import world.bentobox.greenhouses.managers.RecipeManager;
import world.bentobox.greenhouses.ui.user.UserCommand;
2019-01-19 16:52:04 +01:00
/**
* @author tastybento
2019-01-22 00:44:01 +01:00
*
2019-01-19 16:52:04 +01:00
*/
public class Greenhouses extends Addon {
2019-01-22 00:44:01 +01:00
private GreenhouseManager manager;
private Settings settings;
private RecipeManager recipes;
2019-01-26 17:38:13 +01:00
private final List<World> activeWorlds = new ArrayList<>();
2019-01-26 20:10:30 +01:00
public final static Flag GREENHOUSES = new Flag.Builder("GREENHOUSE", Material.GREEN_STAINED_GLASS).build();
2019-01-19 16:52:04 +01:00
2019-01-22 00:44:01 +01:00
/* (non-Javadoc)
* @see world.bentobox.bentobox.api.addons.Addon#onEnable()
2019-01-19 16:52:04 +01:00
*/
@Override
public void onEnable() {
saveDefaultConfig();
2019-01-22 00:44:01 +01:00
this.saveResource("biomes.yml", false);
settings = new Config<>(this, Settings.class).loadConfigObject();
if (settings == null) {
// Settings did no load correctly. Disable.
logError("Settings did not load correctly - disabling Greenhouses - please check config.yml");
this.setState(State.DISABLED);
return;
2019-01-19 16:52:04 +01:00
}
2019-01-22 00:44:01 +01:00
// Load recipes
recipes = new RecipeManager(this);
// Load manager
manager = new GreenhouseManager(this);
2019-07-08 00:45:47 +02:00
// Register commands for
2019-01-22 00:44:01 +01:00
getPlugin().getAddonsManager().getGameModeAddons().stream()
2019-01-26 20:10:30 +01:00
.filter(gm -> settings.getGameModes().contains(gm.getDescription().getName()))
2019-01-22 00:44:01 +01:00
.forEach(gm -> {
// Register command
gm.getPlayerCommand().ifPresent(playerCmd -> new UserCommand(this, playerCmd));
// Store active world
activeWorlds.add(gm.getOverWorld());
2019-01-19 16:52:04 +01:00
});
2019-01-26 20:10:30 +01:00
// Register greenhouse manager
this.registerListener(manager);
2019-01-26 20:10:30 +01:00
// Register protection flag with BentoBox
getPlugin().getFlagsManager().registerFlag(GREENHOUSES);
2019-01-19 16:52:04 +01:00
}
2019-01-22 00:44:01 +01:00
/* (non-Javadoc)
* @see world.bentobox.bentobox.api.addons.Addon#onDisable()
2019-01-19 16:52:04 +01:00
*/
2019-01-22 00:44:01 +01:00
@Override
public void onDisable() {
if (manager != null) {
manager.saveGreenhouses();
2019-07-08 00:45:47 +02:00
manager.getEcoMgr().cancel();
2019-01-19 16:52:04 +01:00
}
2019-01-26 20:10:30 +01:00
if (settings != null) {
new Config<>(this, Settings.class).saveConfigObject(settings);
}
2019-01-19 16:52:04 +01:00
}
/**
2019-01-22 00:44:01 +01:00
* @return the manager
2019-01-19 16:52:04 +01:00
*/
2019-01-22 00:44:01 +01:00
public GreenhouseManager getManager() {
return manager;
2019-01-19 16:52:04 +01:00
}
/**
2019-01-22 00:44:01 +01:00
* @return Settings
2019-01-19 16:52:04 +01:00
*/
2019-01-22 00:44:01 +01:00
public Settings getSettings() {
return settings;
2019-01-19 16:52:04 +01:00
}
/**
2019-01-22 00:44:01 +01:00
* @return the recipes
2019-01-19 16:52:04 +01:00
*/
2019-01-22 00:44:01 +01:00
public RecipeManager getRecipes() {
return recipes;
2019-01-19 16:52:04 +01:00
}
2019-01-22 00:44:01 +01:00
public List<World> getActiveWorlds() {
return activeWorlds;
2019-01-19 16:52:04 +01:00
}
}