From fbd2eeb93d6104c374358a6902fd3922b0a5b070 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 29 Mar 2021 15:14:54 -0700 Subject: [PATCH] Avoid NPE on beast lore jump strength checks --- .../nossr50/skills/taming/TamingManager.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index 3b7f6315d..859892c20 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -29,6 +29,7 @@ import com.gmail.nossr50.util.text.StringUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.*; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -251,12 +252,16 @@ public class TamingManager extends SkillManager { // Bred mules & donkeys can actually have horse-like stats, but llamas cannot. if (beast instanceof AbstractHorse && !(beast instanceof Llama)) { - AbstractHorse horse = (AbstractHorse) beast; - double jumpStrength = horse.getAttribute(Attribute.HORSE_JUMP_STRENGTH).getValue(); - // Taken from https://minecraft.gamepedia.com/Horse#Jump_strength - jumpStrength = -0.1817584952 * Math.pow(jumpStrength, 3) + 3.689713992 * Math.pow(jumpStrength, 2) + 2.128599134 * jumpStrength - 0.343930367; - message = message.concat("\n" + LocaleLoader.getString("Combat.BeastLoreHorseSpeed", horse.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getValue() * 43)) - .concat("\n" + LocaleLoader.getString("Combat.BeastLoreHorseJumpStrength", jumpStrength)); + AbstractHorse horseLikeCreature = (AbstractHorse) beast; + AttributeInstance jumpAttribute = horseLikeCreature.getAttribute(Attribute.HORSE_JUMP_STRENGTH); + + if(jumpAttribute != null) { + double jumpStrength = jumpAttribute.getValue(); + // Taken from https://minecraft.gamepedia.com/Horse#Jump_strength + jumpStrength = -0.1817584952 * Math.pow(jumpStrength, 3) + 3.689713992 * Math.pow(jumpStrength, 2) + 2.128599134 * jumpStrength - 0.343930367; + message = message.concat("\n" + LocaleLoader.getString("Combat.BeastLoreHorseSpeed", horseLikeCreature.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).getValue() * 43)) + .concat("\n" + LocaleLoader.getString("Combat.BeastLoreHorseJumpStrength", jumpStrength)); + } } player.sendMessage(message);