Skip to content

Commit 80aa420

Browse files
authored
Fixed setting Base64 favicon for 1.19.4 or later (#2533)
Fix redundant base64 encoding of favicon
1 parent 564349c commit 80aa420

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,15 @@ public void setMotD(String message) {
134134
* @return The favicon, or NULL if no favicon will be displayed.
135135
*/
136136
public CompressedImage getFavicon() {
137-
String favicon = impl.getFavicon();
138-
return (favicon != null) ? CompressedImage.fromEncodedText(favicon) : null;
137+
return impl.getFavicon();
139138
}
140139

141140
/**
142141
* Set the compressed PNG file that is being displayed.
143142
* @param image - the new compressed image or NULL if no favicon should be displayed.
144143
*/
145144
public void setFavicon(CompressedImage image) {
146-
impl.setFavicon((image != null) ? image.toEncodedText() : null);
145+
impl.setFavicon(image);
147146
}
148147

149148
/**

src/main/java/com/comphenix/protocol/wrappers/ping/LegacyServerPing.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,19 @@ public void setMotD(WrappedChatComponent description) {
155155
* @return The favicon, or NULL if no favicon will be displayed.
156156
*/
157157
@Override
158-
public String getFavicon() {
159-
return (String) FAVICON.get(handle);
158+
public WrappedServerPing.CompressedImage getFavicon() {
159+
160+
String favicon = (String) FAVICON.get(handle);
161+
return (favicon != null) ? WrappedServerPing.CompressedImage.fromEncodedText(favicon) : null;
160162
}
161163

162164
/**
163165
* Set the compressed PNG file that is being displayed.
164166
* @param image - the new compressed image or NULL if no favicon should be displayed.
165167
*/
166168
@Override
167-
public void setFavicon(String image) {
168-
FAVICON.set(handle, image);
169+
public void setFavicon(WrappedServerPing.CompressedImage image) {
170+
FAVICON.set(handle, (image != null) ? image.toEncodedText() : null);
169171
}
170172

171173
/**

src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.comphenix.protocol.wrappers.WrappedChatComponent;
44
import com.comphenix.protocol.wrappers.WrappedGameProfile;
5+
import com.comphenix.protocol.wrappers.WrappedServerPing;
56
import com.google.common.collect.ImmutableList;
67

78
public interface ServerPingImpl extends Cloneable {
@@ -17,8 +18,8 @@ public interface ServerPingImpl extends Cloneable {
1718
void setVersionName(String versionName);
1819
int getVersionProtocol();
1920
void setVersionProtocol(int protocolVersion);
20-
String getFavicon();
21-
void setFavicon(String favicon);
21+
WrappedServerPing.CompressedImage getFavicon();
22+
void setFavicon(WrappedServerPing.CompressedImage favicon);
2223
boolean isEnforceSecureChat();
2324
void setEnforceSecureChat(boolean safeChat);
2425

src/main/java/com/comphenix/protocol/wrappers/ping/ServerPingRecord.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ public void setVersionProtocol(int protocolVersion) {
273273
}
274274

275275
@Override
276-
public String getFavicon() {
277-
return new String(favicon.iconBytes, StandardCharsets.UTF_8);
276+
public WrappedServerPing.CompressedImage getFavicon() {
277+
return new WrappedServerPing.CompressedImage("data:image/png;base64", favicon.iconBytes);
278278
}
279279

280280
@Override
281-
public void setFavicon(String favicon) {
282-
this.favicon.iconBytes = favicon.getBytes(StandardCharsets.UTF_8);
281+
public void setFavicon(WrappedServerPing.CompressedImage favicon) {
282+
this.favicon.iconBytes = favicon.getDataCopy();
283283
}
284284

285285
@Override

0 commit comments

Comments
 (0)