Allow our own spawns to be more accurate, including decimal precision on XYZ and Pitch/Yaw.

We still set the spawn in the bukkit worlds to the inaccurate setting.
No migrator is included for this change, just do /mvss in game.
This commit is contained in:
Eric Stokes 2011-08-21 08:34:07 -06:00
parent f11f3dd88e
commit 2c865aa0ff
5 changed files with 85 additions and 18 deletions

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.Player;
@ -97,6 +98,7 @@ public class MVWorld {
private boolean canSave = false; // Prevents all the setters from constantly saving to the config when being called from the constructor.
private boolean allowWeather;
private Location spawnLocation;
public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) {
this.config = config;
@ -140,7 +142,7 @@ public class MVWorld {
this.getWorldBlacklist().addAll(config.getStringList("worlds." + this.name + ".worldblacklist", new ArrayList<String>()));
this.getBlockBlacklist().addAll(config.getIntList("worlds." + this.name + ".blockblacklist", new ArrayList<Integer>()));
this.translateTempSpawn(config);
this.readSpawnFromConfig(this.getCBWorld());
this.canSave = true;
saveConfig();
@ -202,7 +204,7 @@ public class MVWorld {
coords[i] = Integer.parseInt(coordsString[i]);
}
this.world.setSpawnLocation(coords[0], coords[1], coords[2]);
this.setSpawn(new Location(this.getCBWorld(), coords[0], coords[2], coords[3]));
} catch (NumberFormatException e) {
this.plugin.log(Level.WARNING, "A MV1 spawn value was found, but it could not be migrated. Format Error. Sorry.");
}
@ -631,8 +633,35 @@ public class MVWorld {
public boolean getWeatherEnabled() {
return this.allowWeather;
}
public boolean getKeepSpawnInMemory() {
return this.keepSpawnInMemory;
}
public boolean setSpawn(Location l) {
this.getCBWorld().setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
config.setProperty("worlds." + this.name + ".spawn.x", l.getX());
config.setProperty("worlds." + this.name + ".spawn.y", l.getY());
config.setProperty("worlds." + this.name + ".spawn.z", l.getZ());
config.setProperty("worlds." + this.name + ".spawn.pitch", l.getPitch());
config.setProperty("worlds." + this.name + ".spawn.yaw", l.getYaw());
this.getCBWorld().setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
this.spawnLocation = l.clone();
saveConfig();
return true;
}
private void readSpawnFromConfig(World w) {
double x = config.getDouble("worlds." + this.name + ".spawn.x", w.getSpawnLocation().getX());
double y = config.getDouble("worlds." + this.name + ".spawn.y", w.getSpawnLocation().getY());
double z = config.getDouble("worlds." + this.name + ".spawn.z", w.getSpawnLocation().getZ());
float pitch = (float) config.getDouble("worlds." + this.name + ".spawn.pitch", w.getSpawnLocation().getPitch());
float yaw = (float) config.getDouble("worlds." + this.name + ".spawn.yaw", w.getSpawnLocation().getYaw());
this.spawnLocation = new Location(w, x, y, z, yaw, pitch);
}
public Location getSpawnLocation() {
return this.spawnLocation;
}
}

View File

@ -50,7 +50,7 @@ public class CoordCommand extends MultiverseCommand {
DecimalFormat df = new DecimalFormat();
df.setMinimumFractionDigits(0);
df.setMaximumFractionDigits(2);
p.sendMessage(ChatColor.AQUA + "Coordinates: " + ChatColor.WHITE + this.locMan.strCoords(p.getLocation()) + ChatColor.GOLD + "Pitch: " + df.format(p.getLocation().getPitch()));
p.sendMessage(ChatColor.AQUA + "Coordinates: " + ChatColor.WHITE + LocationManipulation.strCoords(p.getLocation()));
p.sendMessage(ChatColor.AQUA + "Direction: " + ChatColor.WHITE + LocationManipulation.getDirection(p.getLocation()));
p.sendMessage(ChatColor.AQUA + "Block: " + ChatColor.WHITE + Material.getMaterial(world.getBlockTypeIdAt(p.getLocation())));
} else {

View File

@ -8,7 +8,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.LocationManipulation;
public class SetSpawnCommand extends MultiverseCommand {
@ -31,8 +33,16 @@ public class SetSpawnCommand extends MultiverseCommand {
Player p = (Player) sender;
Location l = p.getLocation();
World w = p.getWorld();
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
p.sendMessage(w.getName() + " - Spawn set to X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ());
MVWorld foundWorld = this.plugin.getMVWorld(w.getName());
if(foundWorld != null) {
foundWorld.setSpawn(p.getLocation());
sender.sendMessage("Spawn was set to: " + LocationManipulation.strCoords(p.getLocation()));
} else {
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
sender.sendMessage("Multiverse does not know about this world, only X,Y and Z set. Please import it to set the spawn fully.");
}
} else {
sender.sendMessage("You cannot use this command from the console.");
}

View File

@ -74,17 +74,26 @@ public class MVPlayerListener extends PlayerListener {
}
// If it's null then it either means the World doesn't exist or the value is blank, so we don't handle it.
if (respawnWorld == null) {
return;
// NOW: We'll always handle it to get more accurate spawns
if (respawnWorld != null) {
world = respawnWorld.getCBWorld();
}
Location respawnLocation = respawnWorld.getCBWorld().getSpawnLocation();
// World has been set to the appropriate world
Location respawnLocation = getMostAccurateRespawnLocation(world);
MVRespawnEvent respawnEvent = new MVRespawnEvent(respawnLocation, event.getPlayer(), "compatability");
this.plugin.getServer().getPluginManager().callEvent(respawnEvent);
event.setRespawnLocation(respawnEvent.getPlayersRespawnLocation());
}
private Location getMostAccurateRespawnLocation(World w) {
MVWorld mvw = this.plugin.getMVWorld(w.getName());
if (mvw != null) {
return mvw.getSpawnLocation();
}
return w.getSpawnLocation();
}
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
if (this.plugin.getMVWorlds().size() == 0 && this.plugin.getPermissions().hasPermission(event.getPlayer(), "multiverse.core.import", true)) {
@ -118,14 +127,14 @@ public class MVPlayerListener extends PlayerListener {
return;
}
}
if(toWorld == null) {
if (toWorld == null) {
// The toworld is not handled by MV, we don't care about payments
return;
}
// Only check payments if it's a different world:
if (!event.getTo().getWorld().equals(event.getFrom().getWorld())) {
// If the player does not have to pay, return now.
if(toWorld.isExempt(event.getPlayer())) {
if (toWorld.isExempt(event.getPlayer())) {
return;
}
GenericBank bank = plugin.getBank();

View File

@ -62,12 +62,11 @@ public class LocationManipulation {
}
/**
* Convert a Location to XYZ Coordinates.
*
* Returns a colored string with the coords
* @param l
* @return
*/
public String strCoords(Location l) {
public static String strCoords(Location l) {
String result = "";
DecimalFormat df = new DecimalFormat();
df.setMinimumFractionDigits(0);
@ -75,9 +74,15 @@ public class LocationManipulation {
result += ChatColor.WHITE + "X: " + ChatColor.AQUA + df.format(l.getX()) + " ";
result += ChatColor.WHITE + "Y: " + ChatColor.AQUA + df.format(l.getY()) + " ";
result += ChatColor.WHITE + "Z: " + ChatColor.AQUA + df.format(l.getZ()) + " ";
result += ChatColor.WHITE + "P: " + ChatColor.GOLD + df.format(l.getPitch()) + " ";
result += ChatColor.WHITE + "Y: " + ChatColor.GOLD + df.format(l.getYaw()) + " ";
return result;
}
/**
* Converts a location to a printable readable formatted string including pitch/yaw
* @param l
* @return
*/
public static String strCoordsRaw(Location l) {
String result = "";
DecimalFormat df = new DecimalFormat();
@ -122,7 +127,11 @@ public class LocationManipulation {
return dir;
}
/**
* Returns the float yaw position for the given cardianl direction
* @param orientation
* @return
*/
public static float getYaw(String orientation) {
if (orientation == null) {
return 0;
@ -132,13 +141,23 @@ public class LocationManipulation {
}
return 0;
}
/**
* Returns a speed float from a given vector.
* @param v
* @return
*/
public static float getSpeed(Vector v) {
return (float) Math.sqrt(v.getX() * v.getX() + v.getZ() * v.getZ());
}
// X, Y, Z
// -W/+E,0, -N/+S
/**
* Returns a translated vector from the given direction
* @param v
* @param direction
* @return
*/
public static Vector getTranslatedVector(Vector v, String direction) {
if (direction == null) {
return v;