Skip to content

Commit

Permalink
Improve queued-teleport controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravis96 committed Oct 5, 2024
1 parent 45185d7 commit ccc3901
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;

@RequiredArgsConstructor
public class QueuedTeleportController implements Listener {
Expand All @@ -25,9 +26,32 @@ public void onPlayerMove(PlayerMoveEvent e) {
}

if (e.getFrom().getBlockX() != e.getTo().getBlockX() ||
e.getFrom().getBlockY() != e.getTo().getBlockY() ||
e.getFrom().getBlockZ() != e.getTo().getBlockZ()) {
queuedTeleport.getMovedNotice().accept(player);
this.queuedTeleportCache.remove(player.getUniqueId());
}
}

@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.PLUGIN) ||
event.getCause().equals(PlayerTeleportEvent.TeleportCause.UNKNOWN)) {
return;
}

final Player player = event.getPlayer();

if (!this.queuedTeleportCache.isQueued(player.getUniqueId())) {
return;
}

final QueuedTeleport queuedTeleport = this.queuedTeleportCache.get(player.getUniqueId());
if (!queuedTeleport.isCancelOnMove()) {
return;
}

queuedTeleport.getMovedNotice().accept(player);
this.queuedTeleportCache.remove(player.getUniqueId());
}
}

0 comments on commit ccc3901

Please sign in to comment.