From bfcdd212c4f2acfcd3070a2bc583e03173206b09 Mon Sep 17 00:00:00 2001 From: Steven Scott Date: Sun, 4 Mar 2012 00:15:49 -0800 Subject: [PATCH] [Version 0.7.5.8] - Fixed an exploit with pistons to destroy gates [Version 0.7.5.7] - Removed SignPost class - Resolved issues with signs in 1.2 --- README | 5 + src/net/TheDgtl/Stargate/Blox.java | 297 ++++++++++++++----------- src/net/TheDgtl/Stargate/Portal.java | 69 +++--- src/net/TheDgtl/Stargate/SignPost.java | 125 ----------- src/net/TheDgtl/Stargate/Stargate.java | 21 ++ src/plugin.yml | 2 +- 6 files changed, 226 insertions(+), 293 deletions(-) delete mode 100644 src/net/TheDgtl/Stargate/SignPost.java diff --git a/README b/README index 252a0f8..5c88e95 100644 --- a/README +++ b/README @@ -201,6 +201,11 @@ createConflict=Gate conflicts with existing gate ============= Changes ============= +[Version 0.7.5.8] + - Fixed an exploit with pistons to destroy gates +[Version 0.7.5.7] + - Removed SignPost class + - Resolved issues with signs in 1.2 [Version 0.7.5.6] - Quick update to the custom event code, works with R5+ now. [Version 0.7.5.5] diff --git a/src/net/TheDgtl/Stargate/Blox.java b/src/net/TheDgtl/Stargate/Blox.java index f5a9d2c..f2a29cf 100644 --- a/src/net/TheDgtl/Stargate/Blox.java +++ b/src/net/TheDgtl/Stargate/Blox.java @@ -1,134 +1,165 @@ -package net.TheDgtl.Stargate; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; - -/** - * Blox.java - * @author Shaun (sturmeh) - * @author Dinnerbone - * @author Steven "Drakia" Scott - */ - -public class Blox { - private int x; - private int y; - private int z; - private World world; - - public Blox (World world, int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - this.world = world; - } - - public Blox (Block block) { - this.x = block.getX(); - this.y = block.getY(); - this.z = block.getZ(); - this.world = block.getWorld(); - } - - public Blox (Location location) { - this.x = location.getBlockX(); - this.y = location.getBlockY(); - this.z = location.getBlockZ(); - this.world = location.getWorld(); - } - - public Blox (World world, String string) { - String[] split = string.split(","); - this.x = Integer.parseInt(split[0]); - this.y = Integer.parseInt(split[1]); - this.z = Integer.parseInt(split[2]); - this.world = world; - } - - public Blox makeRelative(int x, int y, int z) { - return new Blox(this.world, this.x + x, this.y + y, this.z + z); - } - - public Location makeRelativeLoc(double x, double y, double z, float rotX, float rotY) { - return new Location(this.world, (double)this.x + x, (double)this.y + y, (double)this.z + z, rotX, rotY); - } - - public Blox modRelative(int right, int depth, int distance, int modX, int modY, int modZ) { - return makeRelative(-right * modX + distance * modZ, -depth * modY, -right * modZ + -distance * modX); - } - - public Location modRelativeLoc(double right, double depth, double distance, float rotX, float rotY, int modX, int modY, int modZ) { - return makeRelativeLoc(0.5 + -right * modX + distance * modZ, depth, 0.5 + -right * modZ + -distance * modX, rotX, 0); - } - - public void setType(int type) { - world.getBlockAt(x, y, z).setTypeId(type); - } - - public int getType() { - return world.getBlockAt(x, y, z).getTypeId(); - } - - public void setData(int data) { - world.getBlockAt(x, y, z).setData((byte)data); - } - - public int getData() { - return world.getBlockAt(x, y, z).getData(); - } - - public Block getBlock() { - return world.getBlockAt(x, y, z); - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getZ() { - return z; - } - - public World getWorld() { - return world; - } - - public String toString() { - StringBuilder builder = new StringBuilder(); - //builder.append(world.getName()); - //builder.append(','); - builder.append(x); - builder.append(','); - builder.append(y); - builder.append(','); - builder.append(z); - return builder.toString(); - } - - @Override - public int hashCode() { - int result = 18; - - result = result * 27 + x; - result = result * 27 + y; - result = result * 27 + z; - result = result * 27 + world.getName().hashCode(); - - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - - Blox blox = (Blox) obj; - return (x == blox.x) && (y == blox.y) && (z == blox.z) && (world.getName().equals(blox.world.getName())); - } +package net.TheDgtl.Stargate; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; + +/** + * Blox.java + * @author Shaun (sturmeh) + * @author Dinnerbone + * @author Steven "Drakia" Scott + */ + +public class Blox { + private int x; + private int y; + private int z; + private World world; + private Blox parent = null; + + public Blox (World world, int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + this.world = world; + } + + public Blox (Block block) { + this.x = block.getX(); + this.y = block.getY(); + this.z = block.getZ(); + this.world = block.getWorld(); + } + + public Blox (Location location) { + this.x = location.getBlockX(); + this.y = location.getBlockY(); + this.z = location.getBlockZ(); + this.world = location.getWorld(); + } + + public Blox (World world, String string) { + String[] split = string.split(","); + this.x = Integer.parseInt(split[0]); + this.y = Integer.parseInt(split[1]); + this.z = Integer.parseInt(split[2]); + this.world = world; + } + + public Blox makeRelative(int x, int y, int z) { + return new Blox(this.world, this.x + x, this.y + y, this.z + z); + } + + public Location makeRelativeLoc(double x, double y, double z, float rotX, float rotY) { + return new Location(this.world, (double)this.x + x, (double)this.y + y, (double)this.z + z, rotX, rotY); + } + + public Blox modRelative(int right, int depth, int distance, int modX, int modY, int modZ) { + return makeRelative(-right * modX + distance * modZ, -depth * modY, -right * modZ + -distance * modX); + } + + public Location modRelativeLoc(double right, double depth, double distance, float rotX, float rotY, int modX, int modY, int modZ) { + return makeRelativeLoc(0.5 + -right * modX + distance * modZ, depth, 0.5 + -right * modZ + -distance * modX, rotX, 0); + } + + public void setType(int type) { + world.getBlockAt(x, y, z).setTypeId(type); + } + + public int getType() { + return world.getBlockAt(x, y, z).getTypeId(); + } + + public void setData(int data) { + world.getBlockAt(x, y, z).setData((byte)data); + } + + public int getData() { + return world.getBlockAt(x, y, z).getData(); + } + + public Block getBlock() { + return world.getBlockAt(x, y, z); + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getZ() { + return z; + } + + public World getWorld() { + return world; + } + + public Block getParent() { + if (parent == null) findParent(); + if (parent == null) return null; + return parent.getBlock(); + } + + private void findParent() { + int offsetX = 0; + int offsetY = 0; + int offsetZ = 0; + + if (getBlock().getType() == Material.WALL_SIGN) { + if (getData() == 0x2) { + offsetZ = 1; + } else if (getData() == 0x3) { + offsetZ = -1; + } else if (getData() == 0x4) { + offsetX = 1; + } else if (getData() == 0x5) { + offsetX = -1; + } + } else if (getBlock().getType() == Material.SIGN_POST) { + offsetY = -1; + } else { + return; + } + parent = new Blox(world, getX() + offsetX, getY() + offsetY, getZ() + offsetZ); + } + + public String toString() { + StringBuilder builder = new StringBuilder(); + //builder.append(world.getName()); + //builder.append(','); + builder.append(x); + builder.append(','); + builder.append(y); + builder.append(','); + builder.append(z); + return builder.toString(); + } + + @Override + public int hashCode() { + int result = 18; + + result = result * 27 + x; + result = result * 27 + y; + result = result * 27 + z; + result = result * 27 + world.getName().hashCode(); + + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + + Blox blox = (Blox) obj; + return (x == blox.x) && (y == blox.y) && (z == blox.z) && (world.getName().equals(blox.world.getName())); + } } \ No newline at end of file diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index 662a3a4..b4d1f43 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -54,7 +54,7 @@ public class Portal { private float rotX; // Block references - private SignPost id; + private Blox id; private Blox button; private Blox[] frame; private Blox[] entrances; @@ -87,7 +87,7 @@ public class Portal { private long openTime; private Portal(Blox topLeft, int modX, int modZ, - float rotX, SignPost id, Blox button, + float rotX, Blox id, Blox button, String dest, String name, boolean verified, String network, Gate gate, String owner, boolean hidden, boolean alwaysOn, boolean priv, boolean free, boolean backwards, boolean show, boolean noNetwork) { @@ -590,29 +590,30 @@ public class Portal { } public final void drawSign() { - id.setText(0, "--" + name + "--"); + Sign sign = (Sign)id.getBlock().getState(); + sign.setLine(0, "--" + name + "--"); int max = destinations.size() - 1; int done = 0; if (!isActive()) { - id.setText(++done, "Right click to"); - id.setText(++done, "use the gate"); + sign.setLine(++done, "Right click to"); + sign.setLine(++done, "use the gate"); if (!noNetwork) { - id.setText(++done, " (" + network + ") "); + sign.setLine(++done, " (" + network + ") "); } } else { if (isFixed()) { - id.setText(++done, "To: " + destination); + sign.setLine(++done, "To: " + destination); if (noNetwork) { - id.setText(++done, ""); + sign.setLine(++done, ""); } else { - id.setText(++done, " (" + network + ") "); + sign.setLine(++done, " (" + network + ") "); } Portal dest = Portal.getByName(destination, network); if (dest == null) { - id.setText(++done, "(Not Connected)"); + sign.setLine(++done, "(Not Connected)"); } else { - id.setText(++done, ""); + sign.setLine(++done, ""); } } else { int index = destinations.indexOf(destination); @@ -621,55 +622,55 @@ public class Portal { if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { Portal dest = Portal.getByName(destinations.get(index - 2), network); boolean green = Stargate.isFree(activePlayer, this, dest); - id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 2)); + sign.setLine(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 2)); } else { - id.setText(done, destinations.get(index - 2)); + sign.setLine(done, destinations.get(index - 2)); } } if ((index > 0) && (++done <= 3)) { if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { Portal dest = Portal.getByName(destinations.get(index - 1), network); boolean green = Stargate.isFree(activePlayer, this, dest); - id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 1)); + sign.setLine(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index - 1)); } else { - id.setText(done, destinations.get(index - 1)); + sign.setLine(done, destinations.get(index - 1)); } } if (++done <= 3) { if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { Portal dest = Portal.getByName(destination, network); boolean green = Stargate.isFree(activePlayer, this, dest); - id.setText(done, (green ? ChatColor.DARK_GREEN : "") + " >" + destination + "< "); + sign.setLine(done, (green ? ChatColor.DARK_GREEN : "") + " >" + destination + "< "); } else { - id.setText(done, " >" + destination + "< "); + sign.setLine(done, " >" + destination + "< "); } } if ((max >= index + 1) && (++done <= 3)) { if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { Portal dest = Portal.getByName(destinations.get(index + 1), network); boolean green = Stargate.isFree(activePlayer, this, dest); - id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 1)); + sign.setLine(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 1)); } else { - id.setText(done, destinations.get(index + 1)); + sign.setLine(done, destinations.get(index + 1)); } } if ((max >= index + 2) && (++done <= 3)) { if (iConomyHandler.useiConomy() && iConomyHandler.freeGatesGreen) { Portal dest = Portal.getByName(destinations.get(index + 2), network); boolean green = Stargate.isFree(activePlayer, this, dest); - id.setText(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 2)); + sign.setLine(done, (green ? ChatColor.DARK_GREEN : "") + destinations.get(index + 2)); } else { - id.setText(done, destinations.get(index + 2)); + sign.setLine(done, destinations.get(index + 2)); } } } } for (done++; done <= 3; done++) { - id.setText(done, ""); + sign.setLine(done, ""); } - - id.update(); + + sign.update(); } public void unregister(boolean removeAll) { @@ -696,11 +697,12 @@ public class Portal { allPortalsNet.get(getNetwork().toLowerCase()).remove(getName().toLowerCase()); if (id.getBlock().getType() == Material.WALL_SIGN) { - id.setText(0, getName()); - id.setText(1, ""); - id.setText(2, ""); - id.setText(3, ""); - id.update(); + Sign sign = (Sign)id.getBlock().getState(); + sign.setLine(0, getName()); + sign.setLine(1, ""); + sign.setLine(2, ""); + sign.setLine(3, ""); + sign.update(); } for (String originName : allPortalsNet.get(getNetwork().toLowerCase())) { @@ -750,7 +752,7 @@ public class Portal { } public static Portal createPortal(SignChangeEvent event, Player player) { - SignPost id = new SignPost(new Blox(event.getBlock())); + Blox id = new Blox(event.getBlock()); Block idParent = id.getParent(); if (idParent == null) { return null; @@ -1117,12 +1119,11 @@ public class Portal { continue; } String name = split[0]; - Blox s = new Blox(world, split[1]); - if (!(s.getBlock().getState() instanceof Sign)) { - Stargate.log.info("[Stargate] Sign on line " + l + " doesn't exist. BlockType = " + s.getBlock().getType()); + Blox sign = new Blox(world, split[1]); + if (!(sign.getBlock().getState() instanceof Sign)) { + Stargate.log.info("[Stargate] Sign on line " + l + " doesn't exist. BlockType = " + sign.getBlock().getType()); continue; } - SignPost sign = new SignPost(s); Blox button = (split[2].length() > 0) ? new Blox(world, split[2]) : null; int modX = Integer.parseInt(split[3]); int modZ = Integer.parseInt(split[4]); diff --git a/src/net/TheDgtl/Stargate/SignPost.java b/src/net/TheDgtl/Stargate/SignPost.java deleted file mode 100644 index c99254a..0000000 --- a/src/net/TheDgtl/Stargate/SignPost.java +++ /dev/null @@ -1,125 +0,0 @@ -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; - -/** - * SignPost.java - * @author Shaun (sturmeh) - * @author Dinnerbone - * @author Steven "Drakia" Scott - */ - -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) return; - - 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 ea6f362..617e365 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -29,6 +29,8 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -945,6 +947,25 @@ public class Stargate extends JavaPlugin { event.setCancelled((event.getBlock().getY() == event.getToBlock().getY())); } } + + @EventHandler + public void onPistonExtend(BlockPistonExtendEvent event) { + for(Block block : event.getBlocks()) { + Portal portal = Portal.getByBlock(block); + if (portal != null) { + event.setCancelled(true); + return; + } + } + } + + @EventHandler + public void onPistonRetract(BlockPistonRetractEvent event) { + if (!event.isSticky()) return; + Block affected = event.getRetractLocation().getBlock(); + Portal portal = Portal.getByBlock(affected); + if (portal != null) event.setCancelled(true); + } } private class wListener implements Listener { diff --git a/src/plugin.yml b/src/plugin.yml index ad16aad..6173113 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.7.5.6 +version: 0.7.5.8 description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net