tp to move directly in the same scene (#2375)

This commit is contained in:
jie65535 2023-09-18 09:01:21 +08:00 committed by GitHub
parent ff6a51db30
commit 43db7eba8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -396,19 +396,31 @@ public class World implements Iterable<Player> {
return false;
}
Scene oldScene = null;
if (player.getScene() != null) {
oldScene = player.getScene();
Scene oldScene = player.getScene();
var newScene = this.getSceneById(teleportProperties.getSceneId());
// Don't deregister scenes if the player is going to tp back into them
if (oldScene.getId() == teleportProperties.getSceneId()) {
oldScene.setDontDestroyWhenEmpty(true);
// Move directly in the same scene.
if (newScene == oldScene && teleportProperties.getTeleportType() == TeleportType.COMMAND) {
// Set player position and rotation
if (teleportProperties.getTeleportTo() != null) {
player.getPosition().set(teleportProperties.getTeleportTo());
}
if (teleportProperties.getTeleportRot() != null) {
player.getRotation().set(teleportProperties.getTeleportRot());
}
player.sendPacket(new PacketSceneEntityAppearNotify(player));
return true;
}
if (oldScene != null) {
// Don't deregister scenes if the player is going to tp back into them
if (oldScene == newScene) {
oldScene.setDontDestroyWhenEmpty(true);
}
oldScene.removePlayer(player);
}
var newScene = this.getSceneById(teleportProperties.getSceneId());
if (newScene != null) {
newScene.addPlayer(player);
player.getTeamManager().applyAbilities(newScene);
@ -429,6 +441,8 @@ public class World implements Iterable<Player> {
teleportProperties.setTeleportRot(config.born_rot);
}
}
}
// Set player position and rotation
if (teleportProperties.getTeleportTo() != null) {
@ -438,7 +452,7 @@ public class World implements Iterable<Player> {
player.getRotation().set(teleportProperties.getTeleportRot());
}
if (oldScene != null && newScene != oldScene) {
if (oldScene != null && newScene != null && newScene != oldScene) {
newScene.setPrevScenePoint(oldScene.getPrevScenePoint());
oldScene.setDontDestroyWhenEmpty(false);
}