Owner of gate now isn't charge for use if target is owner

Updated for iConomy 5.x
Fixed random iConomy bugs
This commit is contained in:
Drakia 2011-05-03 21:45:11 -07:00
parent 806f5e5e71
commit 7508c8d386
5 changed files with 41 additions and 27 deletions

6
README
View File

@ -126,8 +126,14 @@ toowner - Whether the money from gate-use goes to the owner or nobody
============= =============
Changes Changes
============= =============
[Version 0.4.5]
- Owner of gate now isn't charged for use if target is owner
- Updated for iConomy 5.x
- Fixed random iConomy bugs
[Version 0.4.4] [Version 0.4.4]
- Added a check for stargate.network.*/stargate.world.* on gate creation - Added a check for stargate.network.*/stargate.world.* on gate creation
- Check for stargate.world.*/stargate.network.* on gate entrance
- Warp player outside of gate on access denied
[Version 0.4.3] [Version 0.4.3]
- Made some errors more user-friendly - Made some errors more user-friendly
- Properly take into account portal-closed material - Properly take into account portal-closed material

View File

@ -24,8 +24,6 @@ import org.bukkit.material.Button;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.nijiko.coelho.iConomy.iConomy;
/** /**
* Portal.java - Plug-in for hey0's minecraft mod. * Portal.java - Plug-in for hey0's minecraft mod.
* @author Shaun (sturmeh) * @author Shaun (sturmeh)
@ -687,7 +685,7 @@ public class Portal {
return null; return null;
} }
if (gate.getCreateCost() > 0) if (gate.getCreateCost() > 0)
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(gate.getCreateCost())); player.sendMessage(ChatColor.GREEN + "Deducted " + iConomyHandler.format(gate.getCreateCost()));
} }
Portal portal = null; Portal portal = null;

View File

@ -45,7 +45,7 @@ import org.bukkit.util.config.Configuration;
// Permissions // Permissions
import com.nijikokun.bukkit.Permissions.Permissions; import com.nijikokun.bukkit.Permissions.Permissions;
// iConomy // iConomy
import com.nijiko.coelho.iConomy.iConomy; import com.iConomy.*;
/** /**
* Stargate.java - A customizeable portal plugin for Bukkit * Stargate.java - A customizeable portal plugin for Bukkit
@ -313,14 +313,14 @@ public class Stargate extends JavaPlugin {
boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp())); boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp()));
String target = (portal.getGate().getToOwner() ? portal.getOwner() : null); String target = (portal.getGate().getToOwner() ? portal.getOwner() : null);
iConCharge = iConCharge && !target.equals(player.getName());
if (!iConCharge || iConomyHandler.chargePlayer(player.getName(), target, portal.getGate().getUseCost())) { if (!iConCharge || iConomyHandler.chargePlayer(player.getName(), target, portal.getGate().getUseCost())) {
if (iConCharge && portal.getGate().getUseCost() > 0) { if (iConCharge && portal.getGate().getUseCost() > 0) {
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(portal.getGate().getUseCost())); player.sendMessage(ChatColor.GREEN + "Deducted " + iConomyHandler.format(portal.getGate().getUseCost()));
Player p = server.getPlayer(portal.getOwner()); Player p = server.getPlayer(portal.getOwner());
if (iConomyHandler.toOwner && p != null && !portal.getOwner().equals(player.getName())) if (portal.getGate().getToOwner() && p != null)
p.sendMessage(ChatColor.GREEN + "Obtained " + iConomy.getBank().format(portal.getGate().getUseCost()) + " from Stargate " + portal.getName()); p.sendMessage(ChatColor.GREEN + "Obtained " + iConomyHandler.format(portal.getGate().getUseCost()) + " from Stargate " + portal.getName());
} }
if (!teleMsg.isEmpty()) { if (!teleMsg.isEmpty()) {
player.sendMessage(ChatColor.BLUE + teleMsg); player.sendMessage(ChatColor.BLUE + teleMsg);
@ -371,14 +371,16 @@ public class Stargate extends JavaPlugin {
} }
boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp())); boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp()));
String target = (portal.getGate().getToOwner() ? portal.getOwner() : null);
iConCharge = iConCharge && !target.equals(player.getName());
if (!iConCharge || iConomyHandler.chargePlayer(player.getName(), portal.getOwner(), portal.getGate().getUseCost())) { if (!iConCharge || iConomyHandler.chargePlayer(player.getName(), target, portal.getGate().getUseCost())) {
if (iConCharge && portal.getGate().getUseCost() > 0) { if (iConCharge && portal.getGate().getUseCost() > 0) {
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(portal.getGate().getUseCost())); player.sendMessage(ChatColor.GREEN + "Deducted " + iConomyHandler.format(portal.getGate().getUseCost()));
Player p = server.getPlayer(portal.getOwner()); Player p = server.getPlayer(portal.getOwner());
if (iConomyHandler.toOwner && p != null && !portal.getOwner().equals(player.getName())) { if (portal.getGate().getToOwner() && p != null) {
p.sendMessage(ChatColor.GREEN + "Obtained " + iConomy.getBank().format(portal.getGate().getUseCost()) + " from Stargate " + portal.getName()); p.sendMessage(ChatColor.GREEN + "Obtained " + iConomyHandler.format(portal.getGate().getUseCost()) + " from Stargate " + portal.getName());
} }
} }
if (!teleMsg.isEmpty()) { if (!teleMsg.isEmpty()) {
@ -505,9 +507,9 @@ public class Stargate extends JavaPlugin {
} }
if (portal.getGate().getDestroyCost() > 0) { if (portal.getGate().getDestroyCost() > 0) {
player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(portal.getGate().getDestroyCost())); player.sendMessage(ChatColor.GREEN + "Deducted " + iConomyHandler.format(portal.getGate().getDestroyCost()));
} else if (portal.getGate().getDestroyCost() < 0) { } else if (portal.getGate().getDestroyCost() < 0) {
player.sendMessage(ChatColor.GREEN + "Refunded " + iConomy.getBank().format(-portal.getGate().getDestroyCost())); player.sendMessage(ChatColor.GREEN + "Refunded " + iConomyHandler.format(-portal.getGate().getDestroyCost()));
} }
} }

View File

@ -1,7 +1,8 @@
package net.TheDgtl.Stargate; package net.TheDgtl.Stargate;
import com.nijiko.coelho.iConomy.iConomy; import com.iConomy.*;
import com.nijiko.coelho.iConomy.system.Account; import com.iConomy.system.Account;
import com.iConomy.system.Holdings;
public class iConomyHandler { public class iConomyHandler {
public static boolean useiConomy = false; public static boolean useiConomy = false;
@ -15,33 +16,36 @@ public class iConomyHandler {
public static double getBalance(String player) { public static double getBalance(String player) {
if (useiConomy && iconomy != null) { if (useiConomy && iconomy != null) {
Account acc = iConomy.getBank().getAccount(player); Account acc = iConomy.getAccount(player);
if (acc == null) { if (acc == null) {
Stargate.log.info("[Stargate::ich::getBalance] Error fetching iConomy account for " + player); Stargate.log.info("[Stargate::ich::getBalance] Error fetching iConomy account for " + player);
return 0; return 0;
} }
return acc.getBalance(); return acc.getHoldings().balance();
} }
return 0; return 0;
} }
public static boolean chargePlayer(String player, String target, double amount) { public static boolean chargePlayer(String player, String target, double amount) {
if (useiConomy && iconomy != null) { if (useiConomy && iconomy != null) {
Account acc = iConomy.getBank().getAccount(player); // No point going from a player to themself
if (player.equals(target)) return true;
Account acc = iConomy.getAccount(player);
if (acc == null) { if (acc == null) {
Stargate.log.info("[Stargate::ich::chargePlayer] Error fetching iConomy account for " + player); Stargate.log.info("[Stargate::ich::chargePlayer] Error fetching iConomy account for " + player);
return false; return false;
} }
double balance = acc.getBalance(); Holdings hold = acc.getHoldings();
if (balance < amount) return false; if (!hold.hasEnough(amount)) return false;
acc.setBalance(balance - amount); hold.subtract(amount);
if (target != null && !player.equals(target)) { if (target != null) {
Account tAcc = iConomy.getBank().getAccount(target); Account tAcc = iConomy.getAccount(target);
if (tAcc != null) { if (tAcc != null) {
balance = tAcc.getBalance(); Holdings tHold = tAcc.getHoldings();
tAcc.setBalance(balance + amount); tHold.add(amount);
} }
} }
return true; return true;
@ -52,4 +56,8 @@ public class iConomyHandler {
public static boolean useiConomy() { public static boolean useiConomy() {
return (useiConomy && iconomy != null); return (useiConomy && iconomy != null);
} }
public static String format(int amt) {
return iConomy.format(amt);
}
} }

View File

@ -1,6 +1,6 @@
name: Stargate name: Stargate
main: net.TheDgtl.Stargate.Stargate main: net.TheDgtl.Stargate.Stargate
version: 0.4.4 version: 0.4.5
description: Stargate mod for Bukkit description: Stargate mod for Bukkit
author: Drakia author: Drakia
website: http://www.thedgtl.net website: http://www.thedgtl.net