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