From 78fc00c0cc387ee210076ab2d06de60076307257 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Sun, 18 Aug 2019 22:02:47 +0100 Subject: [PATCH] Yet another AIOOBE fix for WandHelper, fixes #176 Right, I've had enough of this. Why do other people keep getting AIOOBEs from WandHelper when I've never ever had one in my dev environment, after all the testing I've done? What gives?! --- .../java/electroblob/wizardry/util/WandHelper.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/electroblob/wizardry/util/WandHelper.java b/src/main/java/electroblob/wizardry/util/WandHelper.java index 449a807c..07ab31c3 100644 --- a/src/main/java/electroblob/wizardry/util/WandHelper.java +++ b/src/main/java/electroblob/wizardry/util/WandHelper.java @@ -333,9 +333,13 @@ public final class WandHelper { int[] cooldowns = getMaxCooldowns(wand); - if(cooldowns.length == 0) return 0; - // Don't need to check if the tag compound is null since the above check is equivalent. - return cooldowns[wand.getTagCompound().getInteger(SELECTED_SPELL_KEY)]; + if(wand.getTagCompound() == null) return 0; + + int selectedSpell = wand.getTagCompound().getInteger(SELECTED_SPELL_KEY); + + if(cooldowns.length <= selectedSpell) return 0; + + return cooldowns[selectedSpell]; } // ================================================== Upgrades ==================================================