Updated Economy Handling
- Remove iConomy support - Updated Vault support to 1.5 - Changed "useiconomy" setting to "useeconomy"
This commit is contained in:
		| @@ -16,7 +16,7 @@ | |||||||
| ############################ | ############################ | ||||||
| # Stargate economy options # | # Stargate economy options # | ||||||
| ############################ | ############################ | ||||||
| # useiconomy - Whether to use an economy plugin (Uses Register to interact with all economy plugins) | # useeconomy - Whether to use an economy plugin | ||||||
| # createcost - The cost to create a gate | # createcost - The cost to create a gate | ||||||
| # destroycost - The cost to destroy a gate | # destroycost - The cost to destroy a gate | ||||||
| # usecost - The cost to use a gate | # usecost - The cost to use a gate | ||||||
| @@ -40,7 +40,7 @@ handleVehicles: true | |||||||
| sortLists: false | sortLists: false | ||||||
| protectEntrance: false | protectEntrance: false | ||||||
| signColor: BLACK | signColor: BLACK | ||||||
| useiconomy: false | useeconomy: false | ||||||
| createcost: 0 | createcost: 0 | ||||||
| destroycost: 0 | destroycost: 0 | ||||||
| usecost: 0 | usecost: 0 | ||||||
|   | |||||||
							
								
								
									
										83
									
								
								src/net/TheDgtl/Stargate/EconomyHandler.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								src/net/TheDgtl/Stargate/EconomyHandler.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | |||||||
|  | package net.TheDgtl.Stargate; | ||||||
|  |  | ||||||
|  | import net.milkbowl.vault.economy.Economy; | ||||||
|  |  | ||||||
|  | import org.bukkit.plugin.Plugin; | ||||||
|  | import org.bukkit.plugin.PluginManager; | ||||||
|  | import org.bukkit.plugin.RegisteredServiceProvider; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Stargate - A portal plugin for Bukkit | ||||||
|  |  * Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net> | ||||||
|  |  *  | ||||||
|  |  * This program is free software: you can redistribute it and/or modify | ||||||
|  |  * it under the terms of the GNU Lesser General Public License as published by | ||||||
|  |  * the Free Software Foundation, either version 3 of the License, or | ||||||
|  |  * (at your option) any later version. | ||||||
|  |  *  | ||||||
|  |  * This program is distributed in the hope that it will be useful, | ||||||
|  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  |  * GNU Lesser General Public License for more details. | ||||||
|  |  * | ||||||
|  |  * You should have received a copy of the GNU Lesser General Public License | ||||||
|  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | public class EconomyHandler { | ||||||
|  | 	public static boolean economyEnabled = false; | ||||||
|  | 	public static Economy economy = null; | ||||||
|  | 	public static Plugin vault = null; | ||||||
|  | 	 | ||||||
|  | 	public static int useCost = 0; | ||||||
|  | 	public static int createCost = 0; | ||||||
|  | 	public static int destroyCost = 0; | ||||||
|  | 	public static boolean toOwner = false; | ||||||
|  | 	public static boolean chargeFreeDestination = true; | ||||||
|  | 	public static boolean freeGatesGreen = false; | ||||||
|  | 	 | ||||||
|  | 	public static double getBalance(String player) { | ||||||
|  | 		if (!economyEnabled) return 0; | ||||||
|  | 		return economy.getBalance(player); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public static boolean chargePlayer(String player, String target, double amount) { | ||||||
|  | 		if (!economyEnabled) return true; | ||||||
|  | 		if(player.equals(target)) return true; | ||||||
|  | 		if(economy != null) { | ||||||
|  | 			if(!economy.has(player, amount)) return false; | ||||||
|  | 			economy.withdrawPlayer(player, amount); | ||||||
|  | 			if(target != null) economy.depositPlayer(target, amount); | ||||||
|  | 		} | ||||||
|  | 		return false; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public static String format(int amt) { | ||||||
|  | 		if (economyEnabled) { | ||||||
|  | 			return economy.format(amt); | ||||||
|  | 		} | ||||||
|  | 		return ""; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public static boolean setupEconomy(PluginManager pm) { | ||||||
|  | 		if (!economyEnabled) return false; | ||||||
|  | 		// Check for Vault | ||||||
|  | 		Plugin p = pm.getPlugin("Vault"); | ||||||
|  | 		if (p != null && p.isEnabled()) { | ||||||
|  | 			RegisteredServiceProvider<Economy> economyProvider = Stargate.server.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); | ||||||
|  | 			if (economyProvider != null) { | ||||||
|  | 				economy = economyProvider.getProvider(); | ||||||
|  | 				vault = p; | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		economyEnabled = false; | ||||||
|  | 		return false; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public static boolean useEconomy() { | ||||||
|  | 		if(!economyEnabled || economy == null) return false; | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -55,7 +55,7 @@ public class Gate { | |||||||
| 	private int portalBlockOpen = Material.PORTAL.getId(); | 	private int portalBlockOpen = Material.PORTAL.getId(); | ||||||
| 	private int portalBlockClosed = Material.AIR.getId(); | 	private int portalBlockClosed = Material.AIR.getId(); | ||||||
| 	 | 	 | ||||||
| 	// iConomy information | 	// Economy information | ||||||
| 	private int useCost = -1; | 	private int useCost = -1; | ||||||
| 	private int createCost = -1; | 	private int createCost = -1; | ||||||
| 	private int destroyCost = -1; | 	private int destroyCost = -1; | ||||||
| @@ -228,17 +228,17 @@ public class Gate { | |||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public int getUseCost() { | 	public int getUseCost() { | ||||||
| 		if (useCost < 0) return iConomyHandler.useCost; | 		if (useCost < 0) return EconomyHandler.useCost; | ||||||
| 		return useCost; | 		return useCost; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public Integer getCreateCost() { | 	public Integer getCreateCost() { | ||||||
| 		if (createCost < 0) return iConomyHandler.createCost; | 		if (createCost < 0) return EconomyHandler.createCost; | ||||||
| 		return createCost; | 		return createCost; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public Integer getDestroyCost() { | 	public Integer getDestroyCost() { | ||||||
| 		if (destroyCost < 0) return iConomyHandler.destroyCost; | 		if (destroyCost < 0) return EconomyHandler.destroyCost; | ||||||
| 		return destroyCost; | 		return destroyCost; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| @@ -404,7 +404,7 @@ public class Gate { | |||||||
| 		gate.useCost = readConfig(config, gate, file, "usecost", -1); | 		gate.useCost = readConfig(config, gate, file, "usecost", -1); | ||||||
| 		gate.destroyCost = readConfig(config, gate, file, "destroycost", -1); | 		gate.destroyCost = readConfig(config, gate, file, "destroycost", -1); | ||||||
| 		gate.createCost = readConfig(config, gate, file, "createcost", -1); | 		gate.createCost = readConfig(config, gate, file, "createcost", -1); | ||||||
| 		gate.toOwner = (config.containsKey("toowner") ? Boolean.valueOf(config.get("toowner")) : iConomyHandler.toOwner); | 		gate.toOwner = (config.containsKey("toowner") ? Boolean.valueOf(config.get("toowner")) : EconomyHandler.toOwner); | ||||||
|  |  | ||||||
| 		if (gate.getControls().length != 2) { | 		if (gate.getControls().length != 2) { | ||||||
| 			Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points."); | 			Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points."); | ||||||
|   | |||||||
| @@ -731,7 +731,7 @@ public class Portal { | |||||||
| 			} else { | 			} else { | ||||||
| 				int index = destinations.indexOf(destination); | 				int index = destinations.indexOf(destination); | ||||||
| 				if ((index == max) && (max > 1) && (++done <= 3)) { | 				if ((index == max) && (max > 1) && (++done <= 3)) { | ||||||
| 					if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { | 					if (EconomyHandler.useEconomy() && EconomyHandler.freeGatesGreen) { | ||||||
| 						Portal dest = Portal.getByName(destinations.get(index - 2), network); | 						Portal dest = Portal.getByName(destinations.get(index - 2), network); | ||||||
| 						boolean green = Stargate.isFree(activePlayer, this, dest); | 						boolean green = Stargate.isFree(activePlayer, this, dest); | ||||||
| 						Stargate.setLine(sign, done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 2)); | 						Stargate.setLine(sign, done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 2)); | ||||||
| @@ -740,7 +740,7 @@ public class Portal { | |||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 				if ((index > 0) && (++done <= 3)) { | 				if ((index > 0) && (++done <= 3)) { | ||||||
| 					if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { | 					if (EconomyHandler.useEconomy() && EconomyHandler.freeGatesGreen) { | ||||||
| 						Portal dest = Portal.getByName(destinations.get(index - 1), network); | 						Portal dest = Portal.getByName(destinations.get(index - 1), network); | ||||||
| 						boolean green = Stargate.isFree(activePlayer, this, dest); | 						boolean green = Stargate.isFree(activePlayer, this, dest); | ||||||
| 						Stargate.setLine(sign, done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 1)); | 						Stargate.setLine(sign, done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 1)); | ||||||
| @@ -749,7 +749,7 @@ public class Portal { | |||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 				if (++done <= 3) { | 				if (++done <= 3) { | ||||||
| 					if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { | 					if (EconomyHandler.useEconomy() && EconomyHandler.freeGatesGreen) { | ||||||
| 						Portal dest = Portal.getByName(destination, network); | 						Portal dest = Portal.getByName(destination, network); | ||||||
| 						boolean green = Stargate.isFree(activePlayer, this, dest); | 						boolean green = Stargate.isFree(activePlayer, this, dest); | ||||||
| 						Stargate.setLine(sign, done, (green ? ChatColor.DARK_GREEN : "") + ">" + destination + "<"); | 						Stargate.setLine(sign, done, (green ? ChatColor.DARK_GREEN : "") + ">" + destination + "<"); | ||||||
| @@ -758,7 +758,7 @@ public class Portal { | |||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 				if ((max >= index + 1) && (++done <= 3)) { | 				if ((max >= index + 1) && (++done <= 3)) { | ||||||
| 					if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { | 					if (EconomyHandler.useEconomy() && EconomyHandler.freeGatesGreen) { | ||||||
| 						Portal dest = Portal.getByName(destinations.get(index + 1), network); | 						Portal dest = Portal.getByName(destinations.get(index + 1), network); | ||||||
| 						boolean green = Stargate.isFree(activePlayer, this, dest); | 						boolean green = Stargate.isFree(activePlayer, this, dest); | ||||||
| 						Stargate.setLine(sign, done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 1)); | 						Stargate.setLine(sign, done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 1)); | ||||||
| @@ -767,7 +767,7 @@ public class Portal { | |||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 				if ((max >= index + 2) && (++done <= 3)) { | 				if ((max >= index + 2) && (++done <= 3)) { | ||||||
| 					if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { | 					if (EconomyHandler.useEconomy() && EconomyHandler.freeGatesGreen) { | ||||||
| 						Portal dest = Portal.getByName(destinations.get(index + 2), network); | 						Portal dest = Portal.getByName(destinations.get(index + 2), network); | ||||||
| 						boolean green = Stargate.isFree(activePlayer, this, dest); | 						boolean green = Stargate.isFree(activePlayer, this, dest); | ||||||
| 						Stargate.setLine(sign, done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 2)); | 						Stargate.setLine(sign, done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 2)); | ||||||
| @@ -1128,13 +1128,13 @@ public class Portal { | |||||||
| 		if (cost > 0) { | 		if (cost > 0) { | ||||||
| 			if (!Stargate.chargePlayer(player, null, cost)) { | 			if (!Stargate.chargePlayer(player, null, cost)) { | ||||||
| 				String inFundMsg = Stargate.getString("ecoInFunds"); | 				String inFundMsg = Stargate.getString("ecoInFunds"); | ||||||
| 				inFundMsg = Stargate.replaceVars(inFundMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), name}); | 				inFundMsg = Stargate.replaceVars(inFundMsg, new String[] {"%cost%", "%portal%"}, new String[] {EconomyHandler.format(cost), name}); | ||||||
| 				Stargate.sendMessage(player, inFundMsg); | 				Stargate.sendMessage(player, inFundMsg); | ||||||
| 				Stargate.debug("createPortal", "Insufficient Funds"); | 				Stargate.debug("createPortal", "Insufficient Funds"); | ||||||
| 				return null; | 				return null; | ||||||
| 			} | 			} | ||||||
| 			String deductMsg = Stargate.getString("ecoDeduct"); | 			String deductMsg = Stargate.getString("ecoDeduct"); | ||||||
| 			deductMsg = Stargate.replaceVars(deductMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), name}); | 			deductMsg = Stargate.replaceVars(deductMsg, new String[] {"%cost%", "%portal%"}, new String[] {EconomyHandler.format(cost), name}); | ||||||
| 			Stargate.sendMessage(player, deductMsg, false); | 			Stargate.sendMessage(player, deductMsg, false); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
|   | |||||||
| @@ -31,7 +31,6 @@ import org.bukkit.configuration.file.FileConfiguration; | |||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| import org.bukkit.entity.Vehicle; | import org.bukkit.entity.Vehicle; | ||||||
| import org.bukkit.event.Event; |  | ||||||
| import org.bukkit.event.Event.Result; | import org.bukkit.event.Event.Result; | ||||||
| import org.bukkit.event.EventHandler; | import org.bukkit.event.EventHandler; | ||||||
| import org.bukkit.event.EventPriority; | import org.bukkit.event.EventPriority; | ||||||
| @@ -163,12 +162,10 @@ public class Stargate extends JavaPlugin { | |||||||
| 		this.migrate(); | 		this.migrate(); | ||||||
| 		this.reloadGates(); | 		this.reloadGates(); | ||||||
| 		 | 		 | ||||||
| 		// Check to see if iConomy is loaded yet. | 		// Check to see if Economy is loaded yet. | ||||||
| 		if (iConomyHandler.setupeConomy(pm)) { | 		if (EconomyHandler.setupEconomy(pm)) { | ||||||
| 			if (iConomyHandler.register != null) | 			if (EconomyHandler.economy != null) | ||||||
| 				log.info("[Stargate] Register v" + iConomyHandler.register.getDescription().getVersion() + " found"); | 				log.info("[Stargate] Vault v" + EconomyHandler.vault.getDescription().getVersion() + " found"); | ||||||
| 			if (iConomyHandler.economy != null) |  | ||||||
| 				log.info("[Stargate] Vault v" + iConomyHandler.vault.getDescription().getVersion() + " found"); |  | ||||||
|         } |         } | ||||||
| 		 | 		 | ||||||
| 		getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L); | 		getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L); | ||||||
| @@ -218,14 +215,14 @@ public class Stargate extends JavaPlugin { | |||||||
| 		// Debug | 		// Debug | ||||||
| 		debug = newConfig.getBoolean("debug"); | 		debug = newConfig.getBoolean("debug"); | ||||||
| 		permDebug = newConfig.getBoolean("permdebug"); | 		permDebug = newConfig.getBoolean("permdebug"); | ||||||
| 		// iConomy | 		// Economy | ||||||
| 		iConomyHandler.useiConomy = newConfig.getBoolean("useiconomy"); | 		EconomyHandler.economyEnabled = newConfig.getBoolean("useeconomy"); | ||||||
| 		iConomyHandler.createCost = newConfig.getInt("createcost"); | 		EconomyHandler.createCost = newConfig.getInt("createcost"); | ||||||
| 		iConomyHandler.destroyCost = newConfig.getInt("destroycost"); | 		EconomyHandler.destroyCost = newConfig.getInt("destroycost"); | ||||||
| 		iConomyHandler.useCost = newConfig.getInt("usecost"); | 		EconomyHandler.useCost = newConfig.getInt("usecost"); | ||||||
| 		iConomyHandler.toOwner = newConfig.getBoolean("toowner"); | 		EconomyHandler.toOwner = newConfig.getBoolean("toowner"); | ||||||
| 		iConomyHandler.chargeFreeDestination = newConfig.getBoolean("chargefreedestination"); | 		EconomyHandler.chargeFreeDestination = newConfig.getBoolean("chargefreedestination"); | ||||||
| 		iConomyHandler.freeGatesGreen = newConfig.getBoolean("freegatesgreen"); | 		EconomyHandler.freeGatesGreen = newConfig.getBoolean("freegatesgreen"); | ||||||
| 		 | 		 | ||||||
| 		this.saveConfig(); | 		this.saveConfig(); | ||||||
| 	} | 	} | ||||||
| @@ -460,7 +457,7 @@ public class Stargate extends JavaPlugin { | |||||||
| 		// Player gets free use | 		// Player gets free use | ||||||
| 		if (hasPerm(player, "stargate.free") || Stargate.hasPerm(player,  "stargate.free.use")) return true; | 		if (hasPerm(player, "stargate.free") || Stargate.hasPerm(player,  "stargate.free.use")) return true; | ||||||
| 		// Don't charge for free destination gates | 		// Don't charge for free destination gates | ||||||
| 		if (dest != null && !iConomyHandler.chargeFreeDestination && dest.isFree()) return true; | 		if (dest != null && !EconomyHandler.chargeFreeDestination && dest.isFree()) return true; | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| @@ -572,22 +569,22 @@ public class Stargate extends JavaPlugin { | |||||||
| 	public static boolean chargePlayer(Player player, String target, 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 | 		// Economy is disabled | ||||||
| 		if (!iConomyHandler.useiConomy()) return true; | 		if (!EconomyHandler.useEconomy()) return true; | ||||||
| 		// Charge player | 		// Charge player | ||||||
| 		return iConomyHandler.chargePlayer(player.getName(), target, cost); | 		return EconomyHandler.chargePlayer(player.getName(), target, cost); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	/* | 	/* | ||||||
| 	 * Determine the cost of a gate | 	 * Determine the cost of a gate | ||||||
| 	 */ | 	 */ | ||||||
| 	public static int getUseCost(Player player, Portal src, Portal dest) { | 	public static int getUseCost(Player player, Portal src, Portal dest) { | ||||||
| 		// Not using iConomy | 		// Not using Economy | ||||||
| 		if (!iConomyHandler.useiConomy()) return 0; | 		if (!EconomyHandler.useEconomy()) return 0; | ||||||
| 		// Portal is free | 		// Portal is free | ||||||
| 		if (src.isFree()) return 0; | 		if (src.isFree()) return 0; | ||||||
| 		// Not charging for free destinations | 		// Not charging for free destinations | ||||||
| 		if (dest != null && !iConomyHandler.chargeFreeDestination && dest.isFree()) return 0; | 		if (dest != null && !EconomyHandler.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 | 		// Player gets free gate use | ||||||
| @@ -600,8 +597,8 @@ public class Stargate extends JavaPlugin { | |||||||
| 	 * Determine the cost to create the gate | 	 * Determine the cost to create the gate | ||||||
| 	 */ | 	 */ | ||||||
| 	public static int getCreateCost(Player player, Gate gate) { | 	public static int getCreateCost(Player player, Gate gate) { | ||||||
| 		// Not using iConomy | 		// Not using Economy | ||||||
| 		if (!iConomyHandler.useiConomy()) return 0; | 		if (!EconomyHandler.useEconomy()) return 0; | ||||||
| 		// Player gets free gate destruction | 		// Player gets free gate destruction | ||||||
| 		if (hasPerm(player, "stargate.free") || hasPerm(player, "stargate.free.create")) return 0; | 		if (hasPerm(player, "stargate.free") || hasPerm(player, "stargate.free.create")) return 0; | ||||||
| 		 | 		 | ||||||
| @@ -612,8 +609,8 @@ public class Stargate extends JavaPlugin { | |||||||
| 	 * Determine the cost to destroy the gate | 	 * Determine the cost to destroy the gate | ||||||
| 	 */ | 	 */ | ||||||
| 	public static int getDestroyCost(Player player, Gate gate) { | 	public static int getDestroyCost(Player player, Gate gate) { | ||||||
| 		// Not using iConomy | 		// Not using Economy | ||||||
| 		if (!iConomyHandler.useiConomy()) return 0; | 		if (!EconomyHandler.useEconomy()) return 0; | ||||||
| 		// Player gets free gate destruction | 		// Player gets free gate destruction | ||||||
| 		if (hasPerm(player, "stargate.free") || hasPerm(player, "stargate.free.destroy")) return 0; | 		if (hasPerm(player, "stargate.free") || hasPerm(player, "stargate.free.destroy")) return 0; | ||||||
| 		 | 		 | ||||||
| @@ -696,13 +693,13 @@ public class Stargate extends JavaPlugin { | |||||||
| 						return; | 						return; | ||||||
| 					} | 					} | ||||||
| 					String deductMsg = Stargate.getString("ecoDeduct"); | 					String deductMsg = Stargate.getString("ecoDeduct"); | ||||||
| 					deductMsg = Stargate.replaceVars(deductMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), portal.getName()}); | 					deductMsg = Stargate.replaceVars(deductMsg, new String[] {"%cost%", "%portal%"}, new String[] {EconomyHandler.format(cost), portal.getName()}); | ||||||
| 					sendMessage(player, deductMsg, false); | 					sendMessage(player, deductMsg, false); | ||||||
| 					if (target != null) { | 					if (target != null) { | ||||||
| 						Player p = server.getPlayer(target); | 						Player p = server.getPlayer(target); | ||||||
| 						if (p != null) { | 						if (p != null) { | ||||||
| 							String obtainedMsg = Stargate.getString("ecoObtain"); | 							String obtainedMsg = Stargate.getString("ecoObtain"); | ||||||
| 							obtainedMsg = Stargate.replaceVars(obtainedMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), portal.getName()}); | 							obtainedMsg = Stargate.replaceVars(obtainedMsg, new String[] {"%cost%", "%portal%"}, new String[] {EconomyHandler.format(cost), portal.getName()}); | ||||||
| 							Stargate.sendMessage(p, obtainedMsg, false); | 							Stargate.sendMessage(p, obtainedMsg, false); | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
| @@ -825,13 +822,13 @@ public class Stargate extends JavaPlugin { | |||||||
| 					return; | 					return; | ||||||
| 				} | 				} | ||||||
| 				String deductMsg = Stargate.getString("ecoDeduct"); | 				String deductMsg = Stargate.getString("ecoDeduct"); | ||||||
| 				deductMsg = Stargate.replaceVars(deductMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), portal.getName()}); | 				deductMsg = Stargate.replaceVars(deductMsg, new String[] {"%cost%", "%portal%"}, new String[] {EconomyHandler.format(cost), portal.getName()}); | ||||||
| 				sendMessage(player, deductMsg, false); | 				sendMessage(player, deductMsg, false); | ||||||
| 				if (target != null) { | 				if (target != null) { | ||||||
| 					Player p = server.getPlayer(target); | 					Player p = server.getPlayer(target); | ||||||
| 					if (p != null) { | 					if (p != null) { | ||||||
| 						String obtainedMsg = Stargate.getString("ecoObtain"); | 						String obtainedMsg = Stargate.getString("ecoObtain"); | ||||||
| 						obtainedMsg = Stargate.replaceVars(obtainedMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), portal.getName()}); | 						obtainedMsg = Stargate.replaceVars(obtainedMsg, new String[] {"%cost%", "%portal%"}, new String[] {EconomyHandler.format(cost), portal.getName()}); | ||||||
| 						Stargate.sendMessage(p, obtainedMsg, false); | 						Stargate.sendMessage(p, obtainedMsg, false); | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| @@ -1084,11 +1081,11 @@ public class Stargate extends JavaPlugin { | |||||||
| 				 | 				 | ||||||
| 				if (cost > 0) { | 				if (cost > 0) { | ||||||
| 					String deductMsg = Stargate.getString("ecoDeduct"); | 					String deductMsg = Stargate.getString("ecoDeduct"); | ||||||
| 					deductMsg = Stargate.replaceVars(deductMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(cost), portal.getName()}); | 					deductMsg = Stargate.replaceVars(deductMsg, new String[] {"%cost%", "%portal%"}, new String[] {EconomyHandler.format(cost), portal.getName()}); | ||||||
| 					sendMessage(player, deductMsg, false); | 					sendMessage(player, deductMsg, false); | ||||||
| 				} else if (cost < 0) { | 				} else if (cost < 0) { | ||||||
| 					String refundMsg = Stargate.getString("ecoRefund"); | 					String refundMsg = Stargate.getString("ecoRefund"); | ||||||
| 					refundMsg = Stargate.replaceVars(refundMsg, new String[] {"%cost%", "%portal%"}, new String[] {iConomyHandler.format(-cost), portal.getName()}); | 					refundMsg = Stargate.replaceVars(refundMsg, new String[] {"%cost%", "%portal%"}, new String[] {EconomyHandler.format(-cost), portal.getName()}); | ||||||
| 					sendMessage(player, refundMsg, false); | 					sendMessage(player, refundMsg, false); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| @@ -1274,18 +1271,15 @@ public class Stargate extends JavaPlugin { | |||||||
| 	private class sListener implements Listener { | 	private class sListener implements Listener { | ||||||
| 		@EventHandler | 		@EventHandler | ||||||
| 		public void onPluginEnable(PluginEnableEvent event) { | 		public void onPluginEnable(PluginEnableEvent event) { | ||||||
| 			if (iConomyHandler.setupRegister(event.getPlugin())) { | 			if (EconomyHandler.setupEconomy(getServer().getPluginManager())) { | ||||||
| 				log.info("[Stargate] Register v" + iConomyHandler.register.getDescription().getVersion() + " found"); | 				log.info("[Stargate] Vault v" + EconomyHandler.vault.getDescription().getVersion() + " found"); | ||||||
| 			} |  | ||||||
| 			if (iConomyHandler.setupVault(event.getPlugin())) { |  | ||||||
| 				log.info("[Stargate] Vault v" + iConomyHandler.vault.getDescription().getVersion() + " found"); |  | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		@EventHandler | 		@EventHandler | ||||||
| 		public void onPluginDisable(PluginDisableEvent event) { | 		public void onPluginDisable(PluginDisableEvent event) { | ||||||
| 			if (iConomyHandler.checkLost(event.getPlugin())) { | 			if (event.getPlugin().equals(EconomyHandler.vault)) { | ||||||
| 				log.info("[Stargate] Register/Vault plugin lost."); | 				log.info("[Stargate] Vault plugin lost."); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @@ -1369,19 +1363,16 @@ public class Stargate extends JavaPlugin { | |||||||
| 				lang.setLang(langName); | 				lang.setLang(langName); | ||||||
| 				lang.reload(); | 				lang.reload(); | ||||||
| 				 | 				 | ||||||
| 				// Load iConomy support if enabled/clear if disabled | 				// Load Economy support if enabled/clear if disabled | ||||||
| 				if (iConomyHandler.useiConomy && iConomyHandler.register == null && iConomyHandler.economy == null) { | 				if (EconomyHandler.economyEnabled && EconomyHandler.economy == null) { | ||||||
| 					if (iConomyHandler.setupeConomy(pm)) { | 					if (EconomyHandler.setupEconomy(pm)) { | ||||||
| 						if (iConomyHandler.register != null) | 						if (EconomyHandler.economy != null) | ||||||
| 							log.info("[Stargate] Register v" + iConomyHandler.register.getDescription().getVersion() + " found"); | 							log.info("[Stargate] Vault v" + EconomyHandler.vault.getDescription().getVersion() + " found"); | ||||||
| 						if (iConomyHandler.economy != null) |  | ||||||
| 							log.info("[Stargate] Vault v" + iConomyHandler.vault.getDescription().getVersion() + " found"); |  | ||||||
| 			        } | 			        } | ||||||
| 				} | 				} | ||||||
| 				if (!iConomyHandler.useiConomy) { | 				if (!EconomyHandler.economyEnabled) { | ||||||
| 					iConomyHandler.vault = null; | 					EconomyHandler.vault = null; | ||||||
| 					iConomyHandler.register = null; | 					EconomyHandler.economy = null; | ||||||
| 					iConomyHandler.economy = null; |  | ||||||
| 				} | 				} | ||||||
| 				 | 				 | ||||||
| 				// Enable the required channels for Bungee support | 				// Enable the required channels for Bungee support | ||||||
|   | |||||||
| @@ -1,181 +0,0 @@ | |||||||
| package net.TheDgtl.Stargate; |  | ||||||
|  |  | ||||||
| import net.milkbowl.vault.Vault; |  | ||||||
| import net.milkbowl.vault.economy.Economy; |  | ||||||
|  |  | ||||||
| import org.bukkit.plugin.Plugin; |  | ||||||
| import org.bukkit.plugin.PluginManager; |  | ||||||
| import org.bukkit.plugin.RegisteredServiceProvider; |  | ||||||
|  |  | ||||||
| import com.nijikokun.register.Register; |  | ||||||
| import com.nijikokun.register.payment.Method; |  | ||||||
| import com.nijikokun.register.payment.Method.MethodAccount; |  | ||||||
| import com.nijikokun.register.payment.Methods; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Stargate - A portal plugin for Bukkit |  | ||||||
|  * Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net> |  | ||||||
|  *  |  | ||||||
|  * This program is free software: you can redistribute it and/or modify |  | ||||||
|  * it under the terms of the GNU Lesser General Public License as published by |  | ||||||
|  * the Free Software Foundation, either version 3 of the License, or |  | ||||||
|  * (at your option) any later version. |  | ||||||
|  *  |  | ||||||
|  * This program is distributed in the hope that it will be useful, |  | ||||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | ||||||
|  * GNU Lesser General Public License for more details. |  | ||||||
|  * |  | ||||||
|  * You should have received a copy of the GNU Lesser General Public License |  | ||||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| public class iConomyHandler { |  | ||||||
| 	public static boolean useiConomy = false; |  | ||||||
| 	public static Register register = null; |  | ||||||
| 	public static Vault vault = null; |  | ||||||
| 	public static Economy economy = null; |  | ||||||
| 	 |  | ||||||
| 	public static int useCost = 0; |  | ||||||
| 	public static int createCost = 0; |  | ||||||
| 	public static int destroyCost = 0; |  | ||||||
| 	public static boolean toOwner = false; |  | ||||||
| 	public static boolean chargeFreeDestination = true; |  | ||||||
| 	public static boolean freeGatesGreen = false; |  | ||||||
| 	 |  | ||||||
| 	public static double getBalance(String player) { |  | ||||||
| 		if (!useiConomy) return 0; |  | ||||||
| 		if (economy != null) { |  | ||||||
| 			return economy.getBalance(player); |  | ||||||
| 		} |  | ||||||
| 		if (register != null) { |  | ||||||
| 			Method method = Methods.getMethod(); |  | ||||||
| 			if (method == null) { |  | ||||||
| 				return 0; |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			MethodAccount acc = method.getAccount(player); |  | ||||||
| 			if (acc == null) { |  | ||||||
| 				Stargate.debug("ich::getBalance", "Error fetching Register account for " + player); |  | ||||||
| 				return 0; |  | ||||||
| 			} |  | ||||||
| 			return acc.balance(); |  | ||||||
| 		} |  | ||||||
| 		return 0; |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	public static boolean chargePlayer(String player, String target, double amount) { |  | ||||||
| 		if (!useiConomy) return true; |  | ||||||
| 		if (economy != null) { |  | ||||||
| 			if (player.equals(target)) return true; |  | ||||||
| 			 |  | ||||||
| 			if (!economy.has(player, amount)) return false; |  | ||||||
| 			economy.withdrawPlayer(player, amount); |  | ||||||
| 			 |  | ||||||
| 			if (target != null) { |  | ||||||
| 				economy.depositPlayer(target, amount); |  | ||||||
| 			} |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		if (register != null) { |  | ||||||
| 			// Check for a payment method |  | ||||||
| 			Method method = Methods.getMethod(); |  | ||||||
| 			if (method == null) { |  | ||||||
| 				return true; |  | ||||||
| 			} |  | ||||||
| 			// No point going from a player to themself |  | ||||||
| 			if (player.equals(target)) return true; |  | ||||||
| 			 |  | ||||||
| 			MethodAccount acc = method.getAccount(player); |  | ||||||
| 			if (acc == null) { |  | ||||||
| 				Stargate.debug("ich::chargePlayer", "Error fetching Register account for " + player); |  | ||||||
| 				return false; |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			if (!acc.hasEnough(amount)) return false; |  | ||||||
| 			acc.subtract(amount); |  | ||||||
| 			 |  | ||||||
| 			if (target != null) { |  | ||||||
| 				MethodAccount tAcc = method.getAccount(target); |  | ||||||
| 				if (tAcc != null) { |  | ||||||
| 					tAcc.add(amount); |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
| 		return true; |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	public static boolean useiConomy() { |  | ||||||
| 		if (!useiConomy) return false; |  | ||||||
| 		if (economy != null) return true; |  | ||||||
| 		if (register != null && Methods.getMethod() != null) return true; |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	public static String format(int amt) { |  | ||||||
| 		if (economy != null) { |  | ||||||
| 			return economy.format(amt); |  | ||||||
| 		} |  | ||||||
| 		if (register != null) { |  | ||||||
| 			Method method = Methods.getMethod(); |  | ||||||
| 			if (method == null) { |  | ||||||
| 				return Integer.toString(amt); |  | ||||||
| 			} |  | ||||||
| 			return method.format(amt); |  | ||||||
| 		} |  | ||||||
| 		return ""; |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	public static boolean setupeConomy(PluginManager pm) { |  | ||||||
| 		if (!useiConomy) return false; |  | ||||||
| 		// Check for Vault |  | ||||||
| 		Plugin p = pm.getPlugin("Vault"); |  | ||||||
| 		if (p != null) |  | ||||||
| 			return setupVault(p); |  | ||||||
| 		// Check for Register |  | ||||||
| 		p = pm.getPlugin("Register"); |  | ||||||
| 		if (p != null) |  | ||||||
| 			return setupRegister(p); |  | ||||||
| 		 |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	public static boolean setupVault(Plugin p) { |  | ||||||
| 		if (!useiConomy) return false; |  | ||||||
| 		if (register != null) return false; |  | ||||||
| 		if (p == null || !p.isEnabled()) return false; |  | ||||||
| 		if (!p.getDescription().getName().equals("Vault")) return false; |  | ||||||
| 		 |  | ||||||
| 		RegisteredServiceProvider<Economy> economyProvider = Stargate.server.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); |  | ||||||
|         if (economyProvider != null) { |  | ||||||
|         	vault = (Vault)p; |  | ||||||
|             economy = economyProvider.getProvider(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return (economy != null); |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	public static boolean setupRegister(Plugin p) { |  | ||||||
| 		if (!useiConomy) return false; |  | ||||||
| 		if (vault != null) return false; |  | ||||||
| 		if (p == null || !p.isEnabled()) return false; |  | ||||||
| 		if (!p.getDescription().getName().equals("Register")) return false; |  | ||||||
| 		register = (Register)p; |  | ||||||
| 		return true; |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	public static boolean checkLost(Plugin p) { |  | ||||||
| 		if (p.equals(register)) { |  | ||||||
| 			register = null; |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
| 		if (p.equals(vault)) { |  | ||||||
| 			economy = null; |  | ||||||
| 			vault = null; |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user
	 PseudoKnight
					PseudoKnight