MCPcopy Create free account
hub / github.com/boxbeam/RedLib / delayedTeleport

Method delayedTeleport

src/redempt/redlib/misc/LocationUtils.java:137–158  ·  view source on GitHub ↗

Initiates a delayed teleport for a player which will be cancelled if the player moves. The messages relevant to this will be sent automatically. @param player The player to teleport @param loc The location to teleport the player to after the delay @param ticks The delay for the teleport, in tic

(Player player, Location loc, int ticks, Consumer<Boolean> result)

Source from the content-addressed store, hash-verified

135 * @param result A lambda to handle the result, given true if the teleport succeeded, false otherwise
136 */
137 public static void delayedTeleport(Player player, Location loc, int ticks, Consumer<Boolean> result) {
138 double seconds = ticks / 20d;
139 player.sendMessage(RedLib.msg("teleportDelay").replace("%seconds%", timeFormat.format(seconds)));
140 Location start = player.getLocation();
141 Task[] task = {null};
142 EventListener<?> listener = new EventListener<>(RedLib.getInstance(), PlayerMoveEvent.class, (l, e) -> {
143 if (!e.getPlayer().equals(player)) {
144 return;
145 }
146 if (!start.getWorld().equals(e.getTo().getWorld()) || start.distanceSquared(e.getTo()) > 0.125) {
147 player.sendMessage(RedLib.msg("teleportCancelled"));
148 task[0].cancel();
149 l.unregister();
150 result.accept(false);
151 }
152 });
153 task[0] = Task.syncDelayed(RedLib.getInstance(), () -> {
154 player.teleport(loc);
155 listener.unregister();
156 result.accept(true);
157 }, ticks);
158 }
159
160 /**
161 * Initiates a delayed teleport for a player which will be cancelled if the player moves. The messages

Callers

nothing calls this directly

Calls 11

msgMethod · 0.95
getInstanceMethod · 0.95
unregisterMethod · 0.95
syncDelayedMethod · 0.95
sendMessageMethod · 0.80
distanceSquaredMethod · 0.80
getLocationMethod · 0.45
equalsMethod · 0.45
getPlayerMethod · 0.45
getWorldMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected