mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Fixed Enter/Exit messages not being sent when the player teleports to the island
This commit is contained in:
parent
4b9e8f1e0e
commit
343a789d95
@ -5,9 +5,11 @@ package world.bentobox.bentobox.listeners.flags;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||||
@ -28,15 +30,24 @@ public class EnterExitListener extends AbstractFlagListener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onMove(PlayerMoveEvent e) {
|
public void onMove(PlayerMoveEvent e) {
|
||||||
|
handleEnterExitNotification(User.getInstance(e.getPlayer()), e.getFrom(), e.getTo());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
public void onTeleport(PlayerTeleportEvent e) {
|
||||||
|
handleEnterExitNotification(User.getInstance(e.getPlayer()), e.getFrom(), e.getTo());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleEnterExitNotification(User user, Location from, Location to) {
|
||||||
// Only process if Enter Exit flags are active, we are in the right world and there is a change in X or Z coords
|
// Only process if Enter Exit flags are active, we are in the right world and there is a change in X or Z coords
|
||||||
if (!getIWM().inWorld(e.getFrom())
|
if (!getIWM().inWorld(from)
|
||||||
|| e.getFrom().toVector().multiply(XZ).equals(e.getTo().toVector().multiply(XZ))
|
|| from.toVector().multiply(XZ).equals(to.toVector().multiply(XZ))
|
||||||
|| !Flags.ENTER_EXIT_MESSAGES.isSetForWorld(e.getFrom().getWorld())) {
|
|| !Flags.ENTER_EXIT_MESSAGES.isSetForWorld(from.getWorld())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Island> from = getIslands().getProtectedIslandAt(e.getFrom());
|
Optional<Island> islandFrom = getIslands().getProtectedIslandAt(from);
|
||||||
Optional<Island> to = getIslands().getProtectedIslandAt(e.getTo());
|
Optional<Island> islandTo = getIslands().getProtectedIslandAt(to);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Options:
|
* Options:
|
||||||
@ -51,9 +62,7 @@ public class EnterExitListener extends AbstractFlagListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = User.getInstance(e.getPlayer());
|
islandFrom.ifPresent(i -> {
|
||||||
|
|
||||||
from.ifPresent(i -> {
|
|
||||||
// Fire the IslandExitEvent
|
// Fire the IslandExitEvent
|
||||||
new IslandEvent.IslandEventBuilder()
|
new IslandEvent.IslandEventBuilder()
|
||||||
.island(i)
|
.island(i)
|
||||||
@ -74,7 +83,7 @@ public class EnterExitListener extends AbstractFlagListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
to.ifPresent(i -> {
|
islandTo.ifPresent(i -> {
|
||||||
// Fire the IslandEnterEvent
|
// Fire the IslandEnterEvent
|
||||||
new IslandEvent.IslandEventBuilder()
|
new IslandEvent.IslandEventBuilder()
|
||||||
.island(i)
|
.island(i)
|
||||||
|
Loading…
Reference in New Issue
Block a user