From f21abc33632a0cc584b32aa9ad63fe377bee7c84 Mon Sep 17 00:00:00 2001 From: War Pigeon <54217755+minus1over12@users.noreply.github.com> Date: Fri, 14 Jun 2024 22:35:07 -0500 Subject: [PATCH] Fix a NPE --- .idea/.name | 1 + build.gradle | 2 +- .../io/github/minus1over12/ctfbuddy/FlagTracker.java | 11 ++++------- 3 files changed, 6 insertions(+), 8 deletions(-) create mode 100644 .idea/.name diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..55527df --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +CTFBuddy \ No newline at end of file diff --git a/build.gradle b/build.gradle index bc88dcf..411c20b 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group = 'io.github.minus1over12' -version = '1.0.0' +version = '1.0.1' repositories { mavenCentral() diff --git a/src/main/java/io/github/minus1over12/ctfbuddy/FlagTracker.java b/src/main/java/io/github/minus1over12/ctfbuddy/FlagTracker.java index 6efb049..190c84e 100644 --- a/src/main/java/io/github/minus1over12/ctfbuddy/FlagTracker.java +++ b/src/main/java/io/github/minus1over12/ctfbuddy/FlagTracker.java @@ -127,10 +127,7 @@ protected FlagTracker(JavaPlugin plugin) { * @return True if the item is the flag item, false otherwise */ private boolean isFlag(PersistentDataHolder item) { - if (item == null) { - return false; - } - return item.getPersistentDataContainer() + return item != null && item.getPersistentDataContainer() .getOrDefault(isFlagKey, PersistentDataType.BOOLEAN, false); } @@ -246,7 +243,7 @@ public void onEntityDeath(EntityDeathEvent event) { EntityEquipment equipment = entity.getEquipment(); if (equipment != null) { ItemStack helmet = equipment.getHelmet(); - if (isFlag(helmet.getItemMeta())) { + if (helmet != null && isFlag(helmet.getItemMeta())) { // Handles keepInventory true case entity.getWorld().dropItemNaturally(entity.getLocation(), helmet); entity.setGlowing(false); @@ -296,8 +293,8 @@ public void onEntityPortal(EntityPortalEvent event) { if (!allowEnd && event.getPortalType().equals(PortalType.ENDER)) { // Prevent the flag from being teleported to the end, if not allowed Entity entity = event.getEntity(); - if ((entity instanceof Item item && isFlag(item.getItemStack().getItemMeta()) || - isFlag(entity))) { + if (entity instanceof Item item && isFlag(item.getItemStack().getItemMeta()) || + isFlag(entity)) { event.setCancelled(true); } else if (entity instanceof LivingEntity livingEntity) { EntityEquipment equipment = livingEntity.getEquipment();