From f9db8ef7f974f22566eb6918d4618b427dcf7426 Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Mon, 25 Jul 2011 21:15:47 -0600 Subject: [PATCH] =?UTF-8?q?Fix=20getSafeLocation(L)=20only=20returning=20u?= =?UTF-8?q?nsafe=20locations=E2=80=A6=20Silly=20booleans...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MultiverseCore/MVTeleport.java | 20 ++++- .../com/onarandombox/utils/BlockSafety.java | 86 ++++++++++--------- .../utils/LocationManipulation.java | 3 + 3 files changed, 65 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java b/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java index d5ed8313..05bc4c15 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVTeleport.java @@ -40,6 +40,7 @@ public class MVTeleport { // TODO: Make this configurable Location safe = checkAboveAndBelowLocation(l, 6, 9); if (safe != null) { + System.out.print("Safe was NULL!"); safe.setX(safe.getBlockX() + .5); safe.setZ(safe.getBlockZ() + .5); } @@ -63,7 +64,9 @@ public class MVTeleport { } // We've already checked zero right above this. int currentLevel = 1; + System.out.print("Checking Level: 0"); while (currentLevel <= tolerance) { + System.out.print("Checking Level: " + currentLevel); // Check above locToCheck = l.clone(); locToCheck.add(0, currentLevel, 0); @@ -71,6 +74,7 @@ public class MVTeleport { if (safe != null) { return safe; } + // Check below locToCheck = l.clone(); locToCheck.subtract(0, currentLevel, 0); @@ -169,15 +173,25 @@ public class MVTeleport { public boolean safelyTeleport(Entity e, Location l) { if (this.bs.playerCanSpawnHereSafely(l)) { + l.setX(l.getBlockX() + .5); + l.setZ(l.getBlockZ() + .5); e.teleport(l); System.out.print("The first location you gave me was safe!"); return true; - } else if (this.getSafeLocation(l) != null) { - e.teleport(this.getSafeLocation(l)); - System.out.print("Had to look for a bit, but I found a safe place for ya!"); + } + Location safeLocation = this.getSafeLocation(l); + if (safeLocation != null) { + // Add offset to account for a vehicle on dry land! + if(!this.bs.isEntitiyOnTrack(e, safeLocation)) { + safeLocation.setY(safeLocation.getBlockY() + .5); + } + e.teleport(safeLocation); + System.out.print("Had to look for a bit, but I found a safe place for ya!" + safeLocation); return true; } System.out.print("Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now."); return false; } + + } diff --git a/src/main/java/com/onarandombox/utils/BlockSafety.java b/src/main/java/com/onarandombox/utils/BlockSafety.java index be3bf0d9..69aa8d26 100644 --- a/src/main/java/com/onarandombox/utils/BlockSafety.java +++ b/src/main/java/com/onarandombox/utils/BlockSafety.java @@ -3,6 +3,7 @@ package com.onarandombox.utils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.entity.Entity; public class BlockSafety { /** @@ -35,36 +36,32 @@ public class BlockSafety { * @return */ public boolean playerCanSpawnHereSafely(Location l) { - Location actual = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); - Location upOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); - Location downOne = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); + Location actual = l.clone(); + Location upOne = l.clone(); + Location downOne = l.clone(); upOne.setY(upOne.getY() + 1); downOne.setY(downOne.getY() - 1); - if (this.isNotSolidBlock(actual.getBlock().getType()) || this.isNotSolidBlock(upOne.getBlock().getType())) { + if (this.isSolidBlock(actual.getBlock().getType()) || this.isSolidBlock(upOne.getBlock().getType())) { + System.out.print("On or Above is not safe"); return false; } - if (downOne.getBlock().getType() == Material.LAVA) { - return false; - } - - if (downOne.getBlock().getType() == Material.STATIONARY_LAVA) { + if (downOne.getBlock().getType() == Material.LAVA || downOne.getBlock().getType() == Material.STATIONARY_LAVA) { + System.out.print("Lava Below"); return false; } if (downOne.getBlock().getType() == Material.FIRE) { - return false; - } - - if (actual.getBlock().getType() == Material.FIRE) { + System.out.print("Fire Below"); return false; } if (blockIsAboveAir(actual)) { + System.out.print("Above Air"); return false; } - + System.out.print("All Good!"); return true; } @@ -74,60 +71,67 @@ public class BlockSafety { * @param type * @return */ - private boolean isNotSolidBlock(Material type) { + private boolean isSolidBlock(Material type) { switch (type) { case AIR: - return true; + return false; + case SNOW: + return false; case TRAP_DOOR: - return true; + return false; case TORCH: - return true; + return false; case YELLOW_FLOWER: - return true; + return false; case RED_ROSE: - return true; + return false; case RED_MUSHROOM: - return true; + return false; case BROWN_MUSHROOM: - return true; + return false; case REDSTONE: - return true; + return false; case REDSTONE_WIRE: - return true; + return false; case RAILS: - return true; + return false; case POWERED_RAIL: - return true; + return false; case REDSTONE_TORCH_ON: - return true; + return false; case REDSTONE_TORCH_OFF: - return true; + return false; case DEAD_BUSH: - return true; + return false; case SAPLING: - return true; + return false; case STONE_BUTTON: - return true; + return false; case LEVER: - return true; + return false; case LONG_GRASS: - return true; + return false; case PORTAL: - return true; + return false; case STONE_PLATE: - return true; + return false; case WOOD_PLATE: - return true; + return false; case SEEDS: - return true; + return false; case SUGAR_CANE_BLOCK: - return true; + return false; case WALL_SIGN: - return true; + return false; case SIGN_POST: - return true; + return false; } - return false; + return true; + } + + public boolean isEntitiyOnTrack(Entity e, Location l) { + Material currentBlock = l.getBlock().getType(); + return (currentBlock == Material.POWERED_RAIL || currentBlock == Material.DETECTOR_RAIL || currentBlock == Material.RAILS); } public void showDangers(Location l) { diff --git a/src/main/java/com/onarandombox/utils/LocationManipulation.java b/src/main/java/com/onarandombox/utils/LocationManipulation.java index 24db5c1a..b5ba8931 100644 --- a/src/main/java/com/onarandombox/utils/LocationManipulation.java +++ b/src/main/java/com/onarandombox/utils/LocationManipulation.java @@ -117,6 +117,9 @@ public class LocationManipulation { // X, Y, Z // -W/+E,0, -N/+S public static Vector getTranslatedVector(Vector v, String direction) { + if(direction == null) { + return v; + } float speed = getSpeed(v); float halfSpeed = (float) (speed / 2.0); // TODO: Mathmatacize this: