From 80aa42009981b505370b00dd71af6d4e41726f38 Mon Sep 17 00:00:00 2001 From: Lukas Alt Date: Tue, 19 Dec 2023 16:53:16 +0100 Subject: [PATCH] Fixed setting Base64 favicon for 1.19.4 or later (#2533) Fix redundant base64 encoding of favicon --- .../comphenix/protocol/wrappers/WrappedServerPing.java | 5 ++--- .../protocol/wrappers/ping/LegacyServerPing.java | 10 ++++++---- .../protocol/wrappers/ping/ServerPingImpl.java | 5 +++-- .../protocol/wrappers/ping/ServerPingRecord.java | 8 ++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java b/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java index 3f3ed9aa..7d670362 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java +++ b/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java @@ -134,8 +134,7 @@ public class WrappedServerPing implements ClonableWrapper { * @return The favicon, or NULL if no favicon will be displayed. */ public CompressedImage getFavicon() { - String favicon = impl.getFavicon(); - return (favicon != null) ? CompressedImage.fromEncodedText(favicon) : null; + return impl.getFavicon(); } /** @@ -143,7 +142,7 @@ public class WrappedServerPing implements ClonableWrapper { * @param image - the new compressed image or NULL if no favicon should be displayed. */ public void setFavicon(CompressedImage image) { - impl.setFavicon((image != null) ? image.toEncodedText() : null); + impl.setFavicon(image); } /** diff --git a/src/main/java/com/comphenix/protocol/wrappers/ping/LegacyServerPing.java b/src/main/java/com/comphenix/protocol/wrappers/ping/LegacyServerPing.java index e258a7d7..19129b73 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/ping/LegacyServerPing.java +++ b/src/main/java/com/comphenix/protocol/wrappers/ping/LegacyServerPing.java @@ -155,8 +155,10 @@ public final class LegacyServerPing extends AbstractWrapper implements ServerPin * @return The favicon, or NULL if no favicon will be displayed. */ @Override - public String getFavicon() { - return (String) FAVICON.get(handle); + public WrappedServerPing.CompressedImage getFavicon() { + + String favicon = (String) FAVICON.get(handle); + return (favicon != null) ? WrappedServerPing.CompressedImage.fromEncodedText(favicon) : null; } /** @@ -164,8 +166,8 @@ public final class LegacyServerPing extends AbstractWrapper implements ServerPin * @param image - the new compressed image or NULL if no favicon should be displayed. */ @Override - public void setFavicon(String image) { - FAVICON.set(handle, image); + public void setFavicon(WrappedServerPing.CompressedImage image) { + FAVICON.set(handle, (image != null) ? image.toEncodedText() : null); } /** diff --git a/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingImpl.java b/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingImpl.java index ed6f2a24..ed5003d0 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingImpl.java +++ b/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingImpl.java @@ -2,6 +2,7 @@ package com.comphenix.protocol.wrappers.ping; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import com.comphenix.protocol.wrappers.WrappedServerPing; import com.google.common.collect.ImmutableList; public interface ServerPingImpl extends Cloneable { @@ -17,8 +18,8 @@ public interface ServerPingImpl extends Cloneable { void setVersionName(String versionName); int getVersionProtocol(); void setVersionProtocol(int protocolVersion); - String getFavicon(); - void setFavicon(String favicon); + WrappedServerPing.CompressedImage getFavicon(); + void setFavicon(WrappedServerPing.CompressedImage favicon); boolean isEnforceSecureChat(); void setEnforceSecureChat(boolean safeChat); diff --git a/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingRecord.java b/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingRecord.java index f1d77827..4c1426d7 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingRecord.java +++ b/src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingRecord.java @@ -273,13 +273,13 @@ public final class ServerPingRecord implements ServerPingImpl { } @Override - public String getFavicon() { - return new String(favicon.iconBytes, StandardCharsets.UTF_8); + public WrappedServerPing.CompressedImage getFavicon() { + return new WrappedServerPing.CompressedImage("data:image/png;base64", favicon.iconBytes); } @Override - public void setFavicon(String favicon) { - this.favicon.iconBytes = favicon.getBytes(StandardCharsets.UTF_8); + public void setFavicon(WrappedServerPing.CompressedImage favicon) { + this.favicon.iconBytes = favicon.getDataCopy(); } @Override