Have CheckForPortalTrapTask check metadata existence first

If a player logs out then logs back in, and the task in the
PlayerJoinEvent rescues him first and the player has sat in the rescue
location for over 10 ticks (which should be within another portal), then
this task will also attempt to rescue the player. Because it was using
metadata in the log message though, it failed but also printed a
stacktrace since the player's metadata was already removed.
This commit is contained in:
RoboMWM 2018-09-22 12:30:49 -07:00
parent 5fc85097a7
commit 82f17b89b6

View File

@ -49,9 +49,9 @@ class CheckForPortalTrapTask extends BukkitRunnable
@Override
public void run()
{
if(player.isOnline() && player.getPortalCooldown() >= 10)
if(player.isOnline() && player.getPortalCooldown() >= 10 && player.hasMetadata("GP_PORTALRESCUE"))
{
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);
instance.AddLogEntry("Rescued " + player.getName() + " from a nether portal.\nTeleported from " + player.getLocation().toString() + " to " + returnLocation.toString(), CustomLogEntryTypes.Debug);
player.teleport(returnLocation);
player.removeMetadata("GP_PORTALRESCUE", instance);
}