82 lines
4.3 KiB
Diff
82 lines
4.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: AlphaKR93 <dev@alpha93.kr>
|
|
Date: Mon, 6 May 2024 13:40:48 +0900
|
|
Subject: [PATCH] Use Plazma logo instead if server favicon doesn't exist
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index f926376ee95b28a9c09a1ad87223f89f1c28f50e..cf13166d1fdd663f1f99fd6d00a5296631276511 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1555,29 +1555,36 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
|
|
private Optional<ServerStatus.Favicon> loadStatusIcon() {
|
|
- Optional<Path> optional = Optional.of(this.getFile("server-icon.png").toPath()).filter((path) -> {
|
|
- return Files.isRegularFile(path, new LinkOption[0]);
|
|
- }).or(() -> {
|
|
- return this.storageSource.getIconFile().filter((path) -> {
|
|
- return Files.isRegularFile(path, new LinkOption[0]);
|
|
- });
|
|
- });
|
|
-
|
|
- return optional.flatMap((path) -> {
|
|
- try {
|
|
- BufferedImage bufferedimage = ImageIO.read(path.toFile());
|
|
-
|
|
- Preconditions.checkState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide");
|
|
- Preconditions.checkState(bufferedimage.getHeight() == 64, "Must be 64 pixels high");
|
|
- ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
-
|
|
- ImageIO.write(bufferedimage, "PNG", bytearrayoutputstream);
|
|
- return Optional.of(new ServerStatus.Favicon(bytearrayoutputstream.toByteArray()));
|
|
- } catch (Exception exception) {
|
|
- MinecraftServer.LOGGER.error("Couldn't load server icon", exception);
|
|
- return Optional.empty();
|
|
- }
|
|
- });
|
|
+ // Plazma start - Use Plazma logo instead if server favicon doesn't exist
|
|
+ @Nullable File file = Optional.of(this.getFile("server-icon.png").toPath()).filter(Files::isRegularFile)
|
|
+ .or(() -> this.storageSource.getIconFile().filter(Files::isRegularFile)).map(Path::toFile).orElse(null);
|
|
+
|
|
+ try (
|
|
+ java.io.InputStream stream = (file != null)
|
|
+ ? new java.io.FileInputStream(file)
|
|
+ : (
|
|
+ org.plazmamc.plazma.Options.VANILLA_ICO
|
|
+ ? null
|
|
+ : MinecraftServer.class.getResourceAsStream("logo.png")
|
|
+ )
|
|
+ ) {
|
|
+ if (stream == null) return Optional.empty();
|
|
+ if (file == null && !org.plazmamc.plazma.Options.VANILLA_ICO)
|
|
+ LOGGER.info("No server icon found, using the logo instead.");
|
|
+
|
|
+ BufferedImage bufferedimage = ImageIO.read(stream);
|
|
+
|
|
+ Preconditions.checkState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide");
|
|
+ Preconditions.checkState(bufferedimage.getHeight() == 64, "Must be 64 pixels high");
|
|
+ ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
+
|
|
+ ImageIO.write(bufferedimage, "PNG", bytearrayoutputstream);
|
|
+ return Optional.of(new ServerStatus.Favicon(bytearrayoutputstream.toByteArray()));
|
|
+ } catch (Exception exception) {
|
|
+ MinecraftServer.LOGGER.error("Couldn't load server icon", exception);
|
|
+ return Optional.empty();
|
|
+ }
|
|
+ // Plazma end - Use Plazma logo instead if server favicon doesn't exist
|
|
}
|
|
|
|
public Optional<Path> getWorldScreenshotFile() {
|
|
diff --git a/src/main/java/org/plazmamc/plazma/Options.java b/src/main/java/org/plazmamc/plazma/Options.java
|
|
index 3e0e67c089e269d0bccd4a0d2de5ac1ac515997e..2e75ca5d2b7d8f35814fe9a0814b19a9135d80cb 100644
|
|
--- a/src/main/java/org/plazmamc/plazma/Options.java
|
|
+++ b/src/main/java/org/plazmamc/plazma/Options.java
|
|
@@ -8,5 +8,6 @@ public interface Options {
|
|
boolean AGGRESSIVE = Boolean.getBoolean("Plazma.aggressiveOptimize") && !NO_OPTIMIZE;
|
|
boolean VANILLAIZE = Boolean.getBoolean("Plazma.vanillaize") && !AGGRESSIVE;
|
|
boolean USE_VANILLA = Boolean.getBoolean("Plazma.useVanillaConfiguration") && !AGGRESSIVE && NO_OPTIMIZE;
|
|
+ boolean VANILLA_ICO = Boolean.getBoolean("Plazma.useVanillaFavicon");
|
|
|
|
}
|