From 452a6a1c7ebf5c3cc497ae645a926cbd16a2fee0 Mon Sep 17 00:00:00 2001 From: RoboMWM Date: Sun, 23 Jul 2017 14:48:16 -0700 Subject: [PATCH] Add a delay before immediately rescuing players trapped in nether portals In case they actually aren't and lagged out (perhaps due to chunk loading), they'll have a few seconds to be able to walk out before being automatically rescued on reconnect. Also logs when a player has been rescued --- .../GriefPrevention/CheckForPortalTrapTask.java | 1 + .../ryanhamshire/GriefPrevention/DataStore.java | 2 ++ .../GriefPrevention/GriefPrevention.java | 4 ++-- src/me/ryanhamshire/GriefPrevention/Messages.java | 3 ++- .../GriefPrevention/PlayerEventHandler.java | 15 ++++++++++++--- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java b/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java index d10c37d..e98decf 100644 --- a/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java +++ b/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java @@ -51,6 +51,7 @@ class CheckForPortalTrapTask extends BukkitRunnable { if(player.isOnline() && player.getPortalCooldown() >= 10) { + instance.AddLogEntry("Rescued " + player.getName() + " from a nether portal.\nTeleported from " + player.getLocation().toString() + " to " + ((Location)player.getMetadata("GP_PORTALRESCUE").get(0).value()).toString(), CustomLogEntryTypes.Debug); player.teleport(returnLocation); player.removeMetadata("GP_PORTALRESCUE", instance); } diff --git a/src/me/ryanhamshire/GriefPrevention/DataStore.java b/src/me/ryanhamshire/GriefPrevention/DataStore.java index 56352ba..20b886e 100644 --- a/src/me/ryanhamshire/GriefPrevention/DataStore.java +++ b/src/me/ryanhamshire/GriefPrevention/DataStore.java @@ -1643,6 +1643,8 @@ public abstract class DataStore this.addDefault(defaults, Messages.SubclaimRestricted, "This subclaim's permissions will no longer inherit from the parent claim", null); this.addDefault(defaults, Messages.SubclaimUnrestricted, "This subclaim's permissions will now inherit from the parent claim", null); + this.addDefault(defaults, Messages.NetherPortalTrapDetectionMessage, "It seems you might be stuck inside a nether portal. We will rescue you in a few seconds if that is the case!", "Sent to player on join, if they left while inside a nether portal."); + //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 058e434..b76b601 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -3706,8 +3706,8 @@ public class GriefPrevention extends JavaPlugin ConcurrentHashMap portalReturnTaskMap = new ConcurrentHashMap(); public void startRescueTask(Player player, Location location) { - //Schedule task to reset player's portal cooldown after 20 seconds - BukkitTask task = new CheckForPortalTrapTask(player, this, location).runTaskLater(GriefPrevention.instance, 400L); + //Schedule task to reset player's portal cooldown after 30 seconds (Maximum timeout time for client, in case their network is slow and taking forever to load chunks) + BukkitTask task = new CheckForPortalTrapTask(player, this, location).runTaskLater(GriefPrevention.instance, 600L); //Cancel existing rescue task if (portalReturnTaskMap.containsKey(player.getUniqueId())) diff --git a/src/me/ryanhamshire/GriefPrevention/Messages.java b/src/me/ryanhamshire/GriefPrevention/Messages.java index c5422a7..111ce68 100644 --- a/src/me/ryanhamshire/GriefPrevention/Messages.java +++ b/src/me/ryanhamshire/GriefPrevention/Messages.java @@ -251,5 +251,6 @@ public enum Messages TooMuchIpOverlap, StandInSubclaim, SubclaimRestricted, - SubclaimUnrestricted + SubclaimUnrestricted, + NetherPortalTrapDetectionMessage } diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index e81dfcd..0e10d59 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -769,16 +769,25 @@ class PlayerEventHandler implements Listener //is he stuck in a portal frame? if (player.hasMetadata("GP_PORTALRESCUE")) { + //If so, let him know and rescue him in 10 seconds. If he is in fact not trapped, hopefully chunks will have loaded by this time so he can walk out. + instance.sendMessage(player, TextMode.Info, Messages.NetherPortalTrapDetectionMessage, 20L); new BukkitRunnable() { @Override public void run() { - player.teleport((Location)player.getMetadata("GP_PORTALRESCUE").get(0).value()); - player.removeMetadata("GP_PORTALRESCUE", instance); + if (player.getPortalCooldown() > 8) + { + instance.AddLogEntry("Rescued " + player.getName() + " from a nether portal.\nTeleported from " + player.getLocation().toString() + " to " + ((Location)player.getMetadata("GP_PORTALRESCUE").get(0).value()).toString(), CustomLogEntryTypes.Debug); + player.teleport((Location)player.getMetadata("GP_PORTALRESCUE").get(0).value()); + player.removeMetadata("GP_PORTALRESCUE", instance); + } } - }.runTaskLater(instance, 1L); + }.runTaskLater(instance, 200L); } + //Otherwise just reset cooldown, just in case they happened to logout again... + else + player.setPortalCooldown(0); //if we're holding a logout message for this player, don't send that or this event's join message