From e20dcc4ce4eaf7201f16cb0e01c9c03756e34b87 Mon Sep 17 00:00:00 2001 From: William Date: Sat, 29 Oct 2022 17:43:55 +0100 Subject: [PATCH] Fix /tp command not working for vanished users, close #255 --- .../java/net/william278/huskhomes/command/TpCommand.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/net/william278/huskhomes/command/TpCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpCommand.java index 01d6a4f5..cc8a5ef9 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpCommand.java @@ -39,7 +39,14 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe // Find the online user to teleport plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenRun(() -> { - final String playerToTeleport = plugin.getCache().players.stream() + // Get the list of potential teleports, filtered against vanished players, but ensuring the executor is in the list + final List players = plugin.getCache().players; + if (!players.contains(onlineUser.username)) { + players.add(onlineUser.username); + } + + // Find the player to teleport + final String playerToTeleport = players.stream() .filter(user -> user.equalsIgnoreCase(targetPlayerToTeleport)).findFirst() .or(() -> Optional.ofNullable(targetPlayerToTeleport.equals("@s") ? onlineUser.username : null)) .or(() -> plugin.getCache().players.stream().filter(user -> user.toLowerCase().startsWith(targetPlayerToTeleport)).findFirst())