From 10dbcbcdbdd01a9ec1735b1d896d59b3d56af575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 12 May 2020 10:05:47 +0200 Subject: [PATCH] Prevent NPE in entityDamage This is done by creating a fake (WE) entity type in the case that the entity type name is null. In these cases, WE has no equivalent. By doing this, all entity category contains check will fail, and it will default to the PVE check at the bottom of the if-else if chain. --- .../plotsquared/bukkit/listener/PlayerEvents.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 1c7b9d5f5..018509743 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -225,6 +225,9 @@ import java.util.regex.Pattern; @SuppressWarnings("unused") public class PlayerEvents extends PlotListener implements Listener { + public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE + = new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake"); + private boolean pistonBlocks = true; private float lastRadius; // To prevent recursion @@ -2751,8 +2754,16 @@ public class PlayerEvents extends PlotListener implements Listener { } if (player != null) { PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); - final com.sk89q.worldedit.world.entity.EntityType entityType = - BukkitAdapter.adapt(victim.getType()); + + final com.sk89q.worldedit.world.entity.EntityType entityType; + + // Create a fake entity type if the type does not have a name + if (victim.getType().getName() == null) { + entityType = FAKE_ENTITY_TYPE; + } else { + entityType = BukkitAdapter.adapt(victim.getType()); + } + if (EntityCategories.HANGING.contains(entityType)) { // hanging if (plot != null && (plot.getFlag(HangingBreakFlag.class)) || plot .isAdded(plotPlayer.getUUID())) {