Added debug option

Fixed gates will now show in the list of gates they link to.
Line endings in SignPost
This commit is contained in:
Drakia 2011-05-06 17:00:21 -07:00
parent 4c6c829348
commit 858a40e0cf
5 changed files with 172 additions and 134 deletions

4
README
View File

@ -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. 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. 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 toowner - Whether the money from gate-use goes to the owner or nobody
debug - Whether to show massive debug output for gate creation
============= =============
Changes 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] [Version 0.4.6]
- Fixed a bug in iConomy handling. - Fixed a bug in iConomy handling.
[Version 0.4.5] [Version 0.4.5]

View File

@ -355,8 +355,8 @@ public class Portal {
if (Stargate.worldFilter && !Stargate.hasPerm(player, "stargate.world." + portal.getWorld().getName(), player.isOp())) continue; if (Stargate.worldFilter && !Stargate.hasPerm(player, "stargate.world." + portal.getWorld().getName(), player.isOp())) continue;
// Check if dest is this portal // Check if dest is this portal
if (dest.equalsIgnoreCase(getName())) continue; if (dest.equalsIgnoreCase(getName())) continue;
// Check if dest is a fixed gate // Check if dest is a fixed gate not pointing to this gate
if (portal.isFixed()) continue; if (portal.isFixed() && !portal.getDestinationName().equalsIgnoreCase(getName())) continue;
// Visible to this player. // Visible to this player.
if (!portal.isHidden() || Stargate.hasPerm(player, "stargate.hidden", player.isOp()) || portal.getOwner().equals(player.getName())) { if (!portal.isHidden() || Stargate.hasPerm(player, "stargate.hidden", player.isOp()) || portal.getOwner().equals(player.getName())) {
destinations.add(portal.getName()); destinations.add(portal.getName());
@ -556,9 +556,15 @@ public class Portal {
public static Portal createPortal(SignPost id, Player player) { public static Portal createPortal(SignPost id, Player player) {
Block idParent = id.getParent(); 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 (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 parent = new Blox(player.getWorld(), idParent.getX(), idParent.getY(), idParent.getZ());
Blox topleft = null; Blox topleft = null;
@ -581,12 +587,16 @@ public class Portal {
if (alwaysOn && destName.length() == 0) { if (alwaysOn && destName.length() == 0) {
alwaysOn = false; alwaysOn = false;
} }
// Debug
Stargate.debug("createPortal", "h = " + hidden + " a = " + alwaysOn + " p = " + priv + " f = " + free);
if ((network.length() < 1) || (network.length() > 11)) { if ((network.length() < 1) || (network.length() > 11)) {
network = Stargate.getDefaultNetwork(); network = Stargate.getDefaultNetwork();
} }
if ((name.length() < 1) || (name.length() > 11) || (getByName(name, network) != null)) { if ((name.length() < 1) || (name.length() > 11) || (getByName(name, network) != null)) {
Stargate.debug("createPortal", "Name Error");
return null; return null;
} }
@ -668,13 +678,17 @@ public class Portal {
} }
if ((gate == null) || (buttonVector == null)) { if ((gate == null) || (buttonVector == null)) {
Stargate.debug("createPortal", "Could not find matching gate layout");
return null; return null;
} }
// Bleh, gotta check to make sure none of this gate belongs to another gate. Boo slow. // Bleh, gotta check to make sure none of this gate belongs to another gate. Boo slow.
for (RelativeBlockVector v : gate.getBorder()) { for (RelativeBlockVector v : gate.getBorder()) {
Blox b = topleft.modRelative(v.getRight(), v.getDepth(), v.getDistance(), modX, 1, modZ); 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())) { if (iConomyHandler.useiConomy() && !Stargate.hasPerm(player, "stargate.free.create", player.isOp())) {

View File

@ -1,125 +1,125 @@
package net.TheDgtl.Stargate; package net.TheDgtl.Stargate;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
public class SignPost { public class SignPost {
private Blox parent; private Blox parent;
private Blox block; private Blox block;
private World world; private World world;
public SignPost(World world, Sign sign) { public SignPost(World world, Sign sign) {
this.world = world; this.world = world;
this.block = new Blox(world, sign.getX(), sign.getY(), sign.getZ()); this.block = new Blox(world, sign.getX(), sign.getY(), sign.getZ());
} }
public SignPost(Blox block) { public SignPost(Blox block) {
this.block = block; this.block = block;
this.world = block.getWorld(); this.world = block.getWorld();
} }
public Block getParent() { public Block getParent() {
if (parent == null) findParent(); if (parent == null) findParent();
if (parent == null) return null; if (parent == null) return null;
return parent.getBlock(); return parent.getBlock();
} }
public Block getBlock() { public Block getBlock() {
return block.getBlock(); return block.getBlock();
} }
public String getText(int index) { public String getText(int index) {
Sign sign = findSign(); Sign sign = findSign();
if (sign == null) return ""; if (sign == null) return "";
return sign.getLine(index); return sign.getLine(index);
} }
public void setText(int index, String value) { public void setText(int index, String value) {
Sign sign = findSign(); Sign sign = findSign();
if (sign == null) return; if (sign == null) return;
sign.setLine(index, value); sign.setLine(index, value);
} }
public String getIdText() { public String getIdText() {
Sign sign = findSign(); Sign sign = findSign();
if (sign == null) return ""; if (sign == null) return "";
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
result.append(getText(0)); result.append(getText(0));
result.append("\n"); result.append("\n");
result.append(getText(1)); result.append(getText(1));
result.append("\n"); result.append("\n");
result.append(getText(2)); result.append(getText(2));
result.append("\n"); result.append("\n");
result.append(getText(3)); result.append(getText(3));
return result.toString().toLowerCase(); return result.toString().toLowerCase();
} }
public void update() { public void update() {
final Sign sign = findSign(); final Sign sign = findSign();
if (sign == null) { if (sign == null) {
Stargate.log.info("[Stargate::SignPost::update] Sign null"); Stargate.log.info("[Stargate::SignPost::update] Sign null");
return; return;
} }
Stargate.server.getScheduler().scheduleSyncDelayedTask(Stargate.stargate, new Runnable() { Stargate.server.getScheduler().scheduleSyncDelayedTask(Stargate.stargate, new Runnable() {
public void run() { public void run() {
sign.update(); sign.update();
} }
}); });
} }
private void findParent() { private void findParent() {
Sign sign = findSign(); Sign sign = findSign();
int offsetX = 0; int offsetX = 0;
int offsetY = 0; int offsetY = 0;
int offsetZ = 0; int offsetZ = 0;
if (block.getBlock().getType() == Material.WALL_SIGN) { if (block.getBlock().getType() == Material.WALL_SIGN) {
if (block.getData() == 0x2) { if (block.getData() == 0x2) {
offsetZ = 1; offsetZ = 1;
} else if (block.getData() == 0x3) { } else if (block.getData() == 0x3) {
offsetZ = -1; offsetZ = -1;
} else if (block.getData() == 0x4) { } else if (block.getData() == 0x4) {
offsetX = 1; offsetX = 1;
} else if (block.getData() == 0x5) { } else if (block.getData() == 0x5) {
offsetX = -1; offsetX = -1;
} }
} else if (block.getBlock().getType() == Material.SIGN_POST) { } else if (block.getBlock().getType() == Material.SIGN_POST) {
offsetY = -1; offsetY = -1;
} }
if (sign == null) { if (sign == null) {
Stargate.log.info("Sign is null"); Stargate.debug("findParent", "sign == null");
return; return;
} }
if (world == null) { if (world == null) {
Stargate.log.info("World is null"); Stargate.debug("findParent", "world == null");
return; return;
} }
parent = new Blox(world, sign.getX() + offsetX, sign.getY() + offsetY, sign.getZ() + offsetZ); parent = new Blox(world, sign.getX() + offsetX, sign.getY() + offsetY, sign.getZ() + offsetZ);
} }
private Sign findSign() { private Sign findSign() {
try { try {
BlockState sign = this.world.getBlockAt(block.getX(), block.getY(), block.getZ()).getState(); BlockState sign = this.world.getBlockAt(block.getX(), block.getY(), block.getZ()).getState();
if (sign instanceof Sign) return (Sign)sign; if (sign instanceof Sign) return (Sign)sign;
return null; return null;
} catch (Exception e) {} } catch (Exception e) {}
return null; return null;
} }
public static SignPost getFromBlock(Block block) { public static SignPost getFromBlock(Block block) {
BlockState state = block.getState(); BlockState state = block.getState();
if (!(state instanceof Sign)) return null; if (!(state instanceof Sign)) return null;
return new SignPost(block.getWorld(), (Sign)state); return new SignPost(block.getWorld(), (Sign)state);
} }
public static SignPost getFromLocation(Location location) { public static SignPost getFromLocation(Location location) {
return getFromBlock(location.getWorld().getBlockAt((int)location.getX(), (int)location.getY(), (int)location.getZ())); return getFromBlock(location.getWorld().getBlockAt((int)location.getX(), (int)location.getY(), (int)location.getZ()));
} }
} }

View File

@ -3,6 +3,7 @@ package net.TheDgtl.Stargate;
import java.io.File; import java.io.File;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -85,6 +86,9 @@ public class Stargate extends JavaPlugin {
private static int activeLimit = 10; private static int activeLimit = 10;
private static int openLimit = 10; private static int openLimit = 10;
// Used for debug
private static boolean debug = false;
public static ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<Portal>(); public static ConcurrentLinkedQueue<Portal> openList = new ConcurrentLinkedQueue<Portal>();
public static ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<Portal>(); public static ConcurrentLinkedQueue<Portal> activeList = new ConcurrentLinkedQueue<Portal>();
@ -116,7 +120,8 @@ public class Stargate extends JavaPlugin {
// Check to see if iConomy/Permissions is loaded yet. // Check to see if iConomy/Permissions is loaded yet.
permissions = (Permissions)checkPlugin("Permissions"); 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); pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
@ -150,6 +155,8 @@ public class Stargate extends JavaPlugin {
destroyExplosion = config.getBoolean("destroyexplosion", destroyExplosion); destroyExplosion = config.getBoolean("destroyexplosion", destroyExplosion);
networkFilter = config.getBoolean("networkfilter", networkFilter); networkFilter = config.getBoolean("networkfilter", networkFilter);
worldFilter = config.getBoolean("worldfilter", worldFilter); worldFilter = config.getBoolean("worldfilter", worldFilter);
// Debug
debug = config.getBoolean("debug", debug);
// iConomy // iConomy
iConomyHandler.useiConomy = config.getBoolean("useiconomy", iConomyHandler.useiConomy); iConomyHandler.useiConomy = config.getBoolean("useiconomy", iConomyHandler.useiConomy);
iConomyHandler.createCost = config.getInt("createcost", iConomyHandler.createCost); 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() { public static String getSaveLocation() {
return portalFolder; return portalFolder;
@ -470,7 +485,10 @@ public class Stargate extends JavaPlugin {
sign.setText(2, event.getLine(2)); sign.setText(2, event.getLine(2));
sign.setText(3, event.getLine(3)); sign.setText(3, event.getLine(3));
Portal portal = Portal.createPortal(sign, player); Portal portal = Portal.createPortal(sign, player);
if (portal == null) return; if (portal == null) {
Stargate.debug("SignChange", "createPortal returned null");
return;
}
if (!regMsg.isEmpty()) { if (!regMsg.isEmpty()) {
player.sendMessage(ChatColor.GREEN + regMsg); player.sendMessage(ChatColor.GREEN + regMsg);
@ -482,6 +500,8 @@ public class Stargate extends JavaPlugin {
event.setLine(1, sign.getText(1)); event.setLine(1, sign.getText(1));
event.setLine(2, sign.getText(2)); event.setLine(2, sign.getText(2));
event.setLine(3, sign.getText(3)); 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 { private class sListener extends ServerListener {
@Override @Override
public void onPluginEnable(PluginEnableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
if (iConomyHandler.iconomy == null) { if (iConomyHandler.useiConomy && iConomyHandler.iconomy == null) {
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("iConomy")) { if (event.getPlugin().getDescription().getName().equalsIgnoreCase("iConomy")) {
iConomyHandler.iconomy = (iConomy)checkPlugin(event.getPlugin()); iConomyHandler.iconomy = (iConomy)checkPlugin(event.getPlugin());
} }
@ -590,7 +610,7 @@ public class Stargate extends JavaPlugin {
@Override @Override
public void onPluginDisable(PluginDisableEvent event) { public void onPluginDisable(PluginDisableEvent event) {
if (event.getPlugin() == iConomyHandler.iconomy) { if (iConomyHandler.useiConomy && event.getPlugin() == iConomyHandler.iconomy) {
log.info("[Stargate] iConomy plugin lost."); log.info("[Stargate] iConomy plugin lost.");
iConomyHandler.iconomy = null; iConomyHandler.iconomy = null;
} }

View File

@ -1,6 +1,6 @@
name: Stargate name: Stargate
main: net.TheDgtl.Stargate.Stargate main: net.TheDgtl.Stargate.Stargate
version: 0.4.6 version: 0.4.7
description: Stargate mod for Bukkit description: Stargate mod for Bukkit
author: Drakia author: Drakia
website: http://www.thedgtl.net website: http://www.thedgtl.net