From 2d97b497d8e5a516d52e63823f0fb8f0cf4c79f1 Mon Sep 17 00:00:00 2001 From: Drakia Date: Fri, 8 Apr 2011 00:42:34 -0700 Subject: [PATCH] Carts with no player can now go through gates. You can set gates to send their cost to their owner. Cleaned up the iConomy code a bit, messages should only be shown on actual deduction now. Created separate 'stargate.free.{use/create/destroy}' permissions. --- README | 16 ++- src/net/TheDgtl/Stargate/Portal.java | 23 ++-- src/net/TheDgtl/Stargate/Stargate.java | 89 ++++++++------- src/net/TheDgtl/Stargate/iConomyHandler.java | 109 ++++++++++--------- src/plugin.yml | 2 +- 5 files changed, 133 insertions(+), 106 deletions(-) diff --git a/README b/README index c621470..b2af1f3 100644 --- a/README +++ b/README @@ -9,20 +9,21 @@ iConomy support added back in, only costs are create, destroy and use. ============= Known Issues ============= - - There are many bugs with portal material not showing properly. This is a bug I can not track down, and have no fix for at the moment. - +Hmm.. None? + ============= Permissions ============= - stargate.use - Allow this player/group to use stargates. - stargate.create - Allow this player/group to create new stargates. - stargate.create.personal - Allow this player/group to create new stargates on a network defined as their name. - - stargate.destroy - Allow this player/group to destroy existing stargates. (Deprecated) - stargate.destroy.all - Allow this player/group to destroy any existing stargate (Replaces stargate.destroy) - stargate.destroy.owner - Allow this player/group to destroy any stargate that they are the owner of. - stargate.hidden - Allow this player/group to see all hidden stargates. - stargate.private - Allow this player/group to use all private stargates. - - stargate.free - This player/group is not charged to use gates even if the gate has a cost. + - stargate.free.use - This player/group is not charged to use gates even if the gate has a cost. + - stargate.free.create - This player/group is not charged to create gates even if the gate has a cost. + - stargate.free.destroy - This player/group is not charged to destroy gates even if the gate has a cost. - stargate.world.{worldname} - Allow this user/group access to gates on the world {worldname} - stargate.network.{networkname} - Allow this user/group access to the network {networkname} @@ -115,10 +116,17 @@ usecost - The cost to use a stargate 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. +toowner - Whether the money from gate-use goes to the owner or nobody ============= Changes ============= +[Version 0.4.0] + - Carts with no player can now go through gates. + - You can set gates to send their cost to their owner. + - Per-gate layout option for "toOwner". + - Cleaned up the iConomy code a bit, messages should only be shown on actual deduction now. + - Created separate 'stargate.free.{use/create/destroy}' permissions. [Version 0.3.5] - Added 'stargate.world.*' permissions - Added 'stargate.network.*' permissions diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index cbf127c..dcbd0a6 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -24,6 +24,8 @@ 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) @@ -244,10 +246,10 @@ public class Portal { newVelocity.multiply(velocity); final Entity passenger = vehicle.getPassenger(); - vehicle.eject(); - vehicle.remove(); - final Minecart mc = exit.getWorld().spawnMinecart(exit); if (passenger != null) { + vehicle.eject(); + vehicle.remove(); + final Minecart mc = exit.getWorld().spawnMinecart(exit); passenger.teleport(exit); Stargate.server.getScheduler().scheduleSyncDelayedTask(Stargate.stargate, new Runnable() { public void run() { @@ -256,7 +258,8 @@ public class Portal { } }, 1); } else { - mc.setVelocity(newVelocity); + vehicle.teleport(exit); + vehicle.setVelocity(newVelocity); } } @@ -641,11 +644,15 @@ public class Portal { return null; } - if (iConomyHandler.useiConomy() && !Stargate.hasPerm(player, "stargate.free", player.isOp()) && !iConomyHandler.chargePlayer(player.getName(), null, gate.getCreateCost())) { - if (!iConomyHandler.inFundMsg.isEmpty()) { - player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg); + if (iConomyHandler.useiConomy() && !Stargate.hasPerm(player, "stargate.free.create", player.isOp())) { + if (!iConomyHandler.chargePlayer(player.getName(), null, gate.getCreateCost())) { + if (!iConomyHandler.inFundMsg.isEmpty()) { + player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg); + } + return null; } - return null; + if (gate.getCreateCost() > 0) + player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(gate.getCreateCost())); } Portal portal = null; diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index a825d43..8ca7496 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -119,9 +119,6 @@ public class Stargate extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); - //pm.registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener, Priority.Normal, this); - //pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); - //pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.VEHICLE_MOVE, vehicleListener, Priority.Normal, this); @@ -131,7 +128,7 @@ public class Stargate extends JavaPlugin { pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this); - // iConomy Loading + // Dependency Loading pm.registerEvent(Event.Type.PLUGIN_ENABLE, serverListener, Priority.Monitor, this); pm.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Priority.Monitor, this); @@ -158,6 +155,7 @@ public class Stargate extends JavaPlugin { iConomyHandler.destroyCost = config.getInt("destroycost", iConomyHandler.destroyCost); iConomyHandler.useCost = config.getInt("usecost", iConomyHandler.useCost); iConomyHandler.inFundMsg = config.getString("not-enough-money-message", iConomyHandler.inFundMsg); + iConomyHandler.toOwner = config.getBoolean("toowner", iConomyHandler.toOwner); saveConfig(); } @@ -181,6 +179,7 @@ public class Stargate extends JavaPlugin { config.setProperty("destroycost", iConomyHandler.destroyCost); config.setProperty("usecost", iConomyHandler.useCost); config.setProperty("not-enough-money-message", iConomyHandler.inFundMsg); + config.setProperty("toowner", iConomyHandler.toOwner); config.save(); } @@ -238,7 +237,7 @@ public class Stargate extends JavaPlugin { Portal destination = gate.getDestination(); if (!gate.isOpen()) { - if (!gate.isFree() && !hasPerm(player, "stargate.free", player.isOp()) && + 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)) { @@ -311,10 +310,15 @@ public class Stargate extends JavaPlugin { Portal dest = portal.getDestination(); if (dest == null) return; - if (portal.isFree() || !iConomyHandler.useiConomy() || hasPerm(player, "stargate.free", player.isOp()) || - iConomyHandler.chargePlayer(player.getName(), null, portal.getGate().getUseCost())) { - if (!portal.isFree() && iConomyHandler.useiConomy()) { + boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp())); + + if (!iConCharge || iConomyHandler.chargePlayer(player.getName(), portal.getOwner(), portal.getGate().getUseCost())) { + if (iConCharge && portal.getGate().getUseCost() > 0) { player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().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 (!teleMsg.isEmpty()) { player.sendMessage(ChatColor.BLUE + teleMsg); @@ -326,6 +330,10 @@ public class Stargate extends JavaPlugin { } } portal.close(false); + } else { + Portal dest = portal.getDestination(); + if (dest == null) return; + dest.teleport(vehicle, portal); } } } @@ -337,32 +345,38 @@ public class Stargate extends JavaPlugin { Portal portal = Portal.getByEntrance(event.getTo()); if ((portal != null) && (portal.isOpen())) { - if (portal.isOpenFor(player)) { - Portal destination = portal.getDestination(); - - if (destination != null) { - if (portal.isFree() || !iConomyHandler.useiConomy() || hasPerm(player, "stargate.free", player.isOp()) || - iConomyHandler.chargePlayer(player.getName(), null, portal.getGate().getUseCost())) { - if (!portal.isFree() && iConomyHandler.useiConomy()) { - player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(portal.getGate().getUseCost())); - } - if (!teleMsg.isEmpty()) { - player.sendMessage(ChatColor.BLUE + teleMsg); - } - - destination.teleport(player, portal, event); - } else { - if (!iConomyHandler.inFundMsg.isEmpty()) { - player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg); - } - } - portal.close(false); - } - } else { + if (!portal.isOpenFor(player)) { if (!denyMsg.isEmpty()) { player.sendMessage(ChatColor.RED + denyMsg); } + return; } + + Portal destination = portal.getDestination(); + if (destination == null) return; + + boolean iConCharge = (iConomyHandler.useiConomy() && !portal.isFree() && !hasPerm(player, "stargate.free.use", player.isOp())); + + if (!iConCharge || iConomyHandler.chargePlayer(player.getName(), portal.getOwner(), portal.getGate().getUseCost())) { + if (iConCharge && portal.getGate().getUseCost() > 0) { + player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().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 (!teleMsg.isEmpty()) { + player.sendMessage(ChatColor.BLUE + teleMsg); + } + + destination.teleport(player, portal, event); + } else { + if (!iConomyHandler.inFundMsg.isEmpty()) { + player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg); + } + } + portal.close(false); } } @@ -445,10 +459,7 @@ public class Stargate extends JavaPlugin { sign.setText(3, event.getLine(3)); Portal portal = Portal.createPortal(sign, player); if (portal == null) return; - - if (iConomyHandler.useiConomy()) { - player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(portal.getGate().getCreateCost())); - } + if (!regMsg.isEmpty()) { player.sendMessage(ChatColor.GREEN + regMsg); } @@ -476,15 +487,15 @@ public class Stargate extends JavaPlugin { if (hasPerm(player, "stargate.destroy", player.isOp()) || hasPerm(player, "stargate.destroy.all", player.isOp()) || ( portal.getOwner().equalsIgnoreCase(player.getName()) && hasPerm(player, "stargate.destroy.owner", false) )) { // Can't afford - if (iConomyHandler.useiConomy()) { - if(iConomyHandler.getBalance(player.getName()) < portal.getGate().getDestroyCost()) { + if (iConomyHandler.useiConomy() && !hasPerm(player, "stargate.free.destroy", player.isOp())) { + if (!iConomyHandler.chargePlayer(player.getName(), null, portal.getGate().getDestroyCost())) { if (!iConomyHandler.inFundMsg.isEmpty()) { player.sendMessage(ChatColor.RED + iConomyHandler.inFundMsg); - event.setCancelled(true); - return; } + event.setCancelled(true); + return; } - iConomyHandler.chargePlayer(player.getName(), null, portal.getGate().getDestroyCost()); + if (portal.getGate().getDestroyCost() > 0) { player.sendMessage(ChatColor.GREEN + "Deducted " + iConomy.getBank().format(portal.getGate().getDestroyCost())); } else if (portal.getGate().getDestroyCost() < 0) { diff --git a/src/net/TheDgtl/Stargate/iConomyHandler.java b/src/net/TheDgtl/Stargate/iConomyHandler.java index 52a35b8..4b98381 100644 --- a/src/net/TheDgtl/Stargate/iConomyHandler.java +++ b/src/net/TheDgtl/Stargate/iConomyHandler.java @@ -1,54 +1,55 @@ -package net.TheDgtl.Stargate; - -import com.nijiko.coelho.iConomy.iConomy; -import com.nijiko.coelho.iConomy.system.Account; - -public class iConomyHandler { - public static boolean useiConomy = false; - public static iConomy iconomy = null; - - public static int useCost = 0; - public static int createCost = 0; - public static int destroyCost = 0; - public static String inFundMsg = "Insufficient Funds."; - - public static double getBalance(String player) { - if (useiConomy && iconomy != null) { - Account acc = iConomy.getBank().getAccount(player); - if (acc == null) { - Stargate.log.info("[Stargate::ich::getBalance] Error fetching iConomy account for " + player); - return 0; - } - return acc.getBalance(); - } - return 0; - } - - public static boolean chargePlayer(String player, String target, double amount) { - if (useiConomy && iconomy != null) { - Account acc = iConomy.getBank().getAccount(player); - if (acc == null) { - Stargate.log.info("[Stargate::ich::chargePlayer] Error fetching iConomy account for " + player); - return false; - } - double balance = acc.getBalance(); - - if (balance < amount) return false; - acc.setBalance(balance - amount); - - if (target != null) { - Account tAcc = iConomy.getBank().getAccount(target); - if (tAcc != null) { - balance = tAcc.getBalance(); - tAcc.setBalance(balance + amount); - } - } - return true; - } - return true; - } - - public static boolean useiConomy() { - return (useiConomy && iconomy != null); - } -} +package net.TheDgtl.Stargate; + +import com.nijiko.coelho.iConomy.iConomy; +import com.nijiko.coelho.iConomy.system.Account; + +public class iConomyHandler { + public static boolean useiConomy = false; + public static iConomy iconomy = null; + + public static int useCost = 0; + public static int createCost = 0; + public static int destroyCost = 0; + public static String inFundMsg = "Insufficient Funds."; + public static boolean toOwner = false; + + public static double getBalance(String player) { + if (useiConomy && iconomy != null) { + Account acc = iConomy.getBank().getAccount(player); + if (acc == null) { + Stargate.log.info("[Stargate::ich::getBalance] Error fetching iConomy account for " + player); + return 0; + } + return acc.getBalance(); + } + return 0; + } + + public static boolean chargePlayer(String player, String target, double amount) { + if (useiConomy && iconomy != null) { + Account acc = iConomy.getBank().getAccount(player); + if (acc == null) { + Stargate.log.info("[Stargate::ich::chargePlayer] Error fetching iConomy account for " + player); + return false; + } + double balance = acc.getBalance(); + + if (balance < amount) return false; + acc.setBalance(balance - amount); + + if (toOwner && target != null && !player.equals(target)) { + Account tAcc = iConomy.getBank().getAccount(target); + if (tAcc != null) { + balance = tAcc.getBalance(); + tAcc.setBalance(balance + amount); + } + } + return true; + } + return true; + } + + public static boolean useiConomy() { + return (useiConomy && iconomy != null); + } +} diff --git a/src/plugin.yml b/src/plugin.yml index 2124340..af17596 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.3.5 +version: 0.4.0 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net \ No newline at end of file