Skip to content

Commit

Permalink
Treat teleporting as moving for delayed commands.
Browse files Browse the repository at this point in the history
Fixes #1722
  • Loading branch information
tastybento committed Mar 21, 2021
1 parent 8ecfee4 commit 3c4b7de
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.scheduler.BukkitTask;

import world.bentobox.bentobox.api.addons.Addon;
Expand All @@ -26,19 +28,32 @@ public abstract class DelayedTeleportCommand extends CompositeCommand implements
*/
private static Map<UUID, DelayedCommand> toBeMonitored = new HashMap<>();

@EventHandler
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e) {
UUID uuid = e.getPlayer().getUniqueId();
// Only check x,y,z
if (toBeMonitored.containsKey(uuid) && !e.getTo().toVector().equals(toBeMonitored.get(uuid).getLocation().toVector())) {
// Player moved
toBeMonitored.get(uuid).getTask().cancel();
toBeMonitored.remove(uuid);
// Player has another outstanding confirmation request that will now be cancelled
User.getInstance(e.getPlayer()).notify("commands.delay.moved-so-command-cancelled");
moved(uuid);
}
}

private void moved(UUID uuid) {
// Player moved
toBeMonitored.get(uuid).getTask().cancel();
toBeMonitored.remove(uuid);
// Player has another outstanding confirmation request that will now be cancelled
User.getInstance(uuid).notify("commands.delay.moved-so-command-cancelled");
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent e) {
UUID uuid = e.getPlayer().getUniqueId();
if (toBeMonitored.containsKey(uuid)) {
moved(uuid);
}
}


/**
* Top level command
* @param addon - addon creating the command
Expand Down

0 comments on commit 3c4b7de

Please sign in to comment.