mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-12-30 12:57:52 +01:00
Fix crash while enabling addon.
This crash happened because BentoBox hookManager is not initialized when addons are enabled.
This commit is contained in:
parent
6d1f4999e4
commit
0050a83d1a
@ -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.
|
||||
@ -131,18 +132,19 @@ public class ChallengesAddon extends Addon {
|
||||
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));
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user