diff --git a/README b/README index 3cf30f7..61c940b 100644 --- a/README +++ b/README @@ -122,10 +122,14 @@ not-enough-money-message - The message displayed if a player lacks money to do s 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 +debug - Whether to show massive debug output for gate creation ============= Changes ============= +[Version 0.4.7] + - Added debug option + - Fixed gates will now show in the list of gates they link to. [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 fe580d7..3300558 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -355,8 +355,8 @@ public class Portal { if (Stargate.worldFilter && !Stargate.hasPerm(player, "stargate.world." + portal.getWorld().getName(), player.isOp())) continue; // Check if dest is this portal if (dest.equalsIgnoreCase(getName())) continue; - // Check if dest is a fixed gate - if (portal.isFixed()) continue; + // Check if dest is a fixed gate not pointing to this gate + if (portal.isFixed() && !portal.getDestinationName().equalsIgnoreCase(getName())) continue; // Visible to this player. if (!portal.isHidden() || Stargate.hasPerm(player, "stargate.hidden", player.isOp()) || portal.getOwner().equals(player.getName())) { destinations.add(portal.getName()); @@ -556,9 +556,15 @@ public class Portal { public static Portal createPortal(SignPost id, Player player) { Block idParent = id.getParent(); - if (idParent == null) return null; + if (idParent == null) { + Stargate.debug("createPortal", "idParent == null"); + return null; + } if (Gate.getGatesByControlBlock(idParent).length == 0) return null; - if (Portal.getByBlock(idParent) != null) return null; + if (Portal.getByBlock(idParent) != null) { + Stargate.debug("createPortal", "idParent belongs to existing gate"); + return null; + } Blox parent = new Blox(player.getWorld(), idParent.getX(), idParent.getY(), idParent.getZ()); Blox topleft = null; @@ -581,12 +587,16 @@ public class Portal { if (alwaysOn && destName.length() == 0) { alwaysOn = false; } + + // Debug + Stargate.debug("createPortal", "h = " + hidden + " a = " + alwaysOn + " p = " + priv + " f = " + free); if ((network.length() < 1) || (network.length() > 11)) { network = Stargate.getDefaultNetwork(); } if ((name.length() < 1) || (name.length() > 11) || (getByName(name, network) != null)) { + Stargate.debug("createPortal", "Name Error"); return null; } @@ -668,13 +678,17 @@ public class Portal { } if ((gate == null) || (buttonVector == null)) { + Stargate.debug("createPortal", "Could not find matching gate layout"); return null; } // Bleh, gotta check to make sure none of this gate belongs to another gate. Boo slow. for (RelativeBlockVector v : gate.getBorder()) { Blox b = topleft.modRelative(v.getRight(), v.getDepth(), v.getDistance(), modX, 1, modZ); - if (Portal.getByBlock(b.getBlock()) != null) return null; + if (Portal.getByBlock(b.getBlock()) != null) { + Stargate.debug("createPortal", "Gate conflicts with existing gate"); + return null; + } } if (iConomyHandler.useiConomy() && !Stargate.hasPerm(player, "stargate.free.create", player.isOp())) { diff --git a/src/net/TheDgtl/Stargate/SignPost.java b/src/net/TheDgtl/Stargate/SignPost.java index 2ac873e..fe35ebc 100644 --- a/src/net/TheDgtl/Stargate/SignPost.java +++ b/src/net/TheDgtl/Stargate/SignPost.java @@ -1,125 +1,125 @@ -package net.TheDgtl.Stargate; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; - -public class SignPost { - private Blox parent; - private Blox block; - private World world; - - public SignPost(World world, Sign sign) { - this.world = world; - this.block = new Blox(world, sign.getX(), sign.getY(), sign.getZ()); - } - - public SignPost(Blox block) { - this.block = block; - this.world = block.getWorld(); - } - - public Block getParent() { - if (parent == null) findParent(); - if (parent == null) return null; - return parent.getBlock(); - } - - public Block getBlock() { - return block.getBlock(); - } - - public String getText(int index) { - Sign sign = findSign(); - if (sign == null) return ""; - return sign.getLine(index); - } - - public void setText(int index, String value) { - Sign sign = findSign(); - if (sign == null) return; - sign.setLine(index, value); - } - - public String getIdText() { - Sign sign = findSign(); - if (sign == null) return ""; - StringBuilder result = new StringBuilder(); - - result.append(getText(0)); - result.append("\n"); - result.append(getText(1)); - result.append("\n"); - result.append(getText(2)); - result.append("\n"); - result.append(getText(3)); - - return result.toString().toLowerCase(); - } - - public void update() { - final Sign sign = findSign(); - if (sign == null) { - Stargate.log.info("[Stargate::SignPost::update] Sign null"); - return; - } - - Stargate.server.getScheduler().scheduleSyncDelayedTask(Stargate.stargate, new Runnable() { - public void run() { - sign.update(); - } - }); - } - - private void findParent() { - Sign sign = findSign(); - int offsetX = 0; - int offsetY = 0; - int offsetZ = 0; - - if (block.getBlock().getType() == Material.WALL_SIGN) { - if (block.getData() == 0x2) { - offsetZ = 1; - } else if (block.getData() == 0x3) { - offsetZ = -1; - } else if (block.getData() == 0x4) { - offsetX = 1; - } else if (block.getData() == 0x5) { - offsetX = -1; - } - } else if (block.getBlock().getType() == Material.SIGN_POST) { - offsetY = -1; - } - if (sign == null) { - Stargate.log.info("Sign is null"); - return; - } - if (world == null) { - Stargate.log.info("World is null"); - return; - } - parent = new Blox(world, sign.getX() + offsetX, sign.getY() + offsetY, sign.getZ() + offsetZ); - } - - private Sign findSign() { - try { - BlockState sign = this.world.getBlockAt(block.getX(), block.getY(), block.getZ()).getState(); - if (sign instanceof Sign) return (Sign)sign; - return null; - } catch (Exception e) {} - return null; - } - - public static SignPost getFromBlock(Block block) { - BlockState state = block.getState(); - if (!(state instanceof Sign)) return null; - return new SignPost(block.getWorld(), (Sign)state); - } - - public static SignPost getFromLocation(Location location) { - return getFromBlock(location.getWorld().getBlockAt((int)location.getX(), (int)location.getY(), (int)location.getZ())); - } +package net.TheDgtl.Stargate; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; + +public class SignPost { + private Blox parent; + private Blox block; + private World world; + + public SignPost(World world, Sign sign) { + this.world = world; + this.block = new Blox(world, sign.getX(), sign.getY(), sign.getZ()); + } + + public SignPost(Blox block) { + this.block = block; + this.world = block.getWorld(); + } + + public Block getParent() { + if (parent == null) findParent(); + if (parent == null) return null; + return parent.getBlock(); + } + + public Block getBlock() { + return block.getBlock(); + } + + public String getText(int index) { + Sign sign = findSign(); + if (sign == null) return ""; + return sign.getLine(index); + } + + public void setText(int index, String value) { + Sign sign = findSign(); + if (sign == null) return; + sign.setLine(index, value); + } + + public String getIdText() { + Sign sign = findSign(); + if (sign == null) return ""; + StringBuilder result = new StringBuilder(); + + result.append(getText(0)); + result.append("\n"); + result.append(getText(1)); + result.append("\n"); + result.append(getText(2)); + result.append("\n"); + result.append(getText(3)); + + return result.toString().toLowerCase(); + } + + public void update() { + final Sign sign = findSign(); + if (sign == null) { + Stargate.log.info("[Stargate::SignPost::update] Sign null"); + return; + } + + Stargate.server.getScheduler().scheduleSyncDelayedTask(Stargate.stargate, new Runnable() { + public void run() { + sign.update(); + } + }); + } + + private void findParent() { + Sign sign = findSign(); + int offsetX = 0; + int offsetY = 0; + int offsetZ = 0; + + if (block.getBlock().getType() == Material.WALL_SIGN) { + if (block.getData() == 0x2) { + offsetZ = 1; + } else if (block.getData() == 0x3) { + offsetZ = -1; + } else if (block.getData() == 0x4) { + offsetX = 1; + } else if (block.getData() == 0x5) { + offsetX = -1; + } + } else if (block.getBlock().getType() == Material.SIGN_POST) { + offsetY = -1; + } + if (sign == null) { + Stargate.debug("findParent", "sign == null"); + return; + } + if (world == null) { + Stargate.debug("findParent", "world == null"); + return; + } + parent = new Blox(world, sign.getX() + offsetX, sign.getY() + offsetY, sign.getZ() + offsetZ); + } + + private Sign findSign() { + try { + BlockState sign = this.world.getBlockAt(block.getX(), block.getY(), block.getZ()).getState(); + if (sign instanceof Sign) return (Sign)sign; + return null; + } catch (Exception e) {} + return null; + } + + public static SignPost getFromBlock(Block block) { + BlockState state = block.getState(); + if (!(state instanceof Sign)) return null; + return new SignPost(block.getWorld(), (Sign)state); + } + + public static SignPost getFromLocation(Location location) { + return getFromBlock(location.getWorld().getBlockAt((int)location.getX(), (int)location.getY(), (int)location.getZ())); + } } \ No newline at end of file diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index eef3b25..05ce3bd 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -3,6 +3,7 @@ package net.TheDgtl.Stargate; import java.io.File; import java.util.Iterator; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.ChatColor; @@ -85,6 +86,9 @@ public class Stargate extends JavaPlugin { private static int activeLimit = 10; private static int openLimit = 10; + // Used for debug + private static boolean debug = false; + public static ConcurrentLinkedQueue openList = new ConcurrentLinkedQueue(); public static ConcurrentLinkedQueue activeList = new ConcurrentLinkedQueue(); @@ -116,7 +120,8 @@ public class Stargate extends JavaPlugin { // Check to see if iConomy/Permissions is loaded yet. permissions = (Permissions)checkPlugin("Permissions"); - iConomyHandler.iconomy = (iConomy)checkPlugin("iConomy"); + if (iConomyHandler.useiConomy) + iConomyHandler.iconomy = (iConomy)checkPlugin("iConomy"); pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); @@ -150,6 +155,8 @@ public class Stargate extends JavaPlugin { destroyExplosion = config.getBoolean("destroyexplosion", destroyExplosion); networkFilter = config.getBoolean("networkfilter", networkFilter); worldFilter = config.getBoolean("worldfilter", worldFilter); + // Debug + debug = config.getBoolean("debug", debug); // iConomy iConomyHandler.useiConomy = config.getBoolean("useiconomy", iConomyHandler.useiConomy); iConomyHandler.createCost = config.getInt("createcost", iConomyHandler.createCost); @@ -225,6 +232,14 @@ public class Stargate extends JavaPlugin { } } } + + public static void debug(String rout, String msg) { + if (Stargate.debug) { + log.info("[Stargate::" + rout + "] " + msg); + } else { + log.log(Level.FINEST, "[Stargate::" + rout + "] " + msg); + } + } public static String getSaveLocation() { return portalFolder; @@ -470,7 +485,10 @@ public class Stargate extends JavaPlugin { sign.setText(2, event.getLine(2)); sign.setText(3, event.getLine(3)); Portal portal = Portal.createPortal(sign, player); - if (portal == null) return; + if (portal == null) { + Stargate.debug("SignChange", "createPortal returned null"); + return; + } if (!regMsg.isEmpty()) { player.sendMessage(ChatColor.GREEN + regMsg); @@ -482,6 +500,8 @@ public class Stargate extends JavaPlugin { event.setLine(1, sign.getText(1)); event.setLine(2, sign.getText(2)); event.setLine(3, sign.getText(3)); + } else { + Stargate.debug("SignChange", player.getName() + " tried to create gate without permissions"); } } @@ -576,7 +596,7 @@ public class Stargate extends JavaPlugin { private class sListener extends ServerListener { @Override public void onPluginEnable(PluginEnableEvent event) { - if (iConomyHandler.iconomy == null) { + if (iConomyHandler.useiConomy && iConomyHandler.iconomy == null) { if (event.getPlugin().getDescription().getName().equalsIgnoreCase("iConomy")) { iConomyHandler.iconomy = (iConomy)checkPlugin(event.getPlugin()); } @@ -590,7 +610,7 @@ public class Stargate extends JavaPlugin { @Override public void onPluginDisable(PluginDisableEvent event) { - if (event.getPlugin() == iConomyHandler.iconomy) { + if (iConomyHandler.useiConomy && event.getPlugin() == iConomyHandler.iconomy) { log.info("[Stargate] iConomy plugin lost."); iConomyHandler.iconomy = null; } diff --git a/src/plugin.yml b/src/plugin.yml index a9d4361..9074a6f 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.4.6 +version: 0.4.7 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net