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".
This commit is contained in:
Florian CUNY 2020-02-02 11:07:27 +01:00
parent 61fde3bceb
commit 2e3b9962c8
2 changed files with 8 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -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<DamageModifier, Function<? super Double, Double>>(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);