From d22a4b08714698a325d85508e693dd81a2329f4a Mon Sep 17 00:00:00 2001 From: Drakia Date: Sat, 7 May 2011 13:13:21 -0700 Subject: [PATCH] Added chargefreedestination option Added freegatesgreen option Thanks @jtojnar --- README | 6 +++ src/net/TheDgtl/Stargate/Portal.java | 47 +++++++++++++++++--- src/net/TheDgtl/Stargate/Stargate.java | 15 +++++-- src/net/TheDgtl/Stargate/iConomyHandler.java | 2 + src/plugin.yml | 2 +- 5 files changed, 62 insertions(+), 10 deletions(-) diff --git a/README b/README index 61c940b..1af3fc4 100644 --- a/README +++ b/README @@ -118,6 +118,8 @@ useiconomy - Whether or not to use iConomy createcost - The cost to create a stargate destroycost - The cost to destroy a stargate (Can be negative for a "refund" usecost - The cost to use a stargate +chargefreedestination - Enable to allow free travel from any gate to a free gate +freegatesgreen - Enable to make gates that won't cost the player money show up as green not-enough-money-message - The message displayed if a player lacks money to do something networkfilter - Whether or not to disallow users access to a network if they don't have the 'stargate.network.{networkname}' permission. worldfilter - Whether or not to disallow users access to a network if they don't have the 'stargate.world.{worldname}' permission. @@ -127,9 +129,13 @@ debug - Whether to show massive debug output for gate creation ============= Changes ============= +[Version 0.4.8] + - Added chargefreedestination option + - Added freegatesgreen option [Version 0.4.7] - Added debug option - Fixed gates will now show in the list of gates they link to. + - iConomy no longer touched if not enabled in config [Version 0.4.6] - Fixed a bug in iConomy handling. [Version 0.4.5] diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index 3300558..90f1b68 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -122,6 +122,13 @@ public class Portal { public boolean isFree() { return free; } + + public boolean isFree(Player player, Portal dest) { + // This gate is free, the player gets all gates free, or we don't charge for free dest and dest is free + boolean isFree = isFree() || Stargate.hasPerm(player, "stargate.free.use", player.isOp()) || + (!iConomyHandler.chargeFreeDestination && dest.isFree()); + return isFree; + } public boolean open(boolean force) { return open(null, force); @@ -424,19 +431,49 @@ public class Portal { int index = destinations.indexOf(destination); if ((index == max) && (max > 1) && (++done <= 3)) { - id.setText(done, destinations.get(index - 2)); + if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { + Portal dest = Portal.getByName(destinations.get(index - 2), network); + boolean green = isFree(activePlayer, dest); + id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 2)); + } else { + id.setText(done, destinations.get(index - 2)); + } } if ((index > 0) && (++done <= 3)) { - id.setText(done, destinations.get(index - 1)); + if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { + Portal dest = Portal.getByName(destinations.get(index - 1), network); + boolean green = isFree(activePlayer, dest); + id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 1)); + } else { + id.setText(done, destinations.get(index - 1)); + } } if (++done <= 3) { - id.setText(done, " >" + destination + "< "); + if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { + Portal dest = Portal.getByName(destination, network); + boolean green = isFree(activePlayer, dest); + id.setText(done, (green ? ChatColor.DARK_GREEN : "") + " >" + destination + "< "); + } else { + id.setText(done, " >" + destination + "< "); + } } if ((max >= index + 1) && (++done <= 3)) { - id.setText(done, destinations.get(index + 1)); + if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { + Portal dest = Portal.getByName(destinations.get(index + 1), network); + boolean green = isFree(activePlayer, dest); + id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 1)); + } else { + id.setText(done, destinations.get(index + 1)); + } } if ((max >= index + 2) && (++done <= 3)) { - id.setText(done, destinations.get(index + 2)); + if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { + Portal dest = Portal.getByName(destinations.get(index + 2), network); + boolean green = isFree(activePlayer, dest); + id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 2)); + } else { + id.setText(done, destinations.get(index + 2)); + } } } } diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index 05ce3bd..1becebe 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -164,6 +164,8 @@ public class Stargate extends JavaPlugin { iConomyHandler.useCost = config.getInt("usecost", iConomyHandler.useCost); iConomyHandler.inFundMsg = config.getString("not-enough-money-message", iConomyHandler.inFundMsg); iConomyHandler.toOwner = config.getBoolean("toowner", iConomyHandler.toOwner); + iConomyHandler.chargeFreeDestination = config.getBoolean("chargefreedestination", iConomyHandler.chargeFreeDestination); + iConomyHandler.freeGatesGreen = config.getBoolean("freegatesgreen", iConomyHandler.freeGatesGreen); saveConfig(); } @@ -188,6 +190,8 @@ public class Stargate extends JavaPlugin { config.setProperty("usecost", iConomyHandler.useCost); config.setProperty("not-enough-money-message", iConomyHandler.inFundMsg); config.setProperty("toowner", iConomyHandler.toOwner); + config.setProperty("chargefreedestination", iConomyHandler.chargeFreeDestination); + config.setProperty("freegatesgreen", iConomyHandler.freeGatesGreen); config.save(); } @@ -253,10 +257,7 @@ public class Stargate extends JavaPlugin { Portal destination = gate.getDestination(); if (!gate.isOpen()) { - if (!gate.isFree() && !hasPerm(player, "stargate.free.use", player.isOp()) && - iConomyHandler.useiConomy() && iConomyHandler.getBalance(player.getName()) < gate.getGate().getUseCost()) { - player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg); - } else if ((!gate.isFixed()) && gate.isActive() && (gate.getActivePlayer() != player)) { + if ((!gate.isFixed()) && gate.isActive() && (gate.getActivePlayer() != player)) { gate.deactivate(); if (!denyMsg.isEmpty()) { player.sendMessage(ChatColor.RED + denyMsg); @@ -327,6 +328,9 @@ public class Stargate extends JavaPlugin { if (dest == null) return; boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp())); + if (!iConomyHandler.chargeFreeDestination) + iConCharge = iConCharge && !dest.isFree(); + String target = (portal.getGate().getToOwner() ? portal.getOwner() : null); if (target != null) iConCharge = iConCharge && !target.equals(player.getName()); @@ -388,6 +392,9 @@ public class Stargate extends JavaPlugin { } boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp())); + if (!iConomyHandler.chargeFreeDestination) + iConCharge = iConCharge && !destination.isFree(); + String target = (portal.getGate().getToOwner() ? portal.getOwner() : null); if (target != null) iConCharge = iConCharge && !target.equals(player.getName()); diff --git a/src/net/TheDgtl/Stargate/iConomyHandler.java b/src/net/TheDgtl/Stargate/iConomyHandler.java index cf891fe..d5b1016 100644 --- a/src/net/TheDgtl/Stargate/iConomyHandler.java +++ b/src/net/TheDgtl/Stargate/iConomyHandler.java @@ -14,6 +14,8 @@ public class iConomyHandler { public static int destroyCost = 0; public static String inFundMsg = "Insufficient Funds."; public static boolean toOwner = false; + public static boolean chargeFreeDestination = true; + public static boolean freeGatesGreen = false; public static double getBalance(String player) { if (useiConomy && iconomy != null) { diff --git a/src/plugin.yml b/src/plugin.yml index 9074a6f..9f0b997 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.4.7 +version: 0.4.8 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net