mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2025-01-02 14:29:01 +01:00
Add direct access to vaultHook and Level addon.
This commit is contained in:
parent
e68c5b2773
commit
2734c70fc5
@ -2,12 +2,17 @@ package world.bentobox.challenges;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.configuration.Config;
|
import world.bentobox.bentobox.api.configuration.Config;
|
||||||
|
import world.bentobox.bentobox.hooks.VaultHook;
|
||||||
import world.bentobox.challenges.commands.ChallengesCommand;
|
import world.bentobox.challenges.commands.ChallengesCommand;
|
||||||
import world.bentobox.challenges.commands.admin.Challenges;
|
import world.bentobox.challenges.commands.admin.Challenges;
|
||||||
import world.bentobox.challenges.listeners.ResetListener;
|
import world.bentobox.challenges.listeners.ResetListener;
|
||||||
import world.bentobox.challenges.listeners.SaveListener;
|
import world.bentobox.challenges.listeners.SaveListener;
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
|
import world.bentobox.level.Level;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add-on to BSkyBlock that enables challenges
|
* Add-on to BSkyBlock that enables challenges
|
||||||
@ -29,10 +34,20 @@ public class ChallengesAddon extends Addon {
|
|||||||
private boolean hooked;
|
private boolean hooked;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This indicate if economy plugin exists.
|
* This boolean indicate if economy is enabled.
|
||||||
*/
|
*/
|
||||||
private boolean economyProvided;
|
private boolean economyProvided;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VaultHook that process economy.
|
||||||
|
*/
|
||||||
|
private VaultHook vaultHook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Level addon.
|
||||||
|
*/
|
||||||
|
private Level levelAddon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This indicate if level addon exists.
|
* This indicate if level addon exists.
|
||||||
*/
|
*/
|
||||||
@ -103,17 +118,31 @@ public class ChallengesAddon extends Addon {
|
|||||||
if (this.hooked) {
|
if (this.hooked) {
|
||||||
// Try to find Level addon and if it does not exist, display a warning
|
// Try to find Level addon and if it does not exist, display a warning
|
||||||
|
|
||||||
this.levelProvided = this.getAddonByName("Level").isPresent();
|
Optional<Addon> level = this.getAddonByName("Level");
|
||||||
|
|
||||||
if (!this.levelProvided) {
|
if (!level.isPresent())
|
||||||
|
{
|
||||||
this.logWarning("Level add-on not found so level challenges will not work!");
|
this.logWarning("Level add-on not found so level challenges will not work!");
|
||||||
|
this.levelAddon = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.levelProvided = true;
|
||||||
|
this.levelAddon = (Level) level.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.economyProvided = this.getPlugin().getVault().isPresent() && this.getPlugin().getVault().get().hook();
|
Optional<VaultHook> vault = this.getPlugin().getVault();
|
||||||
|
|
||||||
if (!this.economyProvided) {
|
if (!vault.isPresent() || !vault.get().hook())
|
||||||
|
{
|
||||||
|
this.vaultHook = null;
|
||||||
this.logWarning("Economy plugin not found so money options will not work!");
|
this.logWarning("Economy plugin not found so money options will not work!");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.economyProvided = true;
|
||||||
|
this.vaultHook = vault.get();
|
||||||
|
}
|
||||||
|
|
||||||
// Register the reset listener
|
// Register the reset listener
|
||||||
this.registerListener(new ResetListener(this));
|
this.registerListener(new ResetListener(this));
|
||||||
@ -215,6 +244,17 @@ public class ChallengesAddon extends Addon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns VaultHook. Used to get easier access to Economy. NEVER USE WITHOUT isEconomyProvided or null
|
||||||
|
* check.
|
||||||
|
* @return VaultHook or null.
|
||||||
|
*/
|
||||||
|
public VaultHook getEconomyProvider()
|
||||||
|
{
|
||||||
|
return vaultHook;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return levelProvided variable.
|
* @return levelProvided variable.
|
||||||
@ -223,4 +263,14 @@ public class ChallengesAddon extends Addon {
|
|||||||
{
|
{
|
||||||
return levelProvided;
|
return levelProvided;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns Level addon. Used to easier access to Level. NEVER USE WITHOUT isLevelProvided or null
|
||||||
|
* @return LevelAddon or null.
|
||||||
|
*/
|
||||||
|
public Level getLevelAddon()
|
||||||
|
{
|
||||||
|
return levelAddon;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user