Fixed from and to worlds being the same for a PlayerTeleportEvent for crossworld teleports. Thanks for the help Rigby and Verrier! Tahg is responsible for the mess.

By: EvilSeph <evilseph@unaligned.org>
This commit is contained in:
CraftBukkit/Spigot 2011-06-10 22:59:54 -04:00
parent 648b50c4f4
commit 81ef43a0cc

View file

@ -21,6 +21,7 @@ import org.bukkit.Statistic;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
public class CraftPlayer extends CraftHumanEntity implements Player { public class CraftPlayer extends CraftHumanEntity implements Player {
@ -198,17 +199,33 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override @Override
public boolean teleport(Location location) { public boolean teleport(Location location) {
WorldServer oldWorld = ((CraftWorld)getWorld()).getHandle(); // From = Players current Location
WorldServer newWorld = ((CraftWorld)location.getWorld()).getHandle(); Location from = this.getLocation();
ServerConfigurationManager manager = server.getHandle(); // To = Players new Location if Teleport is Successful
EntityPlayer entity = getHandle(); Location to = location;
// Create & Call the Teleport Event.
if (oldWorld != newWorld) { PlayerTeleportEvent event = new PlayerTeleportEvent((Player) this, from, to);
manager.a(entity, newWorld.dimension, location); server.getPluginManager().callEvent(event);
return true; //best guess // Return False to inform the Plugin that the Teleport was unsuccessful/cancelled.
} else { if (event.isCancelled() == true) {
return entity.netServerHandler.teleport(location); return false;
} }
// Update the From Location
from = event.getFrom();
// Grab the new To Location dependent on whether the event was cancelled.
to = event.getTo();
// Grab the To and From World Handles.
WorldServer fromWorld = ((CraftWorld) from.getWorld()).getHandle();
WorldServer toWorld = ((CraftWorld) to.getWorld()).getHandle();
// Grab the EntityPlayer
EntityPlayer entity = getHandle();
// Check if the fromWorld and toWorld are the same.
if (fromWorld == toWorld){
entity.netServerHandler.teleport(to);
} else {
server.getHandle().a(entity, toWorld.dimension, to);
}
return true;
} }
public void setSneaking(boolean sneak) { public void setSneaking(boolean sneak) {