Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-24 07:10:10 +01:00
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.
Dieser Commit ist enthalten in:
Ursprung
cd12f057a7
Commit
5b93f5565a
@ -358,30 +358,27 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
|||||||
|
|
||||||
public void a(double d0, double d1, double d2, float f, float f1) {
|
public void a(double d0, double d1, double d2, float f, float f1) {
|
||||||
// CraftBukkit start - Delegate to teleport(Location)
|
// 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();
|
Player player = getPlayer();
|
||||||
Location from = player.getLocation();
|
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);
|
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
|
||||||
server.getPluginManager().callEvent(event);
|
server.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
from = event.getFrom();
|
from = event.getFrom();
|
||||||
to = event.isCancelled() ? from : event.getTo();
|
to = event.isCancelled() ? from : event.getTo();
|
||||||
|
|
||||||
|
teleport(to);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void teleport(Location dest) {
|
||||||
double d0, d1, d2;
|
double d0, d1, d2;
|
||||||
float f, f1;
|
float f, f1;
|
||||||
|
|
||||||
d0 = to.getX();
|
d0 = dest.getX();
|
||||||
d1 = to.getY();
|
d1 = dest.getY();
|
||||||
d2 = to.getZ();
|
d2 = dest.getZ();
|
||||||
f = to.getYaw();
|
f = dest.getYaw();
|
||||||
f1 = to.getPitch();
|
f1 = dest.getPitch();
|
||||||
|
|
||||||
// TODO: make sure this is the best way to address this.
|
// TODO: make sure this is the best way to address this.
|
||||||
if (Float.isNaN(f)) {
|
if (Float.isNaN(f)) {
|
||||||
@ -399,9 +396,6 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
|||||||
this.z = d2;
|
this.z = d2;
|
||||||
this.player.setLocation(d0, d1, d2, f, f1);
|
this.player.setLocation(d0, d1, d2, f, f1);
|
||||||
this.player.netServerHandler.sendPacket(new Packet13PlayerLookMove(d0, d1 + 1.6200000047683716D, d1, d2, f, f1, false));
|
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) {
|
public void a(Packet14BlockDig packet14blockdig) {
|
||||||
|
@ -17,6 +17,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.craftbukkit.CraftWorld;
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.command.ColouredConsoleSender;
|
import org.bukkit.craftbukkit.command.ColouredConsoleSender;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerPortalEvent;
|
import org.bukkit.event.player.PlayerPortalEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
@ -256,8 +257,8 @@ public class ServerConfigurationManager {
|
|||||||
entityplayer1.netServerHandler.sendPacket(new Packet9Respawn(actualDimension));
|
entityplayer1.netServerHandler.sendPacket(new Packet9Respawn(actualDimension));
|
||||||
entityplayer1.a(worldserver);
|
entityplayer1.a(worldserver);
|
||||||
entityplayer1.dead = false;
|
entityplayer1.dead = false;
|
||||||
|
entityplayer1.netServerHandler.teleport(new Location(worldserver.getWorld(), entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch));
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
entityplayer1.netServerHandler.a(entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch);
|
|
||||||
this.a(entityplayer1, worldserver);
|
this.a(entityplayer1, worldserver);
|
||||||
this.a(entityplayer1.dimension).addPlayer(entityplayer1);
|
this.a(entityplayer1.dimension).addPlayer(entityplayer1);
|
||||||
worldserver.addEntity(entityplayer1);
|
worldserver.addEntity(entityplayer1);
|
||||||
@ -268,9 +269,10 @@ public class ServerConfigurationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void f(EntityPlayer entityplayer) {
|
public void f(EntityPlayer entityplayer) {
|
||||||
|
// CraftBukkit start
|
||||||
WorldServer worldserver = this.server.a(entityplayer.dimension);
|
WorldServer worldserver = this.server.a(entityplayer.dimension);
|
||||||
boolean flag = false;
|
boolean flag = false; // Unused
|
||||||
byte b0;
|
int b0; // byte -> int
|
||||||
|
|
||||||
if (entityplayer.dimension == -1) {
|
if (entityplayer.dimension == -1) {
|
||||||
b0 = 0;
|
b0 = 0;
|
||||||
@ -278,32 +280,17 @@ public class ServerConfigurationManager {
|
|||||||
b0 = -1;
|
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;
|
// 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()));
|
// entityplayer.netServerHandler.sendPacket(new Packet9Respawn((byte) entityplayer.dimension));
|
||||||
// Craftbukkit end
|
// worldserver.removeEntity(entityplayer);
|
||||||
|
// entityplayer.dead = false;
|
||||||
double d0 = entityplayer.locX;
|
double d0 = entityplayer.locX;
|
||||||
double d1 = entityplayer.locZ;
|
double d1 = entityplayer.locZ;
|
||||||
double d2 = 8.0D;
|
double d2 = 8.0D;
|
||||||
|
|
||||||
if (b0 == -1) { // CraftBukkit
|
if (b0 == -1) { // entityplayer.dimension -> b0
|
||||||
d0 /= d2;
|
d0 /= d2;
|
||||||
d1 /= d2;
|
d1 /= d2;
|
||||||
entityplayer.setPositionRotation(d0, entityplayer.locY, d1, entityplayer.yaw, entityplayer.pitch);
|
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()) {
|
if (entityplayer.S()) {
|
||||||
// worldserver1.addEntity(entityplayer); // CraftBukkit
|
// worldserver1.addEntity(entityplayer);
|
||||||
entityplayer.setPositionRotation(d0, entityplayer.locY, d1, entityplayer.yaw, entityplayer.pitch);
|
entityplayer.setPositionRotation(endLocation.getX(), endLocation.getY(), endLocation.getZ(), endLocation.getYaw(), endLocation.getPitch());
|
||||||
worldserver1.entityJoinedWorld(entityplayer, false);
|
worldserver1.entityJoinedWorld(entityplayer, false);
|
||||||
// CraftBukkit start - added conditional
|
|
||||||
if (event.useTravelAgent()) {
|
if (event.useTravelAgent()) {
|
||||||
worldserver1.chunkProviderServer.a = true;
|
worldserver1.chunkProviderServer.a = true;
|
||||||
(new PortalTravelAgent()).a(worldserver1, entityplayer);
|
(new PortalTravelAgent()).a(worldserver1, entityplayer);
|
||||||
worldserver1.chunkProviderServer.a = false;
|
worldserver1.chunkProviderServer.a = false;
|
||||||
} // CraftBukkit end
|
endLocation.setX(entityplayer.locX);
|
||||||
|
endLocation.setY(entityplayer.locY);
|
||||||
|
endLocation.setZ(entityplayer.locZ);
|
||||||
}
|
}
|
||||||
/* CraftBukkit start
|
}
|
||||||
this.a(entityplayer);
|
|
||||||
entityplayer.netServerHandler.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
|
// this.a(entityplayer);
|
||||||
entityplayer.a((World) worldserver1);
|
// entityplayer.netServerHandler.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
|
||||||
this.a(entityplayer, worldserver1);
|
// entityplayer.a((World) worldserver1);
|
||||||
this.g(entityplayer);
|
// this.a(entityplayer, worldserver1);
|
||||||
*/ // CraftBukkit end
|
// this.g(entityplayer);
|
||||||
// CraftBukkit - defer for actual teleportation
|
this.a(entityplayer, b0, endLocation);
|
||||||
a(entityplayer, b0, new Location(null, entityplayer.locX, entityplayer.locY, entityplayer.locZ));
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
|
|
||||||
public void b() {
|
public void b() {
|
||||||
|
@ -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) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren