diff --git a/src/main/java/world/bentobox/bentobox/commands/BentoBoxAboutCommand.java b/src/main/java/world/bentobox/bentobox/commands/BentoBoxAboutCommand.java index 1f511565e..f2694f563 100644 --- a/src/main/java/world/bentobox/bentobox/commands/BentoBoxAboutCommand.java +++ b/src/main/java/world/bentobox/bentobox/commands/BentoBoxAboutCommand.java @@ -28,7 +28,7 @@ public class BentoBoxAboutCommand extends CompositeCommand { @Override public boolean execute(User user, String label, List args) { user.sendRawMessage("About " + BentoBox.getInstance().getDescription().getName() + " v" + BentoBox.getInstance().getDescription().getVersion() + ":"); - user.sendRawMessage("Copyright (c) 2017 - 2023 Tastybento, Poslovitch and the BentoBoxWorld contributors"); + user.sendRawMessage("Copyright (c) 2017 - 2024 Tastybento, Poslovitch and the BentoBoxWorld contributors"); user.sendRawMessage("See https://www.eclipse.org/legal/epl-2.0/ for license information."); return true; } diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/settings/PVPListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/settings/PVPListener.java index 2b6689165..8dea60870 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/settings/PVPListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/settings/PVPListener.java @@ -53,8 +53,9 @@ public class PVPListener extends FlagListener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onEntityDamage(EntityDamageByEntityEvent e) { if (e.getEntity() instanceof Player player && getPlugin().getIWM().inWorld(e.getEntity().getWorld())) { - // Allow self damage or NPC attack because Citizens handles its own PVP - if (e.getEntity().equals(e.getDamager()) || e.getEntity().hasMetadata("NPC")) { + // Allow self damage or NPC attack or attack by NPC because Citizens handles its own PVP + if (e.getEntity().equals(e.getDamager()) || e.getEntity().hasMetadata("NPC") + || e.getDamager().hasMetadata("NPC")) { return; } // Is PVP allowed here? diff --git a/src/main/java/world/bentobox/bentobox/managers/island/NewIsland.java b/src/main/java/world/bentobox/bentobox/managers/island/NewIsland.java index bb4f2cb22..c3bc4eb92 100644 --- a/src/main/java/world/bentobox/bentobox/managers/island/NewIsland.java +++ b/src/main/java/world/bentobox/bentobox/managers/island/NewIsland.java @@ -227,6 +227,9 @@ public class NewIsland { * @param oldIsland - old island that will be deleted */ private void postCreationTask(Island oldIsland) { + if (oldIsland == null) { + return; + } // Set initial spawn point if one exists if (island.getSpawnPoint(Environment.NORMAL) != null) { plugin.getIslands().setHomeLocation(user, island.getSpawnPoint(Environment.NORMAL)); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java index 8d4168f2a..fa0280163 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/settings/PVPListenerTest.java @@ -25,6 +25,8 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.damage.DamageSource; +import org.bukkit.damage.DamageType; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Arrow; import org.bukkit.entity.Creeper; @@ -295,6 +297,27 @@ public class PVPListenerTest { } + /** + * Test method for {@link PVPListener#onEntityDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}. + */ + @Test + public void testOnEntityDamageNPCAttacks() { + // Player 2 is an NPC + when(player2.hasMetadata(eq("NPC"))).thenReturn(true); + // PVP is not allowed + when(island.isAllowed(any())).thenReturn(false); + EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player2, player, + EntityDamageEvent.DamageCause.ENTITY_ATTACK, null, + new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)), + new EnumMap>( + ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0)))); + new PVPListener().onEntityDamage(e); + // PVP should be allowed for NPC + assertFalse(e.isCancelled()); + verify(player, never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference()); + + } + /** * Test method for {@link PVPListener#onEntityDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}. */