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
This commit is contained in:
RoboMWM 2017-07-23 14:48:16 -07:00
parent 92a0adcfc0
commit 452a6a1c7e
5 changed files with 19 additions and 6 deletions

View File

@ -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);
}

View File

@ -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));

View File

@ -3706,8 +3706,8 @@ public class GriefPrevention extends JavaPlugin
ConcurrentHashMap<UUID, BukkitTask> portalReturnTaskMap = new ConcurrentHashMap<UUID, BukkitTask>();
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()))

View File

@ -251,5 +251,6 @@ public enum Messages
TooMuchIpOverlap,
StandInSubclaim,
SubclaimRestricted,
SubclaimUnrestricted
SubclaimUnrestricted,
NetherPortalTrapDetectionMessage
}

View File

@ -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