mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 05:05:18 +01:00
Let Citizens handle its own PVP protection.
https://github.com/BentoBoxWorld/BentoBox/issues/1518
This commit is contained in:
parent
edacd33fd1
commit
5a5435d815
@ -50,8 +50,8 @@ public class PVPListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onEntityDamage(EntityDamageByEntityEvent e) {
|
||||
if (e.getEntity() instanceof Player && getPlugin().getIWM().inWorld(e.getEntity().getWorld())) {
|
||||
// Allow self damage
|
||||
if (e.getEntity().equals(e.getDamager())) {
|
||||
// Allow self damage or NPC attack because Citizens handles its own PVP
|
||||
if (e.getEntity().equals(e.getDamager()) || e.getEntity().hasMetadata("NPC")) {
|
||||
return;
|
||||
}
|
||||
// Protect visitors
|
||||
@ -112,8 +112,8 @@ public class PVPListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onFishing(PlayerFishEvent e) {
|
||||
if (e.getCaught() instanceof Player && getPlugin().getIWM().inWorld(e.getCaught().getLocation())) {
|
||||
// Allow self-inflicted damage
|
||||
if (e.getCaught().equals(e.getPlayer())) {
|
||||
// Allow self-inflicted damage or NPC damage
|
||||
if (e.getCaught().equals(e.getPlayer()) || e.getCaught().hasMetadata("NPC")) {
|
||||
return;
|
||||
}
|
||||
// Protect visitors
|
||||
@ -154,8 +154,8 @@ public class PVPListener extends FlagListener {
|
||||
* @return true if PVP should be blocked otherwise false
|
||||
*/
|
||||
private boolean blockPVP(User user, LivingEntity le, Event e, Flag flag) {
|
||||
// Check for self-inflicted damage
|
||||
if (le.equals(user.getPlayer())) {
|
||||
// Check for self-inflicted damage or Citizen NPCs
|
||||
if (le.equals(user.getPlayer()) || le.hasMetadata("NPC")) {
|
||||
return false;
|
||||
}
|
||||
if (le instanceof Player) {
|
||||
|
@ -273,6 +273,25 @@ public class PVPListenerTest {
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PVPListener#onEntityDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOnEntityDamageNPC() {
|
||||
// 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(player, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
|
||||
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)}.
|
||||
*/
|
||||
@ -671,6 +690,14 @@ public class PVPListenerTest {
|
||||
new PVPListener().onFishing(pfe);
|
||||
assertFalse(pfe.isCancelled());
|
||||
|
||||
// Disallow PVP , attack on NPC
|
||||
when(player2.hasMetadata(eq("NPC"))).thenReturn(true);
|
||||
when(island.isAllowed(any())).thenReturn(false);
|
||||
pfe = new PlayerFishEvent(player, player2, hook, null);
|
||||
new PVPListener().onFishing(pfe);
|
||||
assertFalse(pfe.isCancelled());
|
||||
|
||||
|
||||
// Wrong world
|
||||
wrongWorld();
|
||||
pfe = new PlayerFishEvent(player, player2, hook, null);
|
||||
|
Loading…
Reference in New Issue
Block a user