From 14c69e294a9a6eeb7a9da8a513d3aaaa1aca89ab Mon Sep 17 00:00:00 2001 From: Minecrell Date: Wed, 1 Jan 2014 16:29:21 +0100 Subject: [PATCH] Correctly handle wrapped server pings with no favicon. In the current ProtocolLib release (3.1.0) the getFavicon() method will throw a NullPointerException if the server is not sending a favicon. This was partly fixed in 3c5482f but there's still no way of checking if the server is sending a favicon, without checking if the encoded output of the CompressedImage.toEncodedText() will return a valid result. This commit will make the favicon getter and setter in the server ping correctly handle pings with no favicon, by returning null for getFavicon() (if no favicon will be displayed) and allowing to hide the favicon by setting the favicon to null. --- .../protocol/wrappers/WrappedServerPing.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 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 47e2fbc6..dc076137 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java @@ -145,18 +145,19 @@ public class WrappedServerPing extends AbstractWrapper { /** * Retrieve the compressed PNG file that is being displayed as a favicon. - * @return The favicon. + * @return The favicon, or NULL if no favicon will be displayed. */ public CompressedImage getFavicon() { - return CompressedImage.fromEncodedText((String) FAVICON.get(handle)); + String favicon = (String) FAVICON.get(handle); + return (favicon != null) ? CompressedImage.fromEncodedText(favicon) : null; } /** * Set the compressed PNG file that is being displayed. - * @param image - the new compressed image. + * @param image - the new compressed image or NULL if no favicon should be displayed. */ public void setFavicon(CompressedImage image) { - FAVICON.set(handle, image.toEncodedText()); + FAVICON.set(handle, (image != null) ? image.toEncodedText() : null); } /** @@ -455,7 +456,7 @@ public class WrappedServerPing extends AbstractWrapper { */ private static class EncodedCompressedImage extends CompressedImage { public EncodedCompressedImage(String encoded) { - this.encoded = encoded; + this.encoded = Preconditions.checkNotNull(encoded, "encoded favicon cannot be NULL"); } /**