Skip to content

Commit

Permalink
Add new variable "hook" that indicate if Biomes finds bSkyBlock or Ac…
Browse files Browse the repository at this point in the history
…idIsland addons.

This allows to disable addon, if it is not necessary.
Add maven dependency to bSkyBlock and AcidIsland, so it would be easier to get their commands.
  • Loading branch information
BONNe committed Jan 8, 2019
1 parent ce0d390 commit 711e3e8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 38 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bskyblock</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>acidisland</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui</artifactId>
Expand Down
92 changes: 54 additions & 38 deletions src/main/java/world/bentobox/biomes/BiomesAddon.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package world.bentobox.biomes;


import world.bentobox.acidisland.AcidIsland;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.biomes.commands.admin.AdminCommand;
import world.bentobox.biomes.commands.user.BiomesCommand;
import world.bentobox.biomes.listeners.ChangeOwnerListener;
import world.bentobox.biomes.objects.Settings;
import world.bentobox.bskyblock.BSkyBlock;


/**
Expand All @@ -29,87 +30,96 @@ public void onLoad()
@Override
public void onEnable()
{
this.hooked = false;
this.addonManager = new BiomesAddonManager(this);

CommandsManager commandsManager = this.getPlugin().getCommandsManager();

this.getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent(a -> {
CompositeCommand acidIslandCmd =
commandsManager.getCommand(this.getConfig().getString("acidisland.user-command", "ai"));
this.getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent(addon -> {
AcidIsland acidIsland = (AcidIsland) addon;

if (acidIslandCmd != null)
{
new BiomesCommand(this, acidIslandCmd);

CompositeCommand acidCmd =
commandsManager.getCommand(this.getConfig().getString("acidisland.admin-command", "acid"));

new AdminCommand(this, acidCmd);
}
new AdminCommand(this,
commandsManager.getCommand(acidIsland.getSettings().getAdminCommand()));
new BiomesCommand(this,
commandsManager.getCommand(acidIsland.getSettings().getIslandCommand()));

// Probably better would be casting and getting from settings, but then it should be added as
// dependency.
String currentWorld = a.getConfig().getString("world.world-name");
String currentWorld = acidIsland.getWorldSettings().getWorldName();

if (this.addonManager.getBiomes(currentWorld).isEmpty())
{
this.addonManager.importBiomes(currentWorld);
}

this.hooked = true;
});

// BSkyBlock hook in
this.getPlugin().getAddonsManager().getAddonByName("BSkyBlock").ifPresent(a -> {
CompositeCommand bsbIslandCmd =
commandsManager.getCommand(this.getConfig().getString("bskyblock.user-command", "island"));

if (bsbIslandCmd != null)
{
new BiomesCommand(this, bsbIslandCmd);
this.getPlugin().getAddonsManager().getAddonByName("BSkyBlock").ifPresent(addon -> {

CompositeCommand bsbAdminCmd =
commandsManager.getCommand(this.getConfig().getString("bskyblock.admin-command", "bsbadmin"));
BSkyBlock skyBlock = (BSkyBlock) addon;

new AdminCommand(this, bsbAdminCmd);
}
new AdminCommand(this,
commandsManager.getCommand("bsbadmin"));
new BiomesCommand(this,
commandsManager.getCommand("island"));

// Probably better would be casting and getting from settings, but then it should be added as
// dependency.
String currentWorld = a.getConfig().getString("world.world-name");
String currentWorld = skyBlock.getWorldSettings().getWorldName();

if (this.addonManager.getBiomes(currentWorld).isEmpty())
{
this.addonManager.importBiomes(currentWorld);
}

this.hooked = true;
});

// This listener fires on each owner change.
this.getServer().getPluginManager().registerEvents(new ChangeOwnerListener(this), this.getPlugin());
if (this.hooked)
{
// This listener fires on each owner change.
this.getServer().getPluginManager().registerEvents(
new ChangeOwnerListener(this), this.getPlugin());
}
else
{
this.logError("Biomes addon is not loaded, as bSkyBlock or AcidIsland is missing.");
this.setState(State.DISABLED);
}
}


@Override
public void onDisable()
{
if (this.settings != null)
if (this.hooked)
{
new Config<>(this, Settings.class).saveConfigObject(this.settings);
}
if (this.settings != null)
{
new Config<>(this, Settings.class).saveConfigObject(this.settings);
}

if (this.addonManager != null)
{
this.addonManager.save(false);
if (this.addonManager != null)
{
this.addonManager.save(false);
}
}
}


@Override
public void onReload()
{
this.loadSettings();
// Reload biomes manager.
this.addonManager.reloadManager();
if (this.hooked)
{
this.loadSettings();
// Reload biomes manager.
this.addonManager.reloadManager();

this.getLogger().info("Biomes addon reloaded.");
this.getLogger().info("Biomes addon reloaded.");
}
}


Expand Down Expand Up @@ -153,6 +163,12 @@ public Settings getSettings()
// Section: Variables
// ---------------------------------------------------------------------


/**
* This variable stores if current addon is hooked or not.
*/
private boolean hooked;

/**
* This variable stores biomes manager.
*/
Expand Down

0 comments on commit 711e3e8

Please sign in to comment.