mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 21:01:02 -05:00
Remove server list icon decoding as ImageIO/BufferedImage do not exist on Android.
This commit is contained in:
parent
4c315aa206
commit
1840d5aa3d
3 changed files with 9 additions and 29 deletions
|
@ -128,7 +128,7 @@ public class MinecraftProtocolTest {
|
|||
System.out.println("Player Count: " + info.getPlayerInfo().getOnlinePlayers() + " / " + info.getPlayerInfo().getMaxPlayers());
|
||||
System.out.println("Players: " + Arrays.toString(info.getPlayerInfo().getPlayers()));
|
||||
System.out.println("Description: " + info.getDescription().getFullText());
|
||||
System.out.println("Icon: " + info.getIcon());
|
||||
System.out.println("Icon: " + info.getIconPng());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -16,5 +16,5 @@ public class ServerStatusInfo {
|
|||
private @NonNull VersionInfo versionInfo;
|
||||
private @NonNull PlayerInfo playerInfo;
|
||||
private @NonNull Message description;
|
||||
private BufferedImage icon;
|
||||
private byte[] iconPng;
|
||||
}
|
||||
|
|
|
@ -20,10 +20,6 @@ import lombok.NoArgsConstructor;
|
|||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
|
@ -55,7 +51,7 @@ public class StatusResponsePacket implements Packet {
|
|||
PlayerInfo players = new PlayerInfo(plrs.get("max").getAsInt(), plrs.get("online").getAsInt(), profiles);
|
||||
JsonElement desc = obj.get("description");
|
||||
Message description = Message.fromJson(desc);
|
||||
BufferedImage icon = null;
|
||||
byte[] icon = null;
|
||||
if(obj.has("favicon")) {
|
||||
icon = this.stringToIcon(obj.get("favicon").getAsString());
|
||||
}
|
||||
|
@ -87,8 +83,8 @@ public class StatusResponsePacket implements Packet {
|
|||
obj.add("version", ver);
|
||||
obj.add("players", plrs);
|
||||
obj.add("description", this.info.getDescription().toJson());
|
||||
if(this.info.getIcon() != null) {
|
||||
obj.addProperty("favicon", this.iconToString(this.info.getIcon()));
|
||||
if(this.info.getIconPng() != null) {
|
||||
obj.addProperty("favicon", this.iconToString(this.info.getIconPng()));
|
||||
}
|
||||
|
||||
out.writeString(obj.toString());
|
||||
|
@ -99,31 +95,15 @@ public class StatusResponsePacket implements Packet {
|
|||
return false;
|
||||
}
|
||||
|
||||
private BufferedImage stringToIcon(String str) throws IOException {
|
||||
private byte[] stringToIcon(String str) throws IOException {
|
||||
if(str.startsWith("data:image/png;base64,")) {
|
||||
str = str.substring("data:image/png;base64,".length());
|
||||
}
|
||||
|
||||
byte[] bytes = Base64.decode(str.getBytes(StandardCharsets.UTF_8));
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
|
||||
BufferedImage icon = ImageIO.read(in);
|
||||
in.close();
|
||||
if(icon != null && (icon.getWidth() != 64 || icon.getHeight() != 64)) {
|
||||
throw new IOException("Icon must be 64x64.");
|
||||
return Base64.decode(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
private String iconToString(BufferedImage icon) throws IOException {
|
||||
if(icon.getWidth() != 64 || icon.getHeight() != 64) {
|
||||
throw new IOException("Icon must be 64x64.");
|
||||
}
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ImageIO.write(icon, "PNG", out);
|
||||
out.close();
|
||||
byte[] encoded = Base64.encode(out.toByteArray());
|
||||
return "data:image/png;base64," + new String(encoded, StandardCharsets.UTF_8);
|
||||
private String iconToString(byte[] icon) throws IOException {
|
||||
return "data:image/png;base64," + new String(Base64.encode(icon), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue