mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-07 11:20:32 +01:00
Fix getSafeLocation(L) only returning unsafe locations… Silly booleans...
This commit is contained in:
parent
6e88301351
commit
f9db8ef7f9
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user