Implemented Vault support 🎉

This commit is contained in:
Florian CUNY 2018-10-30 15:35:27 +01:00
parent c236e1a3bc
commit 0c75e556b2
4 changed files with 59 additions and 1 deletions

11
pom.xml
View File

@ -56,6 +56,10 @@
<id>bstats-repo</id>
<url>http://repo.bstats.org/content/repositories/releases/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
</repositories>
<dependencies>
@ -97,6 +101,13 @@
<artifactId>mongodb-driver</artifactId>
<version>3.8.0</version>
</dependency>
<!-- Vault -->
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

View File

@ -10,6 +10,7 @@ import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.user.Notifier;
import world.bentobox.bentobox.commands.BentoBoxCommand;
import world.bentobox.bentobox.hooks.VaultHook;
import world.bentobox.bentobox.listeners.BannedVisitorCommands;
import world.bentobox.bentobox.listeners.BlockEndDragon;
import world.bentobox.bentobox.listeners.DeathListener;
@ -135,6 +136,7 @@ public class BentoBox extends JavaPlugin {
// Load hooks
hooksManager = new HooksManager(this);
hooksManager.registerHook(new VaultHook());
// Fire plugin ready event
isLoaded = true;
@ -322,4 +324,12 @@ public class BentoBox extends JavaPlugin {
return hooksManager;
}
/**
* Convenience method to get the VaultHook.
* @return the Vault hook
*/
public Optional<VaultHook> getVault() {
return Optional.ofNullable((VaultHook) hooksManager.getHook("Vault").orElse(null));
}
}

View File

@ -0,0 +1,37 @@
package world.bentobox.bentobox.hooks;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import world.bentobox.bentobox.api.hooks.Hook;
/**
* @author Poslovitch
*/
public class VaultHook extends Hook {
private Economy economy;
public VaultHook() {
super("Vault");
}
@Override
public boolean hook() {
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
economy = rsp.getProvider();
return economy != null;
}
@Override
public String getFailureCause() {
return "no plugin supporting economy has been found";
}
public Economy getEconomy() {
return economy;
}
}

View File

@ -5,7 +5,7 @@ api-version: 1.13
authors: [tastybento, Poslovitch]
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI]
softdepend: [Vault, PlaceholderAPI, MVdWPlaceholderAPI]
loadbefore: [Multiverse-Core]