Test Push. Do not use this build!

This commit is contained in:
Eric Stokes 2011-07-24 12:10:39 -06:00
parent 23158a0707
commit 61e917a60f
4 changed files with 46 additions and 98 deletions

View File

@ -1,13 +1,10 @@
package com.onarandombox.MultiverseCore;
import java.util.ArrayList;
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.entity.Entity;
import com.onarandombox.utils.BlockSafety;
@ -22,41 +19,6 @@ public class MVTeleport {
this.plugin = plugin;
}
/**
* TODO: Sort out JavaDoc
*
* @param l
* @param w
* @return
*/
public Location getCompressedLocation(Player p, World w) {
Location l = p.getLocation();
// Check if they are the same world, might as well skip any calculations.
if (l.getWorld().getName().equalsIgnoreCase(w.getName())) {
return l;
}
double x, y, z;
// Grab the Scaling value for each world.
double srcComp = this.plugin.getMVWorld(l.getWorld().getName()).getScaling();
double trgComp = this.plugin.getMVWorld(w.getName()).getScaling();
// MultiverseCore.debugMsg(p.getName() + " -> " + p.getWorld().getName() + "(" + srcComp + ") -> " + w.getName() + "(" + trgComp + ")");
// If the Targets Compression is 0 then we teleport them to the Spawn of the World.
if (trgComp == 0.0) {
x = w.getSpawnLocation().getX();
y = w.getSpawnLocation().getY();
z = w.getSpawnLocation().getZ();
} else {
x = l.getX() / (srcComp != 0 ? srcComp : 1) * trgComp;
y = l.getY();
z = l.getZ() / (srcComp != 0 ? srcComp : 1) * trgComp;
}
return new Location(w, x, y, z);
}
/**
* This method will be specific to beds, and check on top of the bed then around it.
*
@ -75,6 +37,24 @@ public class MVTeleport {
}
return null;
}
private Location getSafeLocation(Location l) {
return null;
}
public boolean safelyTeleport(Entity e, Location l) {
if(this.bs.playerCanSpawnHereSafely(l)) {
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!");
return true;
}
System.out.print("Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now.");
return false;
}
/**
* This function gets a safe place to teleport to.
@ -83,7 +63,8 @@ public class MVTeleport {
* @param player
* @return
*/
public Location getSafeDestination(Location l) {
@Deprecated
private Location getSafeDestination(Location l) {
double x = l.getX();
double y = l.getY();
double z = l.getZ();
@ -156,41 +137,4 @@ public class MVTeleport {
}
return -1;
}
/**
* Find a portal around the given location and return a new location.
*
* @param location
* @return
*/
public Location findPortal(Location location) {
World world = location.getWorld();
// Get list of columns in a circle around the block
ArrayList<Block> columns = new ArrayList<Block>();
for (int x = location.getBlockX() - 8; x <= location.getBlockX() + 8; ++x) {
for (int z = location.getBlockZ() - 8; z <= location.getBlockZ() + 8; ++z) {
int dx = location.getBlockX() - x, dz = location.getBlockZ() - z;
if (dx * dx + dz * dz <= 256) {
columns.add(world.getBlockAt(x, 0, z));
}
}
}
// For each column try to find a portal block
for (Block col : columns) {
for (int y = 0; y <= 127; y++) {
Block b = world.getBlockAt(col.getX(), y, col.getZ());
if (b.getType().equals(Material.PORTAL)) {
if (b.getWorld().getBlockAt(b.getX() + 1, b.getY(), b.getZ()).getType().equals(Material.PORTAL) || b.getWorld().getBlockAt(b.getX() - 1, b.getY(), b.getZ()).getType().equals(Material.PORTAL)) {
// portal is in X direction
return new Location(b.getWorld(), b.getX() + 0.5, b.getY(), b.getZ() + 1.5);
} else {
// portal is in Z direction
return new Location(b.getWorld(), b.getX() + 1.5, b.getY(), b.getZ() + 0.5);
}
}
}
}
return null;
}
}

View File

@ -107,17 +107,6 @@ public class TeleportCommand extends MultiverseCommand {
teleporter.sendMessage("Sorry Boss, I tried everything, but just couldn't teleport ya there!");
return;
}
// TODO: Put our teleporter back in...
System.out.print("Unsure:");
System.out.print(l);
System.out.print("Safe:");
Location safeLoc = this.playerTeleporter.getSafeDestination(l);
System.out.print(safeLoc);
if(safeLoc != null) {
teleportee.teleport(safeLoc);
} else {
teleportee.teleport(l);
}
this.playerTeleporter.safelyTeleport(teleportee, l);
}
}

View File

@ -41,5 +41,6 @@ public class VersionCommand extends MultiverseCommand {
this.plugin.log(Level.INFO, "opfallback: " + this.plugin.getConfig().getString("opfallback", "NOT SET"));
this.plugin.log(Level.INFO, "disableautoheal: " + this.plugin.getConfig().getString("disableautoheal", "NOT SET"));
this.plugin.log(Level.INFO, "fakepvp: " + this.plugin.getConfig().getString("fakepvp", "NOT SET"));
this.plugin.log(Level.INFO, "Special Code: FRN001");
}
}

View File

@ -7,7 +7,7 @@ import org.bukkit.World;
public class BlockSafety {
/**
* This function checks whether the block at the given coordinates are above air or not.
*
*
* @param world
* @param x
* @param y
@ -27,7 +27,7 @@ public class BlockSafety {
/**
* This function checks whether the block at the coordinates given is safe or not by checking for Laval/Fire/Air etc. This also ensures there is enough space for a player to spawn!
*
*
* @param world
* @param x
* @param y
@ -41,23 +41,37 @@ public class BlockSafety {
upOne.setY(upOne.getY() + 1);
downOne.setY(downOne.getY() - 1);
if (actual.getBlock().getType() != Material.AIR || upOne.getBlock().getType() != Material.AIR)
if (/*actual.getBlock().getType() != Material.AIR || */upOne.getBlock().getType() != Material.AIR) {
System.out.print("Air!");
return false;
}
if (downOne.getBlock().getType() == Material.LAVA)
if (downOne.getBlock().getType() == Material.LAVA) {
System.out.print("Lava!");
return false;
}
if (downOne.getBlock().getType() == Material.STATIONARY_LAVA)
if (downOne.getBlock().getType() == Material.STATIONARY_LAVA) {
System.out.print("Lava!!");
return false;
}
if (downOne.getBlock().getType() == Material.FIRE)
if (downOne.getBlock().getType() == Material.FIRE) {
System.out.print("Fire Below!");
return false;
}
if (actual.getBlock().getType() == Material.FIRE)
if (actual.getBlock().getType() == Material.FIRE) {
System.out.print("Fire!");
return false;
}
if (blockIsAboveAir(actual))
return false;
if (blockIsAboveAir(actual)) {
System.out.print("Above Air!");
// FOR NOW THIS IS OK
// TODO: Take out once the other one is fixed.
return true;
}
return true;
}