summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit
diff options
context:
space:
mode:
authorEvilSeph <evilseph@unaligned.org>2011-06-10 22:59:54 -0400
committerEvilSeph <evilseph@unaligned.org>2011-06-11 01:33:37 -0400
commit5b93f5565a1807f6aae771aae935a021409dba29 (patch)
tree65f15ec06b85b781aacd07b3a6f67196024e3a9a /src/main/java/org/bukkit
parentcd12f057a75868ca3eb131413494c2ee0e182497 (diff)
downloadcraftbukkit-5b93f5565a1807f6aae771aae935a021409dba29.tar
craftbukkit-5b93f5565a1807f6aae771aae935a021409dba29.tar.gz
craftbukkit-5b93f5565a1807f6aae771aae935a021409dba29.tar.lz
craftbukkit-5b93f5565a1807f6aae771aae935a021409dba29.tar.xz
craftbukkit-5b93f5565a1807f6aae771aae935a021409dba29.zip
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.
Diffstat (limited to 'src/main/java/org/bukkit')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 9b49790d..691995a7 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -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();
+ // 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();
-
- if (oldWorld != newWorld) {
- manager.a(entity, newWorld.dimension, location);
- return true; //best guess
+ // Check if the fromWorld and toWorld are the same.
+ if (fromWorld == toWorld){
+ entity.netServerHandler.teleport(to);
} else {
- return entity.netServerHandler.teleport(location);
+ server.getHandle().a(entity, toWorld.dimension, to);
}
+ return true;
}
public void setSneaking(boolean sneak) {