From b03fcd6d41edde9ca43b49dfc9ddd7ce1df8b08d Mon Sep 17 00:00:00 2001 From: AlexIIL Date: Wed, 13 Nov 2024 03:21:03 +0000 Subject: [PATCH] Fix a gui bug where an image read result wasn't checked for null, and small additions to plugin api. --- .../loader/api/plugin/QuiltPluginManager.java | 14 ++++++++++++++ .../quiltmc/loader/impl/gui/BasicWindowUI.java | 5 +++-- .../quiltmc/loader/impl/gui/GuiManagerImpl.java | 7 ------- .../impl/plugin/QuiltPluginManagerImpl.java | 16 ++++++++++++++-- .../impl/plugin/quilt/StandardQuiltPlugin.java | 5 +++-- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/quiltmc/loader/api/plugin/QuiltPluginManager.java b/src/main/java/org/quiltmc/loader/api/plugin/QuiltPluginManager.java index e0b39cd0a..18e30ad60 100644 --- a/src/main/java/org/quiltmc/loader/api/plugin/QuiltPluginManager.java +++ b/src/main/java/org/quiltmc/loader/api/plugin/QuiltPluginManager.java @@ -31,6 +31,8 @@ import org.quiltmc.loader.api.ModContainer; import org.quiltmc.loader.api.QuiltLoader; import org.quiltmc.loader.api.Version; +import org.quiltmc.loader.api.gui.QuiltLoaderGui; +import org.quiltmc.loader.api.gui.QuiltTreeNode; import org.quiltmc.loader.api.plugin.gui.PluginGuiManager; import org.quiltmc.loader.api.plugin.gui.PluginGuiTreeNode; import org.quiltmc.loader.api.plugin.solver.ModLoadOption; @@ -251,10 +253,22 @@ default Path copyToReadOnlyFileSystem(String name, Path folderRoot) throws IOExc // # Gui # // ####### + /** @return The {@link QuiltTreeNode} that will be displayed in the "Mods" tab of the plugin gui for the specific + * mod. */ + QuiltTreeNode getTreeNode(ModLoadOption mod); + + /** @return The {@link QuiltTreeNode} that is the root of the "Files" tab. */ + QuiltTreeNode getFilesTreeNode(); + + /** @deprecated Use {@link #getTreeNode(ModLoadOption)} instead. */ + @Deprecated PluginGuiTreeNode getGuiNode(ModLoadOption mod); + /** @deprecated Use {@link #getFilesTreeNode()} instead. */ + @Deprecated PluginGuiTreeNode getRootGuiNode(); + /** @deprecated Since {@link PluginGuiManager} is deprecated. Use {@link QuiltLoaderGui} directly instead. */ @Deprecated PluginGuiManager getGuiManager(); } diff --git a/src/main/java/org/quiltmc/loader/impl/gui/BasicWindowUI.java b/src/main/java/org/quiltmc/loader/impl/gui/BasicWindowUI.java index 4ccac253d..8292a14a9 100644 --- a/src/main/java/org/quiltmc/loader/impl/gui/BasicWindowUI.java +++ b/src/main/java/org/quiltmc/loader/impl/gui/BasicWindowUI.java @@ -907,11 +907,12 @@ BufferedImage generateIcon(PluginIconImpl.IconType info, int scale) throws IOExc if (map.isEmpty()) { for (byte[] src : srcImages) { BufferedImage sub = ImageIO.read(new ByteArrayInputStream(src)); - map.put(sub.getWidth(), sub); + if (sub != null) { + map.put(sub.getWidth(), sub); + } } } - Entry bestSource = map.ceilingEntry(scale); if (bestSource == null) { bestSource = map.floorEntry(scale); diff --git a/src/main/java/org/quiltmc/loader/impl/gui/GuiManagerImpl.java b/src/main/java/org/quiltmc/loader/impl/gui/GuiManagerImpl.java index a11607a73..1bf58e8d2 100644 --- a/src/main/java/org/quiltmc/loader/impl/gui/GuiManagerImpl.java +++ b/src/main/java/org/quiltmc/loader/impl/gui/GuiManagerImpl.java @@ -21,19 +21,12 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; -import javax.imageio.ImageIO; - -import org.quiltmc.loader.api.FasterFiles; import org.quiltmc.loader.api.ModContainer; -import org.quiltmc.loader.api.QuiltLoader; import org.quiltmc.loader.api.gui.QuiltLoaderIcon; import org.quiltmc.loader.api.plugin.gui.PluginGuiManager; import org.quiltmc.loader.impl.util.FileUtil; diff --git a/src/main/java/org/quiltmc/loader/impl/plugin/QuiltPluginManagerImpl.java b/src/main/java/org/quiltmc/loader/impl/plugin/QuiltPluginManagerImpl.java index f7845a9ad..ae8a8b893 100644 --- a/src/main/java/org/quiltmc/loader/impl/plugin/QuiltPluginManagerImpl.java +++ b/src/main/java/org/quiltmc/loader/impl/plugin/QuiltPluginManagerImpl.java @@ -182,7 +182,6 @@ public class QuiltPluginManagerImpl implements QuiltPluginManager { final Queue mainThreadTasks; - public final GuiManagerImpl guiManager = GuiManagerImpl.MANAGER; /** The root tree node for the "files" tab. */ public final QuiltStatusNode guiFileRoot = QuiltLoaderGuiImpl.createTreeNode(); public final QuiltStatusNode guiModsRoot = QuiltLoaderGuiImpl.createTreeNode(); @@ -688,18 +687,31 @@ public EnvType getEnvironment() { // ####### @Override + public QuiltTreeNode getTreeNode(ModLoadOption mod) { + return modGuiNodes.get(mod); + } + + @Override + @Deprecated public PluginGuiTreeNode getGuiNode(ModLoadOption mod) { return modGuiNodes.get(mod); } @Override + public QuiltTreeNode getFilesTreeNode() { + return guiFileRoot; + } + + @Override + @Deprecated public PluginGuiTreeNode getRootGuiNode() { return guiFileRoot; } @Override + @Deprecated public PluginGuiManager getGuiManager() { - return guiManager; + return GuiManagerImpl.MANAGER; } public QuiltDisplayedError reportError(BasePluginContext reporter, QuiltLoaderText title) { diff --git a/src/main/java/org/quiltmc/loader/impl/plugin/quilt/StandardQuiltPlugin.java b/src/main/java/org/quiltmc/loader/impl/plugin/quilt/StandardQuiltPlugin.java index 555ac6f1e..4cea7cb9a 100644 --- a/src/main/java/org/quiltmc/loader/impl/plugin/quilt/StandardQuiltPlugin.java +++ b/src/main/java/org/quiltmc/loader/impl/plugin/quilt/StandardQuiltPlugin.java @@ -44,6 +44,7 @@ import org.quiltmc.loader.api.gui.QuiltLoaderGui; import org.quiltmc.loader.api.gui.QuiltLoaderIcon; import org.quiltmc.loader.api.gui.QuiltLoaderText; +import org.quiltmc.loader.api.gui.QuiltTreeNode; import org.quiltmc.loader.api.QuiltLoader; import org.quiltmc.loader.api.Version; import org.quiltmc.loader.api.VersionRange; @@ -456,9 +457,9 @@ public void onLoadOptionAdded(LoadOption option) { Collection provides = metadata.provides(); for (ProvidedMod provided : provides) { - PluginGuiTreeNode guiNode = context().manager().getGuiNode(mod)// + QuiltTreeNode guiNode = context().manager().getTreeNode(mod)// .addChild(QuiltLoaderText.translate("gui.text.providing", provided.id())); - guiNode.mainIcon(QuiltLoaderGui.iconUnknownFile()); + guiNode.icon(QuiltLoaderGui.iconUnknownFile()); context().addModLoadOption(new ProvidedModOption(mod, provided), guiNode); } }