mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Cancel teleport on damage or move
This commit is contained in:
parent
4166f1276a
commit
5f9dce1a07
@ -598,9 +598,16 @@ public class PlotMain extends JavaPlugin implements Listener {
|
||||
final World world = player.getWorld();
|
||||
final int x = loc.getBlockX();
|
||||
final int z = loc.getBlockZ();
|
||||
final String name = player.getName();
|
||||
TaskManager.TELEPORT_QUEUE.add(name);
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!TaskManager.TELEPORT_QUEUE.contains(name)) {
|
||||
PlayerFunctions.sendMessage(player, C.TELEPORT_FAILED);
|
||||
return;
|
||||
}
|
||||
TaskManager.TELEPORT_QUEUE.remove(name);
|
||||
if (!player.isOnline()) {
|
||||
return;
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ public enum C {
|
||||
TELEPORTED_TO_PLOT("&6You have been teleported"),
|
||||
TELEPORTED_TO_ROAD("&cYou got teleported to the road"),
|
||||
TELEPORT_IN_SECONDS("&6Teleporting in %s seconds. Do not move..."),
|
||||
TELEPORT_FAILED("&cTeleportation cancelled due to movement"),
|
||||
TELEPORT_FAILED("&cTeleportation cancelled due to movement or damage"),
|
||||
/*
|
||||
* Set Block
|
||||
*/
|
||||
|
@ -99,6 +99,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
|
||||
/**
|
||||
@ -161,6 +162,12 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
final Location q = new Location(t.getWorld(), t.getBlockX(), 0, t.getZ());
|
||||
|
||||
if ((f.getBlockX() != q.getBlockX()) || (f.getBlockZ() != q.getBlockZ())) {
|
||||
if (Settings.TELEPORT_DELAY != 0 && TaskManager.TELEPORT_QUEUE.size() > 0) {
|
||||
String name = player.getName();
|
||||
if (TaskManager.TELEPORT_QUEUE.contains(name)) {
|
||||
TaskManager.TELEPORT_QUEUE.remove(name);
|
||||
}
|
||||
}
|
||||
if (!isPlotWorld(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
@ -916,6 +923,15 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
final Location l = e.getEntity().getLocation();
|
||||
final Entity d = e.getDamager();
|
||||
final Entity a = e.getEntity();
|
||||
|
||||
if (Settings.TELEPORT_DELAY != 0 && TaskManager.TELEPORT_QUEUE.size() > 0 && a instanceof Player) {
|
||||
Player player = (Player) a;
|
||||
String name = player.getName();
|
||||
if (TaskManager.TELEPORT_QUEUE.contains(name)) {
|
||||
TaskManager.TELEPORT_QUEUE.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (isPlotWorld(l)) {
|
||||
if (d instanceof Player) {
|
||||
final Player p = (Player) d;
|
||||
|
@ -1,8 +1,13 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
|
||||
public class TaskManager {
|
||||
|
||||
public static HashSet<String> TELEPORT_QUEUE = new HashSet<>();
|
||||
|
||||
public static void runTask(final Runnable r) {
|
||||
PlotMain.getMain().getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), r);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user