Updated for iConomy 4.0 API

This commit is contained in:
DarkLiKally 2011-02-25 15:30:28 +01:00
parent 91f9acb633
commit 71a6d8ab44
3 changed files with 18 additions and 9 deletions

Binary file not shown.

View File

@ -22,6 +22,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.nijikokun.bukkit.iConomy.Account;
import com.nijikokun.bukkit.iConomy.iConomy;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
@ -58,9 +59,11 @@ public boolean handle(CommandSender sender, String senderName, String command, S
if (args[1] == "info") {
player.sendMessage(ChatColor.YELLOW + "Region " + id + " costs " +
iConomy.Misc.formatCurrency(flags.getIntFlag("iconomy", "price"), iConomy.currency));
if (iConomy.database.hasBalance(player.getName())) {
if (iConomy.getBank().hasAccount(player.getName())) {
player.sendMessage(ChatColor.YELLOW + "You have " +
iConomy.Misc.formatCurrency((int)Math.round(iConomy.database.getBalance(player.getName())), iConomy.currency));
iConomy.Misc.formatCurrency(
(int)Math.round(iConomy.getBank().getAccount(player.getName()).getBalance()),
iConomy.currency));
} else {
player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
}
@ -68,18 +71,20 @@ public boolean handle(CommandSender sender, String senderName, String command, S
player.sendMessage(ChatColor.RED + "Usage: /buyregion <region id> (info)");
}
} else {
if (iConomy.database.hasBalance(player.getName())) {
double balance = iConomy.database.getBalance(player.getName());
if (iConomy.getBank().hasAccount(player.getName())) {
Account account = iConomy.getBank().getAccount(player.getName());
double balance = account.getBalance();
int regionPrice = flags.getIntFlag("iconomy", "price");
if (balance >= regionPrice) {
iConomy.database.setBalance(player.getName(), balance - regionPrice);
account.subtract(regionPrice);
player.sendMessage(ChatColor.YELLOW + "You have bought the region " + id + " for " +
iConomy.Misc.formatCurrency(regionPrice, iConomy.currency));
DefaultDomain owners = region.getOwners();
owners.addPlayer(player.getName());
region.setOwners(owners);
flags.setFlag("iconomy", "buyable", false);
account.save();
}
} else {
player.sendMessage(ChatColor.YELLOW + "You have not enough money.");

View File

@ -32,6 +32,7 @@
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.nijikokun.bukkit.iConomy.Account;
import com.nijikokun.bukkit.iConomy.iConomy;
import java.io.IOException;
import java.util.logging.Level;
@ -106,18 +107,21 @@ public boolean handle(CommandSender sender, String senderName, String command, S
region.getOwners().addPlayer(player.getName());
if (wg.iConomy != null && wg.useiConomy && wg.buyOnClaim) {
if (iConomy.database.hasBalance(player.getName())) {
double balance = iConomy.database.getBalance(player.getName());
if (iConomy.getBank().hasAccount(player.getName())) {
Account account = iConomy.getBank().getAccount(player.getName());
double balance = account.getBalance();
int regionCosts = region.countBlocks() * wg.buyOnClaimPrice;
if (balance >= regionCosts) {
iConomy.database.setBalance(player.getName(), balance - regionCosts);
account.subtract(regionCosts);
player.sendMessage(ChatColor.YELLOW + "You have bought that region for " +
iConomy.Misc.formatCurrency(regionCosts, iConomy.currency));
account.save();
} else {
player.sendMessage(ChatColor.RED + "You have not enough money.");
player.sendMessage(ChatColor.RED + "The region you want to claim costs " +
iConomy.Misc.formatCurrency(regionCosts, iConomy.currency));
player.sendMessage(ChatColor.RED + "You have " + iConomy.Misc.formatCurrency((int)Math.round(balance), iConomy.currency));
player.sendMessage(ChatColor.RED + "You have " + iConomy.Misc.formatCurrency(
(int)Math.round(balance), iConomy.currency));
return true;
}
} else {