aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2024-05-04 11:04:38 -0400
committerAaron <51387595+AzureAaron@users.noreply.github.com>2024-05-04 11:04:38 -0400
commited98c8b92634f494234cb05c2806ee7b337b6675 (patch)
treeb8c60db6032f55a59a95c210981bc417775da2d7 /src/main/java
parent90ac41c4fed0480526976d6b7d62224016b7b542 (diff)
downloadSkyblocker-ed98c8b92634f494234cb05c2806ee7b337b6675.tar.gz
Skyblocker-ed98c8b92634f494234cb05c2806ee7b337b6675.tar.bz2
Skyblocker-ed98c8b92634f494234cb05c2806ee7b337b6675.zip
Fix wiki lookup crash + other bug
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/item/WikiLookup.java25
1 files changed, 16 insertions, 9 deletions
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 5815c11f..c954953e 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/item/WikiLookup.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/item/WikiLookup.java
@@ -3,6 +3,7 @@ package de.hysky.skyblocker.skyblock.item;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.utils.ItemUtils;
+import de.hysky.skyblocker.utils.Utils;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
@@ -32,19 +33,25 @@ public class WikiLookup {
public static void getSkyblockId(Slot slot) {
//Grabbing the skyblock NBT data
- ItemUtils.getItemIdOptional(slot.getStack()).ifPresent(newId -> id = newId);
+ //Setting to null prevents a bug where using wiki lookup on an empty slot would bring up the last looked up page
+ id = ItemUtils.getItemIdOptional(slot.getStack()).orElse(null);
}
public static void openWiki(Slot slot, PlayerEntity player) {
- if (SkyblockerConfigManager.get().general.wikiLookup.enableWikiLookup) {
+ if (Utils.isOnSkyblock() && SkyblockerConfigManager.get().general.wikiLookup.enableWikiLookup) {
getSkyblockId(slot);
- try {
- String wikiLink = ItemRepository.getWikiLink(id, player);
- if (wikiLink != null) CompletableFuture.runAsync(() -> Util.getOperatingSystem().open(wikiLink));
- } catch (IndexOutOfBoundsException | IllegalStateException e) {
- LOGGER.error("[Skyblocker] Error while retrieving wiki article...", e);
- if (player != null) {
- player.sendMessage(Text.of("[Skyblocker] Error while retrieving wiki article, see logs..."), false);
+
+ //Fixes a crash where using wiki lookup for the first time on an item that doesn't have an id (because id is initialized to null)
+ //and now also because we set it to null above for said reason
+ if (id != null) {
+ try {
+ String wikiLink = ItemRepository.getWikiLink(id, player);
+ if (wikiLink != null) CompletableFuture.runAsync(() -> Util.getOperatingSystem().open(wikiLink));
+ } catch (IndexOutOfBoundsException | IllegalStateException e) {
+ LOGGER.error("[Skyblocker] Error while retrieving wiki article...", e);
+ if (player != null) {
+ player.sendMessage(Text.of("[Skyblocker] Error while retrieving wiki article, see logs..."), false);
+ }
}
}
}