From f7f18879e3d6da59380fe9504da187783de024e7 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 31 Jan 2012 13:50:12 -0600 Subject: [PATCH] [Bleeding] Added Vanish API for hiding players from each other. Adds Player.hidePlayer, Player.showPlayer, and Player.canSee for managing what players are hidden from a player. When someone is hidden from a player the player cannot see them in the user list or /list and they cannot /tell them so they appear to be completely gone from the server. By: Travis Watkins --- .../bukkit/command/defaults/ListCommand.java | 4 ++++ .../bukkit/command/defaults/TellCommand.java | 3 ++- .../main/java/org/bukkit/entity/Player.java | 22 +++++++++++++++++++ .../bukkit/plugin/messaging/TestPlayer.java | 12 ++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/paper-api/src/main/java/org/bukkit/command/defaults/ListCommand.java b/paper-api/src/main/java/org/bukkit/command/defaults/ListCommand.java index b7fc3b0a1e..67f58fa4fc 100644 --- a/paper-api/src/main/java/org/bukkit/command/defaults/ListCommand.java +++ b/paper-api/src/main/java/org/bukkit/command/defaults/ListCommand.java @@ -19,6 +19,10 @@ public class ListCommand extends VanillaCommand { StringBuilder players = new StringBuilder(); for (Player player : Bukkit.getOnlinePlayers()) { + // If a player is hidden from the sender don't show them in the list + if (sender instanceof Player && !((Player) sender).canSee(player)) + continue; + if (players.length() > 0) { players.append(", "); } diff --git a/paper-api/src/main/java/org/bukkit/command/defaults/TellCommand.java b/paper-api/src/main/java/org/bukkit/command/defaults/TellCommand.java index 4fce3b1c2a..4cc31bc82d 100644 --- a/paper-api/src/main/java/org/bukkit/command/defaults/TellCommand.java +++ b/paper-api/src/main/java/org/bukkit/command/defaults/TellCommand.java @@ -24,7 +24,8 @@ public class TellCommand extends VanillaCommand { Player player = Bukkit.getPlayerExact(args[0]); - if (player == null) { + // If a player is hidden from the sender pretend they are offline + if (player == null || (sender instanceof Player && !((Player) sender).canSee(player))) { sender.sendMessage("There's no player by that name online."); } else { StringBuilder message = new StringBuilder(); diff --git a/paper-api/src/main/java/org/bukkit/entity/Player.java b/paper-api/src/main/java/org/bukkit/entity/Player.java index 21e8204ab2..1ee3722e32 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Player.java +++ b/paper-api/src/main/java/org/bukkit/entity/Player.java @@ -490,4 +490,26 @@ public interface Player extends HumanEntity, CommandSender, OfflinePlayer, Plugi */ public void setAllowFlight(boolean flight); + /** + * Hides a player from this player + * + * @param player Player to hide + */ + public void hidePlayer(Player player); + + /** + * Allows this player to see a player that was previously hidden + * + * @param player Player to show + */ + public void showPlayer(Player player); + + /** + * Checks to see if a player has been hidden from this player + * + * @param player Player to check + * @return True if the provided player is not being hidden from this player + */ + public boolean canSee(Player player); + } diff --git a/paper-api/src/test/java/org/bukkit/plugin/messaging/TestPlayer.java b/paper-api/src/test/java/org/bukkit/plugin/messaging/TestPlayer.java index 4bef1f02e8..95e02c7646 100644 --- a/paper-api/src/test/java/org/bukkit/plugin/messaging/TestPlayer.java +++ b/paper-api/src/test/java/org/bukkit/plugin/messaging/TestPlayer.java @@ -609,4 +609,16 @@ public class TestPlayer implements Player { public void setBedSpawnLocation(Location location) { throw new UnsupportedOperationException("Not supported yet."); } + + public void hidePlayer(Player player) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void showPlayer(Player player) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public boolean canSee(Player player) { + throw new UnsupportedOperationException("Not supported yet."); + } }