Should allow spaces, needs testing

This commit is contained in:
Eric Stokes 2011-06-02 16:43:22 -04:00
parent 00b7af5c84
commit 3a6d401a72
4 changed files with 71 additions and 36 deletions

View File

@ -12,17 +12,19 @@ import org.bukkit.entity.Player;
import com.onarandombox.utils.BlockSafety;
public class MVTeleport {
MultiverseCore plugin;
BlockSafety bs = new BlockSafety();
private static final Logger log = Logger.getLogger("Minecraft");
public MVTeleport(MultiverseCore plugin) {
this.plugin = plugin;
}
/**
* TODO: Sort out JavaDoc
*
* @param l
* @param w
* @return
@ -33,15 +35,15 @@ public class MVTeleport {
if (l.getWorld().getName().equalsIgnoreCase(w.getName())) {
return l;
}
double x, y, z;
// Grab the Compression value for each world.
double srcComp = plugin.worlds.get(l.getWorld().getName()).compression;
double trgComp = plugin.worlds.get(w.getName()).compression;
// 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();
@ -54,7 +56,7 @@ public class MVTeleport {
}
return new Location(w, x, y, z);
}
/**
* This function gets a safe place to teleport to.
*
@ -67,12 +69,12 @@ public class MVTeleport {
double y = l.getY();
double z = l.getZ();
World w = l.getWorld();
// To make things easier we'll start with the Y Coordinate on top of a Solid Block.
// while (bs.blockIsAboveAir(w, x, y, z)) {
// y--;
// }
double i = 0, r = 0, aux = -1;
for (r = 0; r < 32; r++) {
for (i = x - r; i <= x + r; i++) {
@ -104,19 +106,20 @@ public class MVTeleport {
break;
}
}
if (aux == -1) {
log.warning("Uh oh, no safe location.");
return null;
}
log.info("Target location (safe): " + x + ", " + aux + ", " + z);
return new Location(w, x, aux, z);
}
/**
* Check the Column given to see if there is an available safe spot.
*
* @param world
* @param x
* @param y
@ -134,9 +137,10 @@ public class MVTeleport {
}
return -1;
}
/**
* Find a portal around the given location and return a new location.
*
* @param location
* @return
*/
@ -152,7 +156,7 @@ public class MVTeleport {
}
}
}
// For each column try to find a portal block
for (Block col : columns) {
for (int y = 0; y <= 127; y++) {

View File

@ -337,8 +337,10 @@ public class MultiverseCore extends JavaPlugin {
Long seed = null;
// Work out the Environment
Environment env;
if (environment.equalsIgnoreCase("NETHER")) { // Check if the selected Environment is NETHER, otherwise we just default to NORMAL.
if (environment.equalsIgnoreCase("NETHER")) {
env = Environment.NETHER;
} else if(environment.equalsIgnoreCase("NETHER")) {
env = Environment.SKYLANDS;
} else {
env = Environment.NORMAL;
}

View File

@ -15,29 +15,52 @@ public class CreateCommand extends BaseCommand {
super(plugin);
name = "Create World";
description = "Creates a new world of the specified type";
usage = "/mvcoord" + ChatColor.GREEN + "{NAME} {TYPE}";
// Syntax is s:SEED so we can see this variable seperately when spaces are allowed in worldnames
usage = "/mvcoord" + ChatColor.GREEN + "{NAME} {TYPE}" + ChatColor.GOLD + " [s:SEED]";
minArgs = 2;
maxArgs = 2;
maxArgs = 3;
identifiers.add("mvcoord");
}
@Override
public void execute(CommandSender sender, String[] args) {
// TODO: Permissions, check
if (args.length != 2) {
// TODO: Allow spaces in world names, currently this will catch it --FF
int numOfParams = args.length;
// By default the environment will be located at the end, unless there is a seed
int envPosition = numOfParams - 1;
boolean hasSeed = false;
String seed = "";
if(args[numOfParams - 1].substring(0, 2).equalsIgnoreCase("s:")) {
envPosition--;
hasSeed = true;
// Pull out the seed name, drop the "s:"
seed = args[numOfParams - 1].split(":")[1];
}
String env = args[envPosition];
String worldName = args[0];
for(int i = 1; i < envPosition; i++) {
worldName += " " + args[i];
}
if (args.length < 2) {
sender.sendMessage("Not enough parameters to create a new world");
sender.sendMessage(ChatColor.RED + "/mvcreate WORLDNAME ENVIRONMENT - Create a new World.");
sender.sendMessage(ChatColor.RED + "Example - /mvcreate hellworld nether");
sender.sendMessage(ChatColor.RED + "/mvcreate {WORLDNAME} {ENVIRONMENT} - Create a new World.");
sender.sendMessage(ChatColor.RED + "Example - /mvcreate world NORMAL");
sender.sendMessage(ChatColor.RED + "Example - /mvcreate airworld SKYLANDS");
sender.sendMessage(ChatColor.RED + "Example - /mvcreate hellworld NETHER");
return;
}
if (new File(args[0].toString()).exists()) {
if (new File(args[0]).exists() || this.plugin.worlds.containsKey(args[0])) {
sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
return;
}
// String name = args[0].toString();
String env = args[1].toString();
Environment environment = null;
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
if (env.equalsIgnoreCase("NETHER") || env.equalsIgnoreCase("HELL"))
environment = Environment.NETHER;
@ -51,6 +74,14 @@ public class CreateCommand extends BaseCommand {
sender.sendMessage(ChatColor.RED + "Environment type " + env + " does not exist!");
return;
}
if(hasSeed) {
plugin.getServer().createWorld(worldName, environment, Long.parseLong(seed));
plugin.addWorld(worldName, environment, Long.parseLong(seed));
} else {
plugin.getServer().createWorld(worldName, environment);
plugin.addWorld(worldName, environment);
}
return;
}

View File

@ -5,8 +5,7 @@ import org.bukkit.World;
public class BlockSafety {
/**
* This function checks whether the block at the given coordinates are above
* air or not.
* This function checks whether the block at the given coordinates are above air or not.
*
* @param world
* @param x
@ -17,10 +16,9 @@ public class BlockSafety {
public boolean blockIsAboveAir(World world, double x, double y, double z) {
return (world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.AIR);
}
/**
* This function checks whether the block at the coordinates given is safe
* or not by checking for Laval/Fire/Air etc.
* This function checks whether the block at the coordinates given is safe or not by checking for Laval/Fire/Air etc.
*
* @param world
* @param x
@ -31,23 +29,23 @@ public class BlockSafety {
public boolean blockIsNotSafe(World world, double x, double y, double z) {
if (world.getBlockAt((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)).getType() != Material.AIR || world.getBlockAt((int) Math.floor(x), (int) Math.floor(y + 1), (int) Math.floor(z)).getType() != Material.AIR)
return true;
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.LAVA))
return true;
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.STATIONARY_LAVA))
return true;
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.FIRE))
return true;
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)).getType() == Material.FIRE))
return true;
if (blockIsAboveAir(world, x, y, z))
return true;
return false;
}
}