From 3e7fe526815292b256a3e5021d742f3a7f96b2ce Mon Sep 17 00:00:00 2001 From: Minecrell Date: Thu, 9 Jan 2014 16:45:05 +0100 Subject: [PATCH 1/3] Correctly modify player sample with hidden player counts. At the moment the setPlayers() method will throw a NullPointerException if the player count has been hidden. This will correctly reset the player counts before setting the player list and return null in the getter instead of throwing an exception. --- .../com/comphenix/protocol/wrappers/WrappedServerPing.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java index 7dd83966..a783052e 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java @@ -241,9 +241,11 @@ public class WrappedServerPing extends AbstractWrapper { /** * Retrieve a copy of all the logged in players. - * @return Logged in players. + * @return Logged in players or NULL if the player count has been hidden via {@link #setPlayersVisible(boolean)}. */ public ImmutableList getPlayers() { + if (players == null) + return null; return ImmutableList.copyOf(PROFILE_CONVERT.getSpecific(PLAYERS_PROFILES.get(players))); } @@ -252,6 +254,8 @@ public class WrappedServerPing extends AbstractWrapper { * @param profile - every logged in player. */ public void setPlayers(Iterable profile) { + if (players == null) + resetPlayers(); PLAYERS_PROFILES.set(players, PROFILE_CONVERT.getGeneric(GameProfile[].class, profile)); } From 2a729cfe2d17b180add0b885b4601c14446b5054 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Thu, 9 Jan 2014 17:18:34 +0100 Subject: [PATCH 2/3] Return an empty list instead of null when getting the player sample. --- .../com/comphenix/protocol/wrappers/WrappedServerPing.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java index a783052e..437b5b5c 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java @@ -241,11 +241,11 @@ public class WrappedServerPing extends AbstractWrapper { /** * Retrieve a copy of all the logged in players. - * @return Logged in players or NULL if the player count has been hidden via {@link #setPlayersVisible(boolean)}. + * @return Logged in players or an empty list if no player names will be displayed. */ public ImmutableList getPlayers() { if (players == null) - return null; + return ImmutableList.of(); return ImmutableList.copyOf(PROFILE_CONVERT.getSpecific(PLAYERS_PROFILES.get(players))); } From 7ed24e72f6896ce290156b41661ab63219359177 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Thu, 9 Jan 2014 17:25:53 +0100 Subject: [PATCH 3/3] Correctly handle player samples set to null. --- .../com/comphenix/protocol/wrappers/WrappedServerPing.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java index 437b5b5c..7ed52bb2 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java @@ -246,7 +246,10 @@ public class WrappedServerPing extends AbstractWrapper { public ImmutableList getPlayers() { if (players == null) return ImmutableList.of(); - return ImmutableList.copyOf(PROFILE_CONVERT.getSpecific(PLAYERS_PROFILES.get(players))); + Object playerProfiles = PLAYERS_PROFILES.get(players); + if (playerProfiles == null) + return ImmutableList.of(); + return ImmutableList.copyOf(PROFILE_CONVERT.getSpecific(playerProfiles)); } /** @@ -256,7 +259,7 @@ public class WrappedServerPing extends AbstractWrapper { public void setPlayers(Iterable profile) { if (players == null) resetPlayers(); - PLAYERS_PROFILES.set(players, PROFILE_CONVERT.getGeneric(GameProfile[].class, profile)); + PLAYERS_PROFILES.set(players, (profile != null) ? PROFILE_CONVERT.getGeneric(GameProfile[].class, profile) : null); } /**