fix: being able to teleport a dead player (#758)

* fix: being able to teleport a dead player

* why did this changes not get commited

* chore: update javadoc
This commit is contained in:
Preva1l authored and GitHub committed 2025-01-30 22:53:44 +00:00
1 parent c2de97baea
commit 3190a81b7d
6 files changed
+40 -1

No files matched your search

@@ -175,4 +175,13 @@ public class BukkitUser extends OnlineUser {
markedAsInvulnerable = false;
}
/**
* Check if the teleporter can teleport.
*
* @return true if the teleport may complete.
*/
@Override
public boolean isValid() {
return getHealth() > 0;
}
}
@@ -82,6 +82,10 @@ public class Teleport implements Completable {
* @throws TeleportationException if the teleport fails for some reason.
*/
public void execute() throws TeleportationException {
if (!teleporter.isValid()) {
throw new TeleportationException(TeleportationException.Type.TELEPORTER_INVALID, plugin);
}
validateTransactions();
resolveLocalTeleporter().ifPresentOrElse(this::executeLocal, this::executeRemote);
}
@@ -49,6 +49,13 @@ public interface Teleportable {
@NotNull
String getName();
/**
* Check if the teleporter can teleport.
*
* @return true if the teleport may complete.
*/
boolean isValid();
@NotNull
@Deprecated(since = "4.8")
default String getUsername() {
@@ -80,7 +80,8 @@ public class TeleportationException extends IllegalStateException {
WARMUP_ALREADY_MOVING,
WORLD_NOT_FOUND,
ILLEGAL_TARGET_COORDINATES,
CANNOT_TELEPORT_TO_SELF
CANNOT_TELEPORT_TO_SELF,
TELEPORTER_INVALID
}
}
@@ -65,4 +65,13 @@ public record Username(@NotNull String name) implements Teleportable, Target {
return name;
}
/**
* Check if the teleporter can teleport.
*
* @return true if the teleport may complete.
*/
@Override
public boolean isValid() {
return false;
}
}
@@ -196,4 +196,13 @@ public class FabricUser extends OnlineUser {
return player;
}
/**
* Check if the teleporter can teleport.
*
* @return true if the teleport may complete.
*/
@Override
public boolean isValid() {
return player.isAlive();
}
}