Skip to content

Commit

Permalink
Fix crash while enabling addon.
Browse files Browse the repository at this point in the history
This crash happened because BentoBox hookManager is not initialized when addons are enabled.
  • Loading branch information
BONNe committed Jan 26, 2019
1 parent 6d1f499 commit 0050a83
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/main/java/world/bentobox/challenges/ChallengesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public class ChallengesAddon extends Addon {

/**
* VaultHook that process economy.
* todo: because of BentoBox limitations.
*/
private VaultHook vaultHook;
private Optional<VaultHook> vaultHook = null;

/**
* Level addon.
Expand Down Expand Up @@ -131,18 +132,19 @@ public void onEnable() {
this.levelAddon = (Level) level.get();
}

Optional<VaultHook> vault = this.getPlugin().getVault();

if (!vault.isPresent() || !vault.get().hook())
{
this.vaultHook = null;
this.logWarning("Economy plugin not found so money options will not work!");
}
else
{
this.economyProvided = true;
this.vaultHook = vault.get();
}
// BentoBox limitation. Cannot check hooks, as HookManager is created after loading addons.
// Optional<VaultHook> vault = this.getPlugin().getVault();
//
// if (!vault.isPresent() || !vault.get().hook())
// {
// this.vaultHook = null;
// this.logWarning("Economy plugin not found so money options will not work!");
// }
// else
// {
// this.economyProvided = true;
// this.vaultHook = vault.get();
// }

// Register the reset listener
this.registerListener(new ResetListener(this));
Expand Down Expand Up @@ -245,7 +247,13 @@ public Settings getChallengesSettings()
*/
public boolean isEconomyProvided()
{
return economyProvided;
if (!this.economyProvided && this.getPlugin().getVault().isPresent() && this.vaultHook == null)
{
this.vaultHook = this.getPlugin().getVault();
this.economyProvided = this.vaultHook.get().hook();
}

return this.economyProvided;
}


Expand All @@ -256,7 +264,7 @@ public boolean isEconomyProvided()
*/
public VaultHook getEconomyProvider()
{
return vaultHook;
return vaultHook.orElseGet(null);
}


Expand Down

0 comments on commit 0050a83

Please sign in to comment.