mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-09-02 10:00:13 +02:00
Added support for Reserve economy
This commit is contained in:
parent
6bb498c607
commit
2c8c6190ee
|
@ -15,6 +15,9 @@ dependencies {
|
|||
// Vault
|
||||
compileOnly (group: 'net.milkbowl', name: 'vault', version: '1.7.1')
|
||||
|
||||
// Reserve
|
||||
compileOnly (group: 'net.tnemc', name: 'Reserve', version: '0.1.3.0')
|
||||
|
||||
// Leaderheads
|
||||
compileOnly (group: 'me.robin', name: 'leaderheads', version: '1.0')
|
||||
|
||||
|
|
|
@ -3,16 +3,25 @@ package me.goodandevil.skyblock.economy;
|
|||
import me.goodandevil.skyblock.api.event.player.PlayerWithdrawMoneyEvent;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import net.tnemc.core.Reserve;
|
||||
import net.tnemc.core.economy.EconomyAPI;
|
||||
import net.tnemc.core.permissions.PermissionsAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class EconomyManager {
|
||||
|
||||
private Economy economy = null;
|
||||
private Permission permission = null;
|
||||
// Vault
|
||||
private Economy vaultEconomy = null;
|
||||
private Permission vaultPermission = null;
|
||||
|
||||
// Reserve
|
||||
private EconomyAPI reserveEconomy = null;
|
||||
// private PermissionsAPI reservePermission = null;
|
||||
|
||||
public EconomyManager() {
|
||||
setup();
|
||||
|
@ -23,48 +32,68 @@ public class EconomyManager {
|
|||
RegisteredServiceProvider<Economy> economyRsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
|
||||
if (economyRsp != null)
|
||||
economy = economyRsp.getProvider();
|
||||
this.vaultEconomy = economyRsp.getProvider();
|
||||
|
||||
RegisteredServiceProvider<Permission> permissionRsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||
if (permissionRsp != null)
|
||||
permission = permissionRsp.getProvider();
|
||||
this.vaultPermission = permissionRsp.getProvider();
|
||||
} else if (Bukkit.getServer().getPluginManager().getPlugin("Reserve") != null) {
|
||||
if (Reserve.instance().economyProvided())
|
||||
this.reserveEconomy = Reserve.instance().economy();
|
||||
|
||||
// if (Reserve.instance().permissionsProvided())
|
||||
// this.reservePermission = Reserve.instance().permissions();
|
||||
}
|
||||
}
|
||||
|
||||
public double getBalance(Player player) {
|
||||
return economy == null ? 0.0D : economy.getBalance(player);
|
||||
if (this.vaultEconomy != null)
|
||||
return this.vaultEconomy.getBalance(player);
|
||||
|
||||
if (this.reserveEconomy != null)
|
||||
return this.reserveEconomy.getHoldings(player.getUniqueId()).doubleValue();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean hasBalance(Player player, double money) {
|
||||
return getBalance(player) >= money;
|
||||
return this.getBalance(player) >= money;
|
||||
}
|
||||
|
||||
public void withdraw(Player player, double money) {
|
||||
if (economy != null)
|
||||
economy.withdrawPlayer(player, money);
|
||||
if (this.vaultEconomy != null)
|
||||
this.vaultEconomy.withdrawPlayer(player, money);
|
||||
else if (this.reserveEconomy != null)
|
||||
this.reserveEconomy.removeHoldings(player.getUniqueId(), new BigDecimal(money));
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerWithdrawMoneyEvent(player, money));
|
||||
}
|
||||
|
||||
public void deposit(Player player, double money) {
|
||||
if (economy != null) {
|
||||
economy.depositPlayer(player, money);
|
||||
}
|
||||
if (this.vaultEconomy != null)
|
||||
this.vaultEconomy.depositPlayer(player, money);
|
||||
else if (this.reserveEconomy != null)
|
||||
this.reserveEconomy.addHoldings(player.getUniqueId(), new BigDecimal(money));
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerWithdrawMoneyEvent(player, money));
|
||||
}
|
||||
|
||||
public boolean hasPermission(String world, OfflinePlayer offlinePlayer, String perm) {
|
||||
if (permission != null)
|
||||
return permission.playerHas(world, offlinePlayer, perm);
|
||||
if (this.vaultPermission != null)
|
||||
return this.vaultPermission.playerHas(world, offlinePlayer, perm);
|
||||
|
||||
// if (this.reservePermission != null) {
|
||||
// // TODO
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEconomy() {
|
||||
return economy != null;
|
||||
return this.vaultEconomy != null || this.reserveEconomy != null;
|
||||
}
|
||||
|
||||
public boolean isPermission() {
|
||||
return permission != null;
|
||||
return this.vaultPermission != null/* || this.reservePermission != null*/;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1060,6 +1060,7 @@ public enum Materials {
|
|||
int data;
|
||||
boolean is13Plusonly;
|
||||
private Material cachedMaterial;
|
||||
private boolean isMaterialParsed = false;
|
||||
|
||||
Materials(String old13Mat, String old12Mat, int data) {
|
||||
this(old13Mat, old12Mat, data, false);
|
||||
|
@ -1237,7 +1238,7 @@ public enum Materials {
|
|||
}
|
||||
|
||||
public Material parseMaterial() {
|
||||
if (this.cachedMaterial != null)
|
||||
if (this.cachedMaterial != null || this.isMaterialParsed)
|
||||
return this.cachedMaterial;
|
||||
|
||||
if (this.isSpawner() && this != Materials.SPAWNER) {
|
||||
|
@ -1260,6 +1261,7 @@ public enum Materials {
|
|||
}
|
||||
|
||||
this.cachedMaterial = Material.matchMaterial(old12Mat);
|
||||
this.isMaterialParsed = true;
|
||||
return this.cachedMaterial;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ version: @version@
|
|||
api-version: 1.13
|
||||
description: A unique SkyBlock plugin
|
||||
author: Songoda
|
||||
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, LeaderHeads, EpicSpawners, WildStacker, UltimateStacker, WorldEdit]
|
||||
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, Reserve, LeaderHeads, EpicSpawners, WildStacker, UltimateStacker, WorldEdit]
|
||||
loadbefore: [Multiverse-Core]
|
||||
commands:
|
||||
island:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
allprojects {
|
||||
apply plugin: 'java'
|
||||
group = 'com.goodandevil.skyblock'
|
||||
version = 'Build-78'
|
||||
version = 'Build-78.3'
|
||||
}
|
||||
|
||||
subprojects {
|
||||
|
|
Loading…
Reference in New Issue
Block a user