Address unnecessary PVP reports on each teleport (#1948)

If a player is teleporting on the same island in the same dimension, it keeps spamming that PVP is enabled in dimension. 
It should be enough with sending messages when the player teleports to the island.

Fixes #1885
This commit is contained in:
BONNe 2022-03-16 09:51:22 +02:00 committed by GitHub
parent e7599ec805
commit 0cf1d43a29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -30,6 +30,7 @@ import world.bentobox.bentobox.api.events.flags.FlagSettingChangeEvent;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.RanksManager;
@ -239,10 +240,20 @@ public class PVPListener extends FlagListener {
if (e.getTo() == null) {
return;
}
// Get previous island to skip reporting if island is not changed.
Island previousIsland = this.getIslands().getIslandAt(e.getFrom()).orElse(null);
getIslands().getIslandAt(e.getTo()).ifPresent(island -> {
if (island.getMemberSet(RanksManager.COOP_RANK).contains(e.getPlayer().getUniqueId())) {
return;
}
if (e.getFrom().getWorld() == e.getTo().getWorld() && island == previousIsland) {
// do not report as it is the same world and same island.
return;
}
if (island.isAllowed(Flags.PVP_OVERWORLD)) {
alertUser(e.getPlayer(), Flags.PVP_OVERWORLD);
}