2018-12-30 14:31:26 +01:00
|
|
|
package world.bentobox.challenges;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
2019-01-10 10:36:06 +01:00
|
|
|
import world.bentobox.bentobox.api.configuration.Config;
|
2018-12-30 14:31:26 +01:00
|
|
|
import world.bentobox.challenges.commands.ChallengesCommand;
|
|
|
|
import world.bentobox.challenges.commands.admin.Challenges;
|
|
|
|
import world.bentobox.challenges.listeners.ResetListener;
|
|
|
|
import world.bentobox.challenges.listeners.SaveListener;
|
|
|
|
import world.bentobox.bentobox.api.addons.Addon;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add-on to BSkyBlock that enables challenges
|
|
|
|
* @author tastybento
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ChallengesAddon extends Addon {
|
|
|
|
|
2019-01-10 10:36:06 +01:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Variables
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
private ChallengesManager challengesManager;
|
2019-01-10 10:36:06 +01:00
|
|
|
|
2019-01-10 10:16:04 +01:00
|
|
|
private ChallengesImportManager importManager;
|
2019-01-10 10:36:06 +01:00
|
|
|
|
|
|
|
private Settings settings;
|
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
private boolean hooked;
|
|
|
|
|
2019-01-10 10:36:06 +01:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Constants
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Permission prefix for addon.
|
|
|
|
*/
|
|
|
|
private static final String PERMISSION_PREFIX = "addon";
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Methods
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2018-12-30 14:31:26 +01:00
|
|
|
@Override
|
|
|
|
public void onLoad() {
|
|
|
|
// Save default config.yml
|
2019-01-10 10:36:06 +01:00
|
|
|
this.saveDefaultConfig();
|
|
|
|
// Load the plugin's config
|
|
|
|
this.loadSettings();
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 10:36:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2018-12-30 14:31:26 +01:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
|
|
|
// Check if it is enabled - it might be loaded, but not enabled.
|
2019-01-10 10:36:06 +01:00
|
|
|
if (this.getPlugin() == null || !this.getPlugin().isEnabled()) {
|
2018-12-30 14:31:26 +01:00
|
|
|
Bukkit.getLogger().severe("BentoBox is not available or disabled!");
|
|
|
|
this.setState(State.DISABLED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Challenges Manager
|
2019-01-10 10:36:06 +01:00
|
|
|
this.challengesManager = new ChallengesManager(this);
|
2018-12-30 14:31:26 +01:00
|
|
|
// Challenge import setup
|
2019-01-10 10:36:06 +01:00
|
|
|
this.importManager = new ChallengesImportManager(this);
|
|
|
|
|
2019-01-23 19:19:18 +01:00
|
|
|
this.getPlugin().getAddonsManager().getGameModeAddons().forEach(gameModeAddon -> {
|
|
|
|
if (!this.settings.getDisabledGameModes().contains(gameModeAddon.getDescription().getName()))
|
|
|
|
{
|
|
|
|
if (gameModeAddon.getPlayerCommand().isPresent())
|
|
|
|
{
|
|
|
|
new ChallengesCommand(this, gameModeAddon.getPlayerCommand().get());
|
|
|
|
this.hooked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gameModeAddon.getAdminCommand().isPresent())
|
|
|
|
{
|
|
|
|
new Challenges(this, gameModeAddon.getAdminCommand().get());
|
|
|
|
this.hooked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2019-01-10 10:36:06 +01:00
|
|
|
|
|
|
|
if (this.hooked) {
|
|
|
|
// Try to find Level addon and if it does not exist, display a warning
|
|
|
|
if (!this.getAddonByName("Level").isPresent()) {
|
|
|
|
this.logWarning("Level add-on not found so level challenges will not work!");
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
2019-01-10 10:36:06 +01:00
|
|
|
|
|
|
|
// Register the reset listener
|
|
|
|
this.registerListener(new ResetListener(this));
|
|
|
|
// Register the autosave listener.
|
|
|
|
this.registerListener(new SaveListener(this));
|
|
|
|
} else {
|
|
|
|
this.logError("Challenges could not hook into AcidIsland or BSkyBlock so will not do anything!");
|
2018-12-30 14:31:26 +01:00
|
|
|
this.setState(State.DISABLED);
|
|
|
|
}
|
2019-01-10 10:36:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onReload()
|
|
|
|
{
|
|
|
|
if (this.hooked) {
|
|
|
|
this.challengesManager.save();
|
|
|
|
|
|
|
|
this.loadSettings();
|
|
|
|
this.getLogger().info("Challenges addon reloaded.");
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 10:36:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2018-12-30 14:31:26 +01:00
|
|
|
@Override
|
2019-01-10 10:36:06 +01:00
|
|
|
public void onDisable() {
|
|
|
|
if (this.hooked) {
|
|
|
|
this.challengesManager.save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method loads addon configuration settings in memory.
|
|
|
|
*/
|
|
|
|
private void loadSettings() {
|
|
|
|
this.settings = new Config<>(this, Settings.class).loadConfigObject();
|
|
|
|
|
|
|
|
if (this.settings == null) {
|
|
|
|
// Disable
|
|
|
|
this.logError("Challenges settings could not load! Addon disabled.");
|
|
|
|
this.setState(State.DISABLED);
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 10:36:06 +01:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Getters
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return challengesManager
|
|
|
|
*/
|
2018-12-30 14:31:26 +01:00
|
|
|
public ChallengesManager getChallengesManager() {
|
2019-01-10 10:36:06 +01:00
|
|
|
return this.challengesManager;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 10:36:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Permission Prefix.
|
|
|
|
*/
|
2018-12-30 14:31:26 +01:00
|
|
|
@Override
|
|
|
|
public String getPermissionPrefix() {
|
2019-01-10 10:36:06 +01:00
|
|
|
return PERMISSION_PREFIX;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 10:36:06 +01:00
|
|
|
|
2018-12-30 14:31:26 +01:00
|
|
|
/**
|
|
|
|
* @return the importManager
|
|
|
|
*/
|
2019-01-10 10:16:04 +01:00
|
|
|
public ChallengesImportManager getImportManager() {
|
2019-01-10 10:36:06 +01:00
|
|
|
return this.importManager;
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 10:36:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the challenge settings.
|
|
|
|
*/
|
|
|
|
public Settings getChallengesSettings()
|
|
|
|
{
|
|
|
|
return this.settings;
|
|
|
|
}
|
2018-12-30 14:31:26 +01:00
|
|
|
}
|