From 580ce6d55501baf65c58d23779c979d07ef614a2 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Sat, 5 Dec 2020 14:04:52 +0100 Subject: [PATCH] Fix NPE related to MythicMobs display name Fixes #1015 --- .../jobs/hooks/MythicMobs/MythicMobs4.java | 4 ++-- .../jobs/listeners/JobsPaymentListener.java | 18 ++++++------------ .../java/com/gamingmesh/jobs/stuff/Util.java | 8 -------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4.java b/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4.java index 9b292995..40b6f312 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4.java @@ -60,8 +60,8 @@ public class MythicMobs4 implements MythicMobInterface { MythicMob mm = MMAPI.getMythicMob(id); try { - if (mm != null) - return mm.getDisplayName().toString(); + if (mm != null && mm.getDisplayName() != null) + return mm.getDisplayName().get(); } catch (Throwable e) { if (!failed) { failed = true; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index dcea3118..2f336316 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -1576,8 +1576,7 @@ public class JobsPaymentListener implements Listener { if (Jobs.getGCManager().useBlockProtection && block.getState().hasMetadata(BlockMetadata)) return; - BlockActionInfo bInfo = new BlockActionInfo(block, ActionType.TNTBREAK); - Jobs.action(jPlayer, bInfo, block); + Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.TNTBREAK), block); } } @@ -1592,8 +1591,7 @@ public class JobsPaymentListener implements Listener { return; CMIMaterial cmat = CMIMaterial.get(block); - final JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(p); - + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(p); Material hand = Jobs.getNms().getItemInMainHand(p).getType(); if (Version.isCurrentEqualOrHigher(Version.v1_14_R1) && event.useInteractedBlock() != org.bukkit.event.Event.Result.DENY @@ -1657,21 +1655,18 @@ public class JobsPaymentListener implements Listener { } } else if (Version.isCurrentEqualOrHigher(Version.v1_13_R1) && block.getType().toString().startsWith("STRIPPED_") && - event.getAction() == Action.RIGHT_CLICK_BLOCK && jPlayer != null) { - ItemStack iih = Jobs.getNms().getItemInMainHand(p); - if (iih.getType().toString().endsWith("_AXE")) { + event.getAction() == Action.RIGHT_CLICK_BLOCK && jPlayer != null && hand.toString().endsWith("_AXE")) { // check if player is riding if (Jobs.getGCManager().disablePaymentIfRiding && p.isInsideVehicle()) return; // Prevent item durability loss - if (!Jobs.getGCManager().payItemDurabilityLoss && iih.getType().getMaxDurability() - - Jobs.getNms().getDurability(iih) != iih.getType().getMaxDurability()) + if (!Jobs.getGCManager().payItemDurabilityLoss && hand.getMaxDurability() + - Jobs.getNms().getDurability(Jobs.getNms().getItemInMainHand(p)) != hand.getMaxDurability()) return; Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.STRIPLOGS), block), 1); - } } } @@ -1734,9 +1729,8 @@ public class JobsPaymentListener implements Listener { return true; ItemStack hand = Jobs.getNms().getItemInMainHand(p); - CMIMaterial cmat = CMIMaterial.get(hand); - HashMap got = Jobs.getGCManager().whiteListedItems.get(cmat); + HashMap got = Jobs.getGCManager().whiteListedItems.get(CMIMaterial.get(hand)); if (got == null) return false; diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Util.java b/src/main/java/com/gamingmesh/jobs/stuff/Util.java index 2c07381c..a8e4d039 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Util.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Util.java @@ -9,7 +9,6 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.ListIterator; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.UUID; @@ -53,13 +52,6 @@ public class Util { return item; } - public static void toLowerCase(List strings) { - ListIterator iterator = strings.listIterator(); - while (iterator.hasNext()) { - iterator.set(iterator.next().toLowerCase()); - } - } - public static World getWorld(String name) { World w = Bukkit.getWorld(name); if (w != null)