Fixed setting Base64 favicon for 1.19.4 or later (#2533)

Fix redundant base64 encoding of favicon
This commit is contained in:
Lukas Alt 2023-12-19 16:53:16 +01:00 committed by GitHub
parent 564349c914
commit 80aa420099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 13 deletions

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);

View File

@ -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