diff --git a/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java b/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java index ff510cf472..9ae25d85e2 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java @@ -97,7 +97,7 @@ protected HandledScreenMixin(Text title) { public void skyblocker$keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable cir) { if (this.client != null && this.focusedSlot != null && keyCode != 256) { //wiki lookup - if (!this.client.options.inventoryKey.matchesKey(keyCode, scanCode) && WikiLookup.wikiLookup.matchesKey(keyCode, scanCode)) { + if (!this.client.options.inventoryKey.matchesKey(keyCode, scanCode) && WikiLookup.wikiLookup.matchesKey(keyCode, scanCode) && client.player != null) { WikiLookup.openWiki(this.focusedSlot, client.player); } //item protection diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/WikiLookup.java b/src/main/java/de/hysky/skyblocker/skyblock/item/WikiLookup.java index 19bef1e1bc..109e550319 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/WikiLookup.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/WikiLookup.java @@ -10,7 +10,9 @@ import net.minecraft.client.util.InputUtil; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.screen.slot.Slot; +import net.minecraft.text.Text; import net.minecraft.util.Util; +import org.jetbrains.annotations.NotNull; import org.lwjgl.glfw.GLFW; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,19 +32,15 @@ public static void init() { )); } - public static void openWiki(Slot slot, PlayerEntity player) { + public static void openWiki(@NotNull Slot slot, @NotNull PlayerEntity player) { if (!Utils.isOnSkyblock() || !SkyblockerConfigManager.get().general.wikiLookup.enableWikiLookup) return; - ItemUtils.getItemIdOptional(slot.getStack()).map(id -> ItemRepository.getWikiLink(id, player)).ifPresent(wikiLink -> { - try { - CompletableFuture.runAsync(() -> Util.getOperatingSystem().open(wikiLink)); - } catch (IndexOutOfBoundsException | IllegalStateException e) { - LOGGER.error("[Skyblocker] Error while retrieving wiki article...", e); - if (player != null) { + ItemUtils.getItemIdOptional(slot.getStack()) + .map(ItemRepository::getWikiLink) + .ifPresentOrElse(wikiLink -> CompletableFuture.runAsync(() -> Util.getOperatingSystem().open(wikiLink)).exceptionally(e -> { + LOGGER.error("[Skyblocker] Error while retrieving wiki article...", e); player.sendMessage(Constants.PREFIX.get().append("Error while retrieving wiki article, see logs..."), false); - } - } - }); + return null; + }), () -> player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.wikiLookup.noArticleFound")), false)); } - } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java index 3379b693cc..4fd0f8cd6b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java @@ -1,16 +1,13 @@ package de.hysky.skyblocker.skyblock.itemlist; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.NEURepoManager; import io.github.moulberry.repo.data.NEUCraftingRecipe; import io.github.moulberry.repo.data.NEUItem; import io.github.moulberry.repo.data.NEURecipe; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.text.Text; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,10 +64,9 @@ private static void loadRecipes(NEUItem item) { } } - public static String getWikiLink(String internalName, PlayerEntity player) { + public static String getWikiLink(String internalName) { NEUItem item = NEURepoManager.NEU_REPO.getItems().getItemBySkyblockId(internalName); if (item == null || item.getInfo() == null || item.getInfo().isEmpty()) { - warnNoWikiLink(player); return null; } @@ -83,16 +79,9 @@ public static String getWikiLink(String internalName, PlayerEntity player) { } else if (wikiLink1.startsWith(wikiDomain)) { return wikiLink1; } - warnNoWikiLink(player); return null; } - private static void warnNoWikiLink(PlayerEntity player) { - if (player != null) { - player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.wikiLookup.noArticleFound")), false); - } - } - public static List getRecipes(String internalName) { List result = new ArrayList<>(); for (SkyblockCraftingRecipe recipe : recipes) {