PlotSquared/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java

87 lines
2.6 KiB
Java
Raw Normal View History

2015-07-30 19:24:01 +02:00
package com.plotsquared.bukkit.util;
2015-06-05 14:39:31 +02:00
2015-07-30 16:25:16 +02:00
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
2015-08-01 22:11:28 +02:00
import org.bukkit.World;
2015-07-30 16:25:16 +02:00
import org.bukkit.plugin.RegisteredServiceProvider;
2015-08-01 22:11:28 +02:00
import com.intellectualcrafters.plot.PS;
2015-07-27 19:50:04 +02:00
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler;
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
import com.plotsquared.bukkit.object.BukkitPlayer;
2015-06-05 16:08:16 +02:00
2015-06-05 14:39:31 +02:00
public class BukkitEconHandler extends EconHandler {
private Economy econ;
private Permission perms;
public boolean init() {
if (econ == null || perms == null) {
setupPermissions();
setupEconomy();
}
return econ != null && perms != null;
}
private boolean setupPermissions()
{
RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
if (permissionProvider != null) {
perms = permissionProvider.getProvider();
}
return (perms != null);
}
private boolean setupEconomy()
{
RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
econ = economyProvider.getProvider();
}
return (econ != null);
}
@Override
public double getMoney(PlotPlayer player) {
2015-07-27 20:06:20 +02:00
double bal = super.getMoney(player);
if (bal == Double.NaN) {
return econ.getBalance(player.getName());
}
return bal;
2015-06-05 14:39:31 +02:00
}
@Override
public void withdrawMoney(PlotPlayer player, double amount) {
2015-06-05 14:39:31 +02:00
econ.withdrawPlayer(player.getName(), amount);
}
@Override
public void depositMoney(PlotPlayer player, double amount) {
2015-06-05 14:39:31 +02:00
econ.depositPlayer(player.getName(), amount);
}
@Override
public void depositMoney(OfflinePlotPlayer player, double amount) {
2015-06-05 14:39:31 +02:00
econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
}
@Override
2015-08-01 22:11:28 +02:00
public void setPermission(String player, String perm, boolean value) {
2015-06-05 14:39:31 +02:00
if (value) {
2015-08-01 22:11:28 +02:00
perms.playerAdd((World) null, player, perm);
2015-06-05 14:39:31 +02:00
}
else {
2015-08-01 22:11:28 +02:00
perms.playerRemove((World) null, player, perm);
2015-06-05 14:39:31 +02:00
}
}
2015-08-01 22:11:28 +02:00
@Override
public boolean hasPermission(String player, String perm) {
return perms.playerHas((String) null, Bukkit.getOfflinePlayer(player), perm);
}
2015-06-05 14:39:31 +02:00
}