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.CraftWorld;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
public class CraftPlayer extends CraftHumanEntity implements Player {
@ -198,17 +199,33 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public boolean teleport(Location location) {
WorldServer oldWorld = ((CraftWorld)getWorld()).getHandle();
WorldServer newWorld = ((CraftWorld)location.getWorld()).getHandle();
ServerConfigurationManager manager = server.getHandle();
EntityPlayer entity = getHandle();
if (oldWorld != newWorld) {
manager.a(entity, newWorld.dimension, location);
return true; //best guess
} else {
return entity.netServerHandler.teleport(location);
// From = Players current Location
Location from = this.getLocation();
// To = Players new Location if Teleport is Successful
Location to = location;
// Create & Call the Teleport Event.
PlayerTeleportEvent event = new PlayerTeleportEvent((Player) this, from, to);
server.getPluginManager().callEvent(event);
// Return False to inform the Plugin that the Teleport was unsuccessful/cancelled.
if (event.isCancelled() == true) {
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) {