Fix inconsistencies between offline/online spawn position getter (#11960)
This commit is contained in:
@@ -6,7 +6,6 @@ import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.core.GlobalPos;
|
||||
@@ -33,8 +32,6 @@ import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@SerializableAs("Player")
|
||||
public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable {
|
||||
@@ -362,18 +359,23 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getRespawnLocation() {
|
||||
CompoundTag data = this.getData();
|
||||
public Location getRespawnLocation(final boolean loadLocationAndValidate) {
|
||||
final CompoundTag data = this.getData();
|
||||
if (data == null) return null;
|
||||
|
||||
final ServerPlayer.RespawnConfig respawnConfig = data.read("respawn", ServerPlayer.RespawnConfig.CODEC).orElse(null);
|
||||
if (respawnConfig != null) {
|
||||
final ServerLevel level = this.server.console.getLevel(respawnConfig.dimension());
|
||||
if (level != null) {
|
||||
return CraftLocation.toBukkit(respawnConfig.pos(), level.getWorld(), respawnConfig.angle(), 0);
|
||||
}
|
||||
if (respawnConfig == null) return null;
|
||||
|
||||
final ServerLevel level = this.server.console.getLevel(respawnConfig.dimension());
|
||||
if (level == null) return null;
|
||||
|
||||
if (!loadLocationAndValidate) {
|
||||
return CraftLocation.toBukkit(respawnConfig.pos(), level.getWorld(), respawnConfig.angle(), 0);
|
||||
}
|
||||
return null;
|
||||
|
||||
return ServerPlayer.findRespawnAndUseSpawnBlock(level, respawnConfig, false)
|
||||
.map(resolvedPos -> CraftLocation.toBukkit(resolvedPos.position(), level.getWorld(), resolvedPos.yaw(), 0))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private ServerStatsCounter getStatisticManager() {
|
||||
|
||||
@@ -1541,19 +1541,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getRespawnLocation() {
|
||||
public Location getRespawnLocation(final boolean loadLocationAndValidate) {
|
||||
final ServerPlayer.RespawnConfig respawnConfig = this.getHandle().getRespawnConfig();
|
||||
if (respawnConfig == null) return null;
|
||||
|
||||
ServerLevel world = this.getHandle().server.getLevel(respawnConfig.dimension());
|
||||
if (world != null) {
|
||||
Optional<ServerPlayer.RespawnPosAngle> spawnLoc = ServerPlayer.findRespawnAndUseSpawnBlock(world, respawnConfig, true);
|
||||
if (spawnLoc.isPresent()) {
|
||||
ServerPlayer.RespawnPosAngle vec = spawnLoc.get();
|
||||
return CraftLocation.toBukkit(vec.position(), world.getWorld(), vec.yaw(), 0);
|
||||
}
|
||||
final ServerLevel world = this.getHandle().server.getLevel(respawnConfig.dimension());
|
||||
if (world == null) return null;
|
||||
|
||||
if (!loadLocationAndValidate) {
|
||||
return CraftLocation.toBukkit(respawnConfig.pos(), world.getWorld(), respawnConfig.angle(), 0);
|
||||
}
|
||||
return null;
|
||||
|
||||
return ServerPlayer.findRespawnAndUseSpawnBlock(world, respawnConfig, false)
|
||||
.map(pos -> CraftLocation.toBukkit(pos.position(), world.getWorld(), pos.yaw(), 0))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user