diff --git a/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java b/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java index 57aaa1d..5579d6d 100644 --- a/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java +++ b/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java @@ -23,11 +23,12 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; //players can be "trapped" in a portal frame if they don't have permission to break //solid blocks blocking them from exiting the frame //if that happens, we detect the problem and send them back through the portal. -class CheckForPortalTrapTask implements Runnable +class CheckForPortalTrapTask extends BukkitRunnable { //player who recently teleported via nether portal private Player player; @@ -51,13 +52,14 @@ class CheckForPortalTrapTask implements Runnable //if still standing in a portal frame, teleport him back through if(GriefPrevention.instance.isPlayerTrappedInPortal(playerBlock)) { - this.player.teleport(this.returnLocation); + GriefPrevention.instance.rescuePlayerTrappedInPortal(player, returnLocation); } //otherwise, note that he 'escaped' the portal frame else { PlayerEventHandler.portalReturnMap.remove(player.getUniqueId()); + PlayerEventHandler.portalReturnTaskMap.remove(player.getUniqueId()); } } } diff --git a/src/me/ryanhamshire/GriefPrevention/DataStore.java b/src/me/ryanhamshire/GriefPrevention/DataStore.java index 921e2fd..7fe24df 100644 --- a/src/me/ryanhamshire/GriefPrevention/DataStore.java +++ b/src/me/ryanhamshire/GriefPrevention/DataStore.java @@ -1616,6 +1616,7 @@ public abstract class DataStore this.addDefault(defaults, Messages.ConsoleOnlyCommand, "That command may only be executed from the server console.", null); this.addDefault(defaults, Messages.WorldNotFound, "World not found.", null); this.addDefault(defaults, Messages.TooMuchIpOverlap, "Sorry, there are too many players logged in with your IP address.", null); + this.addDefault(defaults, Messages.RescuedFromPortalTrap, "Automatically rescued you from a nether portal. If this was a mistake, use /UndoRescue to return to your prior location.", null); //load the config file FileConfiguration config = YamlConfiguration.loadConfiguration(new File(messagesFilePath)); diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 4b6830e..006795c 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -3617,7 +3617,7 @@ public class GriefPrevention extends JavaPlugin { Location oldLocation = player.getLocation(); player.teleport(returnLocation); - sendMessage(player, TextMode.Info, Messages.); + sendMessage(player, TextMode.Info, Messages.RescuedFromPortalTrap); return oldLocation; } } diff --git a/src/me/ryanhamshire/GriefPrevention/Messages.java b/src/me/ryanhamshire/GriefPrevention/Messages.java index 8c06845..a01c5da 100644 --- a/src/me/ryanhamshire/GriefPrevention/Messages.java +++ b/src/me/ryanhamshire/GriefPrevention/Messages.java @@ -247,5 +247,6 @@ public enum Messages ConsoleOnlyCommand, WorldNotFound, AdjustBlocksAllSuccess, - TooMuchIpOverlap + TooMuchIpOverlap, + RescuedFromPortalTrap } diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 906aa05..72c821d 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -70,6 +70,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.BlockIterator; class PlayerEventHandler implements Listener @@ -766,7 +768,7 @@ class PlayerEventHandler implements Listener Block playerBlock = player.getLocation().getBlock(); if(GriefPrevention.instance.isPlayerTrappedInPortal(playerBlock)) { - player.teleport(returnLocation); + GriefPrevention.instance.rescuePlayerTrappedInPortal(player, returnLocation); } } @@ -974,6 +976,7 @@ class PlayerEventHandler implements Listener //remember where players teleport from (via portals) in case they're trapped at the destination static ConcurrentHashMap portalReturnMap = new ConcurrentHashMap(); + static ConcurrentHashMap portalReturnTaskMap = new ConcurrentHashMap(); //when a player teleports via a portal @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) @@ -990,9 +993,13 @@ class PlayerEventHandler implements Listener if(event.getCause() == TeleportCause.NETHER_PORTAL) { //FEATURE: when players get trapped in a nether portal, send them back through to the other side - CheckForPortalTrapTask task = new CheckForPortalTrapTask(player, event.getFrom()); - GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 600L); //after 30 seconds + BukkitTask task = new CheckForPortalTrapTask(player, event.getFrom()).runTaskLater(GriefPrevention.instance, 600L); portalReturnMap.put(player.getUniqueId(), event.getFrom()); + + //Cancel existing rescue task + if (portalReturnTaskMap.containsKey(player.getUniqueId())) + portalReturnTaskMap.get(player.getUniqueId()).cancel(); + portalReturnTaskMap.put(player.getUniqueId(), task); //FEATURE: if the player teleporting doesn't have permission to build a nether portal and none already exists at the destination, cancel the teleportation if(GriefPrevention.instance.config_claims_portalsRequirePermission)