2015-06-05 14:39:31 +02:00
|
|
|
package com.intellectualcrafters.plot.util.bukkit;
|
|
|
|
|
|
|
|
import net.milkbowl.vault.economy.Economy;
|
|
|
|
import net.milkbowl.vault.permission.Permission;
|
|
|
|
|
2015-06-05 16:08:16 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
|
|
|
2015-06-05 14:39:31 +02:00
|
|
|
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.util.EconHandler;
|
|
|
|
|
|
|
|
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-06-09 20:54:00 +02:00
|
|
|
return econ.getBalance(player.getName());
|
2015-06-05 14:39:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-09 20:54:00 +02:00
|
|
|
public void withdrawMoney(PlotPlayer player, double amount) {
|
2015-06-05 14:39:31 +02:00
|
|
|
econ.withdrawPlayer(player.getName(), amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-09 20:54:00 +02:00
|
|
|
public void depositMoney(PlotPlayer player, double amount) {
|
2015-06-05 14:39:31 +02:00
|
|
|
econ.depositPlayer(player.getName(), amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-09 20:54:00 +02:00
|
|
|
public void depositMoney(OfflinePlotPlayer player, double amount) {
|
2015-06-05 14:39:31 +02:00
|
|
|
econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPermission(PlotPlayer player, String perm, boolean value) {
|
|
|
|
if (value) {
|
|
|
|
perms.playerAdd(((BukkitPlayer) player).player, perm);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
perms.playerRemove(((BukkitPlayer) player).player, perm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|