diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-09-08 18:31:03 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-09-08 18:31:03 +0200 |
commit | 63d23eff40d6014a5014d8bef85560af38cf39b0 (patch) | |
tree | 39da0791a2b707c93f6b103289bb8e91ba134609 /src | |
parent | 133f6a9bef6317bb9e6c2b54a7b17e0907c30f6a (diff) | |
download | skyhanni-63d23eff40d6014a5014d8bef85560af38cf39b0.tar.gz skyhanni-63d23eff40d6014a5014d8bef85560af38cf39b0.tar.bz2 skyhanni-63d23eff40d6014a5014d8bef85560af38cf39b0.zip |
Fix item resolution query crashing on some enchant books
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ItemResolutionQuery.java | 5 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/IteratorUtils.kt | 14 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemResolutionQuery.java b/src/main/java/at/hannibal2/skyhanni/utils/ItemResolutionQuery.java index 1f8988613..548db2f08 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemResolutionQuery.java +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemResolutionQuery.java @@ -1,7 +1,6 @@ package at.hannibal2.skyhanni.utils; import at.hannibal2.skyhanni.config.ConfigManager; -import com.google.common.collect.Iterables; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import net.minecraft.client.Minecraft; @@ -155,14 +154,14 @@ public class ItemResolutionQuery { private String resolveEnchantedBookNameFromNBT() { NBTTagCompound enchantments = getExtraAttributes().getCompoundTag("enchantments"); - String enchantName = Iterables.getOnlyElement(enchantments.getKeySet(), null); + String enchantName = IteratorUtils.INSTANCE.getOnlyElement(enchantments.getKeySet(), null); if (enchantName == null || enchantName.isEmpty()) return null; return enchantName.toUpperCase(Locale.ROOT) + ";" + enchantments.getInteger(enchantName); } private String resolveRuneName() { NBTTagCompound runes = getExtraAttributes().getCompoundTag("runes"); - String runeName = Iterables.getOnlyElement(runes.getKeySet(), null); + String runeName = IteratorUtils.INSTANCE.getOnlyElement(runes.getKeySet(), null); if (runeName == null || runeName.isEmpty()) return null; return runeName.toUpperCase(Locale.ROOT) + "_RUNE;" + runes.getInteger(runeName); } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/IteratorUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/IteratorUtils.kt new file mode 100644 index 000000000..ca55a665f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/IteratorUtils.kt @@ -0,0 +1,14 @@ +package at.hannibal2.skyhanni.utils + +object IteratorUtils { + + fun <T> getOnlyElement(it: Iterator<T>, defaultValue: T): T { + if (!it.hasNext()) return defaultValue + val ret = it.next() + return if (it.hasNext()) defaultValue else ret + } + + fun <T> getOnlyElement(it: Iterable<T>, defaultValue: T): T { + return getOnlyElement(it.iterator(), defaultValue) + } +}
\ No newline at end of file |