From 0050a83d1a63c1aec31a085c64078ec41fa7e64b Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 16:14:43 +0200 Subject: [PATCH] Fix crash while enabling addon. This crash happened because BentoBox hookManager is not initialized when addons are enabled. --- .../bentobox/challenges/ChallengesAddon.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index 63c8b89..6f4cc94 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -40,8 +40,9 @@ public class ChallengesAddon extends Addon { /** * VaultHook that process economy. + * todo: because of BentoBox limitations. */ - private VaultHook vaultHook; + private Optional vaultHook = null; /** * Level addon. @@ -131,18 +132,19 @@ public class ChallengesAddon extends Addon { this.levelAddon = (Level) level.get(); } - Optional 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 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)); @@ -245,7 +247,13 @@ public class ChallengesAddon extends Addon { */ 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; } @@ -256,7 +264,7 @@ public class ChallengesAddon extends Addon { */ public VaultHook getEconomyProvider() { - return vaultHook; + return vaultHook.orElseGet(null); }