Fix /tp command not working for vanished users, close #255

This commit is contained in:
William committed 2022-10-29 17:43:55 +01:00
1 parent 88802db702
commit e20dcc4ce4
1 file changed
+8 -1
@@ -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<String> 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())