From 2e3b9962c8feb055774af69da06d529b8d335eec Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sun, 2 Feb 2020 11:07:27 +0100 Subject: [PATCH] Fixed "PVP disabled in ..." messages not using world-specific messages. No matter which dimension the player was in, in some cases, it was telling "PVP disabled in the Overworld". --- .../listeners/flags/settings/PVPListener.java | 12 ++++++------ .../listeners/flags/settings/PVPListenerTest.java | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) 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 8ce05bb1a..1b43ab6c7 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 @@ -78,7 +78,7 @@ public class PVPListener extends FlagListener { if (damager instanceof Player) { User user = User.getInstance(damager); if (!checkIsland((Event)e, (Player)damager, damager.getLocation(), flag)) { - user.notify(Flags.PVP_OVERWORLD.getHintReference()); + user.notify(getFlag(damager.getWorld()).getHintReference()); e.setCancelled(true); } } else if (damager instanceof Projectile) { @@ -103,7 +103,7 @@ public class PVPListener extends FlagListener { if (!checkIsland((Event)e, shooter, damager.getLocation(), flag)) { damager.setFireTicks(0); hurtEntity.setFireTicks(0); - user.notify(Flags.PVP_OVERWORLD.getHintReference()); + user.notify(getFlag(damager.getWorld()).getHintReference()); e.setCancelled(true); } @@ -122,7 +122,7 @@ public class PVPListener extends FlagListener { e.setCancelled(true); } else if (!checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), getFlag(e.getCaught().getWorld()))) { e.getHook().remove(); - User.getInstance(e.getPlayer()).notify(Flags.PVP_OVERWORLD.getHintReference()); + User.getInstance(e.getPlayer()).notify(getFlag(e.getCaught().getWorld()).getHintReference()); e.setCancelled(true); } } @@ -144,14 +144,14 @@ public class PVPListener extends FlagListener { /** * Check if PVP should be blocked or not * @param user - user who is initiating the action - * @param le - Living entity involed + * @param le - Living entity involved * @param e - event driving * @param flag - flag to check * @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 (user.getPlayer().equals(le)) { + if (le.equals(user.getPlayer())) { return false; } if (le instanceof Player) { @@ -162,7 +162,7 @@ public class PVPListener extends FlagListener { } // Check if PVP is allowed or not if (!checkIsland(e, user.getPlayer(), le.getLocation(), flag)) { - user.notify(Flags.PVP_OVERWORLD.getHintReference()); + user.notify(getFlag(le.getWorld()).getHintReference()); return true; } } 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 f66fdf279..ad04ae836 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 @@ -525,6 +525,7 @@ public class PVPListenerTest { Projectile p = mock(Projectile.class); when(p.getShooter()).thenReturn(player); when(p.getLocation()).thenReturn(loc); + when(p.getWorld()).thenReturn(world); EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK, new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)), new EnumMap>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0)))); @@ -1090,6 +1091,7 @@ public class PVPListenerTest { Firework firework = mock(Firework.class); when(firework.getEntityId()).thenReturn(123); when(firework.getLocation()).thenReturn(loc); + when(firework.getWorld()).thenReturn(world); EntityShootBowEvent e = new EntityShootBowEvent(player, bow, firework, 0); listener.onPlayerShootFireworkEvent(e);