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.
This commit is contained in:
Alexander Söderberg 2020-05-12 10:05:47 +02:00
parent e8dd5fe903
commit 10dbcbcdbd

View file

@ -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())) {