78 lines
4.2 KiB
Diff
78 lines
4.2 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 ccfeda1ba3f89112eccf29f382b5526934db1d91..94eb4e0686d8235f06ea7950c178cdec8bd6e037 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1584,29 +1584,32 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
|
|
private Optional<ServerStatus.Favicon> loadStatusIcon() {
|
|
- Optional<Path> optional = Optional.of(this.getFile("server-icon.png")).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").toAbsolutePath()).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 a8711b8a66b443d40cad8dfec31cca357e0877b4..4b3ae18ef8cd09a2d9c9eaee2bf402d0dd7ee1cd 100644
|
|
--- a/src/main/java/org/plazmamc/plazma/Options.java
|
|
+++ b/src/main/java/org/plazmamc/plazma/Options.java
|
|
@@ -11,5 +11,6 @@ public interface Options {
|
|
boolean AGGRESSIVE = getBoolean("Plazma.aggressiveOptimize") && !NO_OPTIMIZE;
|
|
boolean VANILLAIZE = getBoolean("Plazma.vanillaize") && !AGGRESSIVE;
|
|
boolean USE_VANILLA = getBoolean("Plazma.useVanillaConfiguration") && !AGGRESSIVE && NO_OPTIMIZE;
|
|
+ boolean VANILLA_ICO = getBoolean("Plazma.useVanillaFavicon");
|
|
|
|
}
|