mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 10:45:22 +01:00
Allow NPC's to hit players (#2368)
* WIP for debug only * Allow attacks from NPC's
This commit is contained in:
parent
7126e837ed
commit
290158e6ef
@ -28,7 +28,7 @@ public class BentoBoxAboutCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> 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;
|
||||
}
|
||||
|
@ -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?
|
||||
|
@ -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));
|
||||
|
@ -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<DamageModifier, Function<? super Double, Double>>(
|
||||
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)}.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user