Deprecate 2 location methods in favor of using MVDestination instead of Location to preserver velocity.

This commit is contained in:
Eric Stokes 2011-08-21 10:32:07 -06:00
parent dc9f2fc360
commit d12725ca0e
4 changed files with 93 additions and 15 deletions

View File

@ -7,9 +7,11 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.util.Vector;
import com.onarandombox.utils.BlockSafety;
import com.onarandombox.utils.LocationManipulation;
import com.onarandombox.utils.MVDestination;
public class MVTeleport {
@ -181,15 +183,30 @@ public class MVTeleport {
return false;
}
/**
* Deprectated. use safelyTeleport(Entity e, Destination d)
*
* @param e
* @param l
* @return
*/
@Deprecated
public boolean safelyTeleport(Entity e, Location l) {
Location safeLoc = this.getSafeLocation(e, l);
if(safeLoc != null) {
if (safeLoc != null) {
e.teleport(safeLoc);
return true;
}
return false;
}
/**
*
* @param e
* @param l
* @return
*/
@Deprecated
public Location getSafeLocation(Entity e, Location l) {
if (this.bs.playerCanSpawnHereSafely(l)) {
plugin.log(Level.FINE, "The first location you gave me was safe.");
@ -231,4 +248,71 @@ public class MVTeleport {
return null;
}
/**
* Safely teleport the entity to the MVDestination. This will perform checks to see if the place is safe, and if it's not, will adjust the final destination accordingly.
* @param e Entity to teleport
* @param d Destination to teleport them to
* @return true for success, false for failure
*/
public boolean safelyTeleport(Entity e, MVDestination d) {
Location safeLoc = this.getSafeLocation(e, d);
if (safeLoc != null) {
e.teleport(safeLoc);
if (!d.getVelocity().equals(new Vector(0, 0, 0))) {
e.setVelocity(d.getVelocity());
}
return true;
}
return false;
}
/**
* Returns a safe location for the entity to spawn at.
*
* @param e The entity to spawn
* @param d The MVDestination to take the entity to.
* @return A new location to spawn the entity at.
*/
public Location getSafeLocation(Entity e, MVDestination d) {
Location l = d.getLocation(e);
if (this.bs.playerCanSpawnHereSafely(l)) {
plugin.log(Level.FINE, "The first location you gave me was safe.");
return l;
}
if (e instanceof Minecart) {
Minecart m = (Minecart) e;
if (!this.bs.canSpawnCartSafely(m)) {
return null;
}
}
else if (e instanceof Vehicle) {
Vehicle v = (Vehicle) e;
if (!this.bs.canSpawnVehicleSafely(v)) {
return null;
}
}
Location safeLocation = this.getSafeLocation(l);
if (safeLocation != null) {
// Add offset to account for a vehicle on dry land!
if (e instanceof Minecart && !this.bs.isEntitiyOnTrack(e, safeLocation)) {
safeLocation.setY(safeLocation.getBlockY() + .5);
this.plugin.log(Level.FINER, "Player was inside a minecart. Offsetting Y location.");
}
this.plugin.log(Level.FINE, "Had to look for a bit, but I found a safe place for ya!");
return safeLocation;
}
if (e instanceof Player) {
Player p = (Player) e;
p.sendMessage("No safe locations found!");
this.plugin.log(Level.FINER, "No safe location found for " + p.getName());
}
else if (e.getPassenger() instanceof Player) {
Player p = (Player) e.getPassenger();
p.sendMessage("No safe locations found!");
this.plugin.log(Level.FINER, "No safe location found for " + p.getName());
}
this.plugin.log(Level.FINE, "Sorry champ, you're basically trying to teleport into a minefield. I should just kill you now.");
return null;
}
}

View File

@ -16,8 +16,6 @@ import com.onarandombox.utils.LocationManipulation;
public class CoordCommand extends MultiverseCommand {
private LocationManipulation locMan = new LocationManipulation();
public CoordCommand(MultiverseCore plugin) {
super(plugin);
this.setName("Coordinates");

View File

@ -6,12 +6,8 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionDefault;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.gui.GenericButton;
import org.getspout.spoutapi.gui.GenericPopup;
import org.getspout.spoutapi.gui.InGameHUD;
import org.getspout.spoutapi.gui.InGameScreen;
import org.getspout.spoutapi.gui.ItemWidget;
import org.getspout.spoutapi.gui.PopupScreen;
import org.getspout.spoutapi.player.SpoutPlayer;

View File

@ -13,9 +13,10 @@ import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MVTeleport;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.MVDestination;
import com.onarandombox.utils.DestinationFactory;
import com.onarandombox.utils.InvalidDestination;
import com.onarandombox.utils.LocationManipulation;
import com.onarandombox.utils.MVDestination;
public class TeleportCommand extends MultiverseCommand {
private MVTeleport playerTeleporter;
@ -84,7 +85,7 @@ public class TeleportCommand extends MultiverseCommand {
}
}
DestinationFactory df = this.plugin.getDestinationFactory();// .parseDestination(worldName, (MultiverseCore) this.plugin);
DestinationFactory df = this.plugin.getDestinationFactory();
MVDestination d = df.getDestination(destinationName);
if (d != null && d instanceof InvalidDestination) {
sender.sendMessage("Multiverse does not know how to take you to: " + ChatColor.RED + destinationName);
@ -106,18 +107,17 @@ public class TeleportCommand extends MultiverseCommand {
}
return;
}
Location l = d.getLocation(teleportee);
if (l == null) {
if (d.getLocation(teleportee) == null) {
teleporter.sendMessage("Sorry Boss, I tried everything, but just couldn't teleport ya there!");
return;
}
if (!this.playerTeleporter.safelyTeleport(teleportee, l)) {
this.plugin.log(Level.FINE, "Could not teleport " + teleportee.getName() + " to " + l);
if (!this.playerTeleporter.safelyTeleport(teleportee, d)) {
this.plugin.log(Level.FINE, "Could not teleport " + teleportee.getName() + " to " + LocationManipulation.strCoordsRaw(d.getLocation(teleportee)));
this.plugin.log(Level.FINE, "Queueing Command");
Class<?> paramTypes[] = { Player.class, Location.class };
List<Object> items = new ArrayList<Object>();
items.add(teleportee);
items.add(l);
items.add(d.getLocation(teleportee));
String player = "you";
if (!teleportee.equals(teleporter)) {
player = teleportee.getName();