summaryrefslogtreecommitdiffstats
path: root/src/main
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
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')
-rw-r--r--src/main/java/net/minecraft/server/NetServerHandler.java26
-rw-r--r--src/main/java/net/minecraft/server/ServerConfigurationManager.java78
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java33
3 files changed, 76 insertions, 61 deletions
diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java
index b1aaab05..6a2eb2f7 100644
--- a/src/main/java/net/minecraft/server/NetServerHandler.java
+++ b/src/main/java/net/minecraft/server/NetServerHandler.java
@@ -358,30 +358,27 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
public void a(double d0, double d1, double d2, float f, float f1) {
// CraftBukkit start - Delegate to teleport(Location)
- teleport(new Location(getPlayer().getWorld(), d0, d1, d2, f, f1));
- }
-
- public boolean teleport(Location dest) {
- // Note: the world in location is used only for the event
- // Inter-world teleportation is handled in CraftPlayer.teleport()
-
Player player = getPlayer();
Location from = player.getLocation();
- Location to = dest.clone();
+ Location to = new Location(getPlayer().getWorld(), d0, d1, d2, f, f1);
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
server.getPluginManager().callEvent(event);
from = event.getFrom();
to = event.isCancelled() ? from : event.getTo();
+ teleport(to);
+ }
+
+ public void teleport(Location dest) {
double d0, d1, d2;
float f, f1;
- d0 = to.getX();
- d1 = to.getY();
- d2 = to.getZ();
- f = to.getYaw();
- f1 = to.getPitch();
+ d0 = dest.getX();
+ d1 = dest.getY();
+ d2 = dest.getZ();
+ f = dest.getYaw();
+ f1 = dest.getPitch();
// TODO: make sure this is the best way to address this.
if (Float.isNaN(f)) {
@@ -399,9 +396,6 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
this.z = d2;
this.player.setLocation(d0, d1, d2, f, f1);
this.player.netServerHandler.sendPacket(new Packet13PlayerLookMove(d0, d1 + 1.6200000047683716D, d1, d2, f, f1, false));
-
- // CraftBukkit - Returns TRUE if the teleport was successful
- return !event.isCancelled();
}
public void a(Packet14BlockDig packet14blockdig) {
diff --git a/src/main/java/net/minecraft/server/ServerConfigurationManager.java b/src/main/java/net/minecraft/server/ServerConfigurationManager.java
index 3a86026e..695db357 100644
--- a/src/main/java/net/minecraft/server/ServerConfigurationManager.java
+++ b/src/main/java/net/minecraft/server/ServerConfigurationManager.java
@@ -17,6 +17,7 @@ import org.bukkit.Location;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.command.ColouredConsoleSender;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@@ -256,8 +257,8 @@ public class ServerConfigurationManager {
entityplayer1.netServerHandler.sendPacket(new Packet9Respawn(actualDimension));
entityplayer1.a(worldserver);
entityplayer1.dead = false;
+ entityplayer1.netServerHandler.teleport(new Location(worldserver.getWorld(), entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch));
// CraftBukkit end
- entityplayer1.netServerHandler.a(entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch);
this.a(entityplayer1, worldserver);
this.a(entityplayer1.dimension).addPlayer(entityplayer1);
worldserver.addEntity(entityplayer1);
@@ -268,9 +269,10 @@ public class ServerConfigurationManager {
}
public void f(EntityPlayer entityplayer) {
+ // CraftBukkit start
WorldServer worldserver = this.server.a(entityplayer.dimension);
- boolean flag = false;
- byte b0;
+ boolean flag = false; // Unused
+ int b0; // byte -> int
if (entityplayer.dimension == -1) {
b0 = 0;
@@ -278,32 +280,17 @@ public class ServerConfigurationManager {
b0 = -1;
}
- // CraftBukkit start
- CraftWorld oldCraftWorld = worldserver.getWorld();
- CraftWorld newCraftWorld = this.server.a(b0).getWorld();
- Location startLocation = new Location(oldCraftWorld, entityplayer.locX, entityplayer.locY, entityplayer.locZ);
- Location endLocation;
- if (b0 == -1) {
- endLocation = new Location(newCraftWorld, entityplayer.locX / 8.0D, entityplayer.locY, entityplayer.locZ / 8.0D,entityplayer.yaw,entityplayer.pitch);
- } else {
- endLocation = new Location(newCraftWorld, entityplayer.locX * 8.0D, entityplayer.locY, entityplayer.locZ * 8.0D,entityplayer.yaw,entityplayer.pitch);
- }
- PlayerPortalEvent event = new PlayerPortalEvent((Player)entityplayer.getBukkitEntity(),startLocation,endLocation);
- Bukkit.getServer().getPluginManager().callEvent(event);
- if (event.isCancelled()) {
- return;
- }
-
// entityplayer.dimension = b0;
- WorldServer worldserver1 = this.server.a(b0);
+ // WorldServer worldserver1 = this.server.a(entityplayer.dimension);
- // entityplayer.netServerHandler.sendPacket(new Packet9Respawn((byte) ((WorldServer)entityplayer.world).getWorld().getEnvironment().getId()));
- // Craftbukkit end
+ // entityplayer.netServerHandler.sendPacket(new Packet9Respawn((byte) entityplayer.dimension));
+ // worldserver.removeEntity(entityplayer);
+ // entityplayer.dead = false;
double d0 = entityplayer.locX;
double d1 = entityplayer.locZ;
double d2 = 8.0D;
- if (b0 == -1) { // CraftBukkit
+ if (b0 == -1) { // entityplayer.dimension -> b0
d0 /= d2;
d1 /= d2;
entityplayer.setPositionRotation(d0, entityplayer.locY, d1, entityplayer.yaw, entityplayer.pitch);
@@ -319,26 +306,43 @@ public class ServerConfigurationManager {
}
}
+ CraftWorld fromCraftWorld = worldserver.getWorld();
+ CraftWorld toCraftWorld = this.server.a(b0).getWorld();
+ Location startLocation = new Location(fromCraftWorld, entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
+ Location endLocation = new Location(toCraftWorld, d0, entityplayer.locY, d1, entityplayer.yaw, entityplayer.pitch);
+
+ PlayerPortalEvent event = new PlayerPortalEvent((Player)entityplayer.getBukkitEntity(),startLocation,endLocation);
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ endLocation = event.getTo();
+
+ b0 = ((CraftWorld) endLocation.getWorld()).getHandle().dimension;
+
+ WorldServer worldserver1 = this.server.a(b0);
+
if (entityplayer.S()) {
- // worldserver1.addEntity(entityplayer); // CraftBukkit
- entityplayer.setPositionRotation(d0, entityplayer.locY, d1, entityplayer.yaw, entityplayer.pitch);
+ // worldserver1.addEntity(entityplayer);
+ entityplayer.setPositionRotation(endLocation.getX(), endLocation.getY(), endLocation.getZ(), endLocation.getYaw(), endLocation.getPitch());
worldserver1.entityJoinedWorld(entityplayer, false);
- // CraftBukkit start - added conditional
if (event.useTravelAgent()) {
worldserver1.chunkProviderServer.a = true;
(new PortalTravelAgent()).a(worldserver1, entityplayer);
worldserver1.chunkProviderServer.a = false;
- } // CraftBukkit end
- }
- /* CraftBukkit start
- this.a(entityplayer);
- entityplayer.netServerHandler.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
- entityplayer.a((World) worldserver1);
- this.a(entityplayer, worldserver1);
- this.g(entityplayer);
- */ // CraftBukkit end
- // CraftBukkit - defer for actual teleportation
- a(entityplayer, b0, new Location(null, entityplayer.locX, entityplayer.locY, entityplayer.locZ));
+ endLocation.setX(entityplayer.locX);
+ endLocation.setY(entityplayer.locY);
+ endLocation.setZ(entityplayer.locZ);
+ }
+ }
+
+ // this.a(entityplayer);
+ // entityplayer.netServerHandler.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
+ // entityplayer.a((World) worldserver1);
+ // this.a(entityplayer, worldserver1);
+ // this.g(entityplayer);
+ this.a(entityplayer, b0, endLocation);
+ // CraftBukkit end
}
public void b() {
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) {