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:
		
							
								
								
									
										6
									
								
								README
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								README
									
									
									
									
									
								
							@@ -126,8 +126,14 @@ toowner - Whether the money from gate-use goes to the owner or nobody
 | 
			
		||||
=============
 | 
			
		||||
  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]
 | 
			
		||||
 - 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]
 | 
			
		||||
 - Made some errors more user-friendly
 | 
			
		||||
 - Properly take into account portal-closed material
 | 
			
		||||
 
 | 
			
		||||
@@ -24,8 +24,6 @@ import org.bukkit.material.Button;
 | 
			
		||||
import org.bukkit.material.MaterialData;
 | 
			
		||||
import org.bukkit.util.Vector;
 | 
			
		||||
 | 
			
		||||
import com.nijiko.coelho.iConomy.iConomy;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Portal.java - Plug-in for hey0's minecraft mod.
 | 
			
		||||
 * @author Shaun (sturmeh)
 | 
			
		||||
@@ -687,7 +685,7 @@ public class Portal {
 | 
			
		||||
				return null;
 | 
			
		||||
			}
 | 
			
		||||
			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;
 | 
			
		||||
 
 | 
			
		||||
@@ -45,7 +45,7 @@ import org.bukkit.util.config.Configuration;
 | 
			
		||||
// Permissions
 | 
			
		||||
import com.nijikokun.bukkit.Permissions.Permissions;
 | 
			
		||||
// iConomy
 | 
			
		||||
import com.nijiko.coelho.iConomy.iConomy;
 | 
			
		||||
import com.iConomy.*;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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()));
 | 
			
		||||
				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 && 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());
 | 
			
		||||
						if (iConomyHandler.toOwner && p != null && !portal.getOwner().equals(player.getName()))
 | 
			
		||||
							p.sendMessage(ChatColor.GREEN + "Obtained " + iConomy.getBank().format(portal.getGate().getUseCost()) + " from Stargate " + portal.getName());
 | 
			
		||||
						if (portal.getGate().getToOwner() && p != null)
 | 
			
		||||
							p.sendMessage(ChatColor.GREEN + "Obtained " + iConomyHandler.format(portal.getGate().getUseCost()) + " from Stargate " + portal.getName());
 | 
			
		||||
					}
 | 
			
		||||
					if (!teleMsg.isEmpty()) {
 | 
			
		||||
						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()));
 | 
			
		||||
				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) {
 | 
			
		||||
						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());
 | 
			
		||||
						if (iConomyHandler.toOwner && p != null && !portal.getOwner().equals(player.getName())) {
 | 
			
		||||
							p.sendMessage(ChatColor.GREEN + "Obtained " + iConomy.getBank().format(portal.getGate().getUseCost()) + " from Stargate " + portal.getName());
 | 
			
		||||
						if (portal.getGate().getToOwner() && p != null) {
 | 
			
		||||
							p.sendMessage(ChatColor.GREEN + "Obtained " + iConomyHandler.format(portal.getGate().getUseCost()) + " from Stargate " + portal.getName());
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					if (!teleMsg.isEmpty()) {
 | 
			
		||||
@@ -505,9 +507,9 @@ public class Stargate extends JavaPlugin {
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					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) {
 | 
			
		||||
						player.sendMessage(ChatColor.GREEN + "Refunded " + iConomy.getBank().format(-portal.getGate().getDestroyCost()));
 | 
			
		||||
						player.sendMessage(ChatColor.GREEN + "Refunded " + iConomyHandler.format(-portal.getGate().getDestroyCost()));
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,8 @@
 | 
			
		||||
package net.TheDgtl.Stargate;
 | 
			
		||||
 | 
			
		||||
import com.nijiko.coelho.iConomy.iConomy;
 | 
			
		||||
import com.nijiko.coelho.iConomy.system.Account;
 | 
			
		||||
import com.iConomy.*;
 | 
			
		||||
import com.iConomy.system.Account;
 | 
			
		||||
import com.iConomy.system.Holdings;
 | 
			
		||||
 | 
			
		||||
public class iConomyHandler {
 | 
			
		||||
	public static boolean useiConomy = false;
 | 
			
		||||
@@ -15,33 +16,36 @@ public class iConomyHandler {
 | 
			
		||||
	
 | 
			
		||||
	public static double getBalance(String player) {
 | 
			
		||||
		if (useiConomy && iconomy != null) {
 | 
			
		||||
			Account acc = iConomy.getBank().getAccount(player);
 | 
			
		||||
			Account acc = iConomy.getAccount(player);
 | 
			
		||||
			if (acc == null) {
 | 
			
		||||
				Stargate.log.info("[Stargate::ich::getBalance] Error fetching iConomy account for " + player);
 | 
			
		||||
				return 0;
 | 
			
		||||
			}
 | 
			
		||||
			return acc.getBalance();
 | 
			
		||||
			return acc.getHoldings().balance();
 | 
			
		||||
		}
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static boolean chargePlayer(String player, String target, double amount) {
 | 
			
		||||
		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) {
 | 
			
		||||
				Stargate.log.info("[Stargate::ich::chargePlayer] Error fetching iConomy account for " + player);
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
			double balance = acc.getBalance();
 | 
			
		||||
			Holdings hold = acc.getHoldings();
 | 
			
		||||
			
 | 
			
		||||
			if (balance < amount) return false;
 | 
			
		||||
			acc.setBalance(balance - amount);
 | 
			
		||||
			if (!hold.hasEnough(amount)) return false;
 | 
			
		||||
			hold.subtract(amount);
 | 
			
		||||
			
 | 
			
		||||
			if (target != null && !player.equals(target)) {
 | 
			
		||||
				Account tAcc = iConomy.getBank().getAccount(target);
 | 
			
		||||
			if (target != null) {
 | 
			
		||||
				Account tAcc = iConomy.getAccount(target);
 | 
			
		||||
				if (tAcc != null) {
 | 
			
		||||
					balance = tAcc.getBalance();
 | 
			
		||||
					tAcc.setBalance(balance + amount);
 | 
			
		||||
					Holdings tHold = tAcc.getHoldings();
 | 
			
		||||
					tHold.add(amount);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			return true;
 | 
			
		||||
@@ -52,4 +56,8 @@ public class iConomyHandler {
 | 
			
		||||
	public static boolean useiConomy() {
 | 
			
		||||
		return (useiConomy && iconomy != null);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static String format(int amt) {
 | 
			
		||||
		return iConomy.format(amt);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
name: Stargate
 | 
			
		||||
main: net.TheDgtl.Stargate.Stargate
 | 
			
		||||
version: 0.4.4
 | 
			
		||||
version: 0.4.5
 | 
			
		||||
description: Stargate mod for Bukkit
 | 
			
		||||
author: Drakia
 | 
			
		||||
website: http://www.thedgtl.net
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user