Fixed iConomy

This commit is contained in:
Steven Scott 2011-08-25 21:27:43 -07:00
parent fc6dda8b4a
commit f1cb266a0a
4 changed files with 54 additions and 20 deletions

2
README
View File

@ -156,6 +156,8 @@ maxgates - If non-zero, will define the maximum amount of gates allowed on any n
============= =============
Changes Changes
============= =============
[Version 0.6.4]
- Fixed iConomy handling
[Version 0.6.3] [Version 0.6.3]
- Fixed (Not Connected) showing on inter-world gate loading - Fixed (Not Connected) showing on inter-world gate loading
- Added the ability to negate Network/World permissions (Use, Create and Destroy) - Added the ability to negate Network/World permissions (Use, Create and Destroy)

View File

@ -816,9 +816,13 @@ public class Portal {
} }
} }
if (!Stargate.chargePlayer(player, null, "create", gate.getCreateCost())) { int cost = Stargate.getCreateCost(player, gate);
Stargate.debug("createPortal", "Insufficient Funds"); if (cost > 0) {
return null; if (!Stargate.chargePlayer(player, null, gate.getCreateCost())) {
Stargate.sendMessage(player, "Insufficient Funds");
Stargate.debug("createPortal", "Insufficient Funds");
return null;
}
} }
Portal portal = null; Portal portal = null;

View File

@ -486,13 +486,11 @@ public class Stargate extends JavaPlugin {
/* /*
* Charge player for {action} if required, true on success, false if can't afford * Charge player for {action} if required, true on success, false if can't afford
*/ */
public static boolean chargePlayer(Player player, String target, String action, int cost) { public static boolean chargePlayer(Player player, String target, int cost) {
// If cost is 0 // If cost is 0
if (cost <= 0) return true; if (cost == 0) return true;
// iConomy is disabled // iConomy is disabled
if (!iConomyHandler.useiConomy()) return true; if (!iConomyHandler.useiConomy()) return true;
// Player gets free {action}
if (hasPerm(player, "stargate.free") || hasPerm(player, "stargate.free." + action)) return true;
// Charge player // Charge player
return iConomyHandler.chargePlayer(player.getName(), target, cost); return iConomyHandler.chargePlayer(player.getName(), target, cost);
} }
@ -509,10 +507,36 @@ public class Stargate extends JavaPlugin {
if (!iConomyHandler.chargeFreeDestination && dest.isFree()) return 0; if (!iConomyHandler.chargeFreeDestination && dest.isFree()) return 0;
// Cost is 0 if the player owns this gate and funds go to the owner // Cost is 0 if the player owns this gate and funds go to the owner
if (src.getGate().getToOwner() && src.getOwner().equalsIgnoreCase(player.getName())) return 0; if (src.getGate().getToOwner() && src.getOwner().equalsIgnoreCase(player.getName())) return 0;
// Player gets free gate use
if (hasPerm(player, "stargate.free") || hasPerm(player, "stargate.free.use")) return 0;
return src.getGate().getUseCost(); return src.getGate().getUseCost();
} }
/*
* Determine the cost to create the gate
*/
public static int getCreateCost(Player player, Gate gate) {
// Not using iConomy
if (!iConomyHandler.useiConomy()) return 0;
// Player gets free gate destruction
if (hasPerm(player, "stargate.free") || hasPerm(player, "stargate.free.create")) return 0;
return gate.getDestroyCost();
}
/*
* Determine the cost to destroy the gate
*/
public static int getDestroyCost(Player player, Gate gate) {
// Not using iConomy
if (!iConomyHandler.useiConomy()) return 0;
// Player gets free gate destruction
if (hasPerm(player, "stargate.free") || hasPerm(player, "stargate.free.destroy")) return 0;
return gate.getDestroyCost();
}
/* /*
* Check if a plugin is loaded/enabled already. Returns the plugin if so, null otherwise * Check if a plugin is loaded/enabled already. Returns the plugin if so, null otherwise
*/ */
@ -564,7 +588,7 @@ public class Stargate extends JavaPlugin {
int cost = Stargate.getUseCost(player, portal, dest); int cost = Stargate.getUseCost(player, portal, dest);
if (cost > 0) { if (cost > 0) {
String target = portal.getGate().getToOwner() ? portal.getOwner() : null; String target = portal.getGate().getToOwner() ? portal.getOwner() : null;
if (!Stargate.chargePlayer(player, target, "use", cost)) { if (!Stargate.chargePlayer(player, target, cost)) {
// Insufficient Funds // Insufficient Funds
Stargate.sendMessage(player, "Insufficient Funds"); Stargate.sendMessage(player, "Insufficient Funds");
portal.close(false); portal.close(false);
@ -654,7 +678,7 @@ public class Stargate extends JavaPlugin {
int cost = Stargate.getUseCost(player, portal, destination); int cost = Stargate.getUseCost(player, portal, destination);
if (cost > 0) { if (cost > 0) {
String target = portal.getGate().getToOwner() ? portal.getOwner() : null; String target = portal.getGate().getToOwner() ? portal.getOwner() : null;
if (!Stargate.chargePlayer(player, target, "use", cost)) { if (!Stargate.chargePlayer(player, target, cost)) {
// Insufficient Funds // Insufficient Funds
Stargate.sendMessage(player, "Insufficient Funds"); Stargate.sendMessage(player, "Insufficient Funds");
portal.close(false); portal.close(false);
@ -783,17 +807,21 @@ public class Stargate extends JavaPlugin {
return; return;
} }
if (!Stargate.chargePlayer(player, null, "destroy", portal.getGate().getDestroyCost())) { int cost = Stargate.getDestroyCost(player, portal.getGate());
Stargate.debug("onBlockBreak", "Insufficient Funds");
Stargate.sendMessage(player, iConomyHandler.inFundMsg);
event.setCancelled(true);
return;
}
if (portal.getGate().getDestroyCost() > 0) { if (cost != 0) {
Stargate.sendMessage(player, "Deducted " + iConomyHandler.format(portal.getGate().getDestroyCost()), false); if (!Stargate.chargePlayer(player, null, cost)) {
} else if (portal.getGate().getDestroyCost() < 0) { Stargate.debug("onBlockBreak", "Insufficient Funds");
Stargate.sendMessage(player, "Refunded " + iConomyHandler.format(-portal.getGate().getDestroyCost()), false); Stargate.sendMessage(player, iConomyHandler.inFundMsg);
event.setCancelled(true);
return;
}
if (cost > 0) {
Stargate.sendMessage(player, "Deducted " + iConomyHandler.format(cost), false);
} else if (cost < 0) {
Stargate.sendMessage(player, "Refunded " + iConomyHandler.format(-cost), false);
}
} }
portal.unregister(true); portal.unregister(true);

View File

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