diff --git a/base/color/pom.xml b/base/color/pom.xml index 29c18d7..d08410f 100644 --- a/base/color/pom.xml +++ b/base/color/pom.xml @@ -6,7 +6,7 @@ cc.carm.lib easyplugin-parent - 1.5.5 + 1.5.6 ../../pom.xml diff --git a/base/command-alias/pom.xml b/base/command-alias/pom.xml index d78b5b5..e6b87c6 100644 --- a/base/command-alias/pom.xml +++ b/base/command-alias/pom.xml @@ -6,7 +6,7 @@ cc.carm.lib easyplugin-parent - 1.5.5 + 1.5.6 ../../pom.xml diff --git a/base/command/pom.xml b/base/command/pom.xml index 1a946b1..e74137a 100644 --- a/base/command/pom.xml +++ b/base/command/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/base/gui/pom.xml b/base/gui/pom.xml index a0a24fd..0ac7320 100644 --- a/base/gui/pom.xml +++ b/base/gui/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/base/main/pom.xml b/base/main/pom.xml index f1eaff0..eaaa9cf 100644 --- a/base/main/pom.xml +++ b/base/main/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/base/messages/pom.xml b/base/messages/pom.xml index 5758401..3f7f427 100644 --- a/base/messages/pom.xml +++ b/base/messages/pom.xml @@ -6,7 +6,7 @@ cc.carm.lib easyplugin-parent - 1.5.5 + 1.5.6 ../../pom.xml diff --git a/base/storage/pom.xml b/base/storage/pom.xml index 306427d..a842229 100644 --- a/base/storage/pom.xml +++ b/base/storage/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/base/user/pom.xml b/base/user/pom.xml index d403179..551b0e8 100644 --- a/base/user/pom.xml +++ b/base/user/pom.xml @@ -6,7 +6,7 @@ cc.carm.lib easyplugin-parent - 1.5.5 + 1.5.6 ../../pom.xml diff --git a/base/utils/pom.xml b/base/utils/pom.xml index 735abe6..2247a87 100644 --- a/base/utils/pom.xml +++ b/base/utils/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/collection/all/pom.xml b/collection/all/pom.xml index fe25432..87411d7 100644 --- a/collection/all/pom.xml +++ b/collection/all/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/collection/bom/pom.xml b/collection/bom/pom.xml index 18b1f9f..95370e9 100644 --- a/collection/bom/pom.xml +++ b/collection/bom/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/collection/common/pom.xml b/collection/common/pom.xml index 164c2db..f6fd4ec 100644 --- a/collection/common/pom.xml +++ b/collection/common/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/extension/gh-checker/pom.xml b/extension/gh-checker/pom.xml index e03e190..0cd5805 100644 --- a/extension/gh-checker/pom.xml +++ b/extension/gh-checker/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/extension/papi/pom.xml b/extension/papi/pom.xml index 922be6f..7065850 100644 --- a/extension/papi/pom.xml +++ b/extension/papi/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/extension/vault/pom.xml b/extension/vault/pom.xml index a5e8512..0e6f94e 100644 --- a/extension/vault/pom.xml +++ b/extension/vault/pom.xml @@ -5,7 +5,7 @@ easyplugin-parent cc.carm.lib - 1.5.5 + 1.5.6 ../../pom.xml 4.0.0 diff --git a/extension/vault/src/main/java/cc/carm/lib/easyplugin/vault/EasyVault.java b/extension/vault/src/main/java/cc/carm/lib/easyplugin/vault/EasyVault.java new file mode 100644 index 0000000..ffd7882 --- /dev/null +++ b/extension/vault/src/main/java/cc/carm/lib/easyplugin/vault/EasyVault.java @@ -0,0 +1,79 @@ +package cc.carm.lib.easyplugin.vault; + +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.economy.EconomyResponse; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.jetbrains.annotations.NotNull; + +public class EasyVault { + public static boolean hasVault() { + return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null; + } + + public static @NotNull EasyVault create() throws Exception { + return new EasyVault(); + } + + private Economy economy = null; + + public EasyVault() throws Exception { + if (!setupEconomy()) throw new Exception("Vault not found!"); + } + + public boolean setupEconomy() { + if (!hasVault()) return false; + RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); + if (rsp == null) return false; + + this.economy = rsp.getProvider(); + return true; + } + + public Economy getEconomy() { + return economy; + } + + public double getMoney(@NotNull Player player) { + try { + return getEconomy().getBalance(player); + } catch (NullPointerException ignore) { + return 0L; + } + } + + public double getMoney(@NotNull OfflinePlayer player) { + try { + return getEconomy().getBalance(player); + } catch (NullPointerException ignore) { + return 0L; + } + } + + public boolean checkMoney(@NotNull OfflinePlayer player, double amount) { + return getMoney(player) >= amount; + } + + public boolean checkMoney(@NotNull Player player, double amount) { + return getMoney(player) >= amount; + } + + public EconomyResponse removeMoney(Player player, double amount) { + return getEconomy().withdrawPlayer(player, amount); + } + + public EconomyResponse removeMoney(OfflinePlayer player, double amount) { + return getEconomy().withdrawPlayer(player, amount); + } + + public EconomyResponse addMoney(Player player, double amount) { + return getEconomy().depositPlayer(player, amount); + } + + public EconomyResponse addMoney(OfflinePlayer player, double amount) { + return getEconomy().depositPlayer(player, amount); + } + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9e44c1f..480b565 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ cc.carm.lib easyplugin-parent pom - 1.5.5 + 1.5.6 base/color base/utils @@ -144,7 +144,7 @@ cc.carm.lib githubreleases4j - 1.3.1 + 1.3.2 cc.carm.lib