2014-12-21 21:32:09 +00:00
/ *
GriefPrevention Server Plugin for Minecraft
Copyright ( C ) 2012 Ryan Hamshire
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
package me.ryanhamshire.GriefPrevention ;
import org.bukkit.Location ;
import org.bukkit.Material ;
2016-08-27 02:44:18 +00:00
import org.bukkit.block.Block ;
import org.bukkit.block.BlockFace ;
2014-12-21 21:32:09 +00:00
import org.bukkit.entity.Player ;
2017-07-22 07:19:09 +00:00
import org.bukkit.metadata.FixedMetadataValue ;
2016-09-30 17:48:19 +00:00
import org.bukkit.scheduler.BukkitRunnable ;
2014-12-21 21:32:09 +00:00
//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.
2016-09-30 17:48:19 +00:00
class CheckForPortalTrapTask extends BukkitRunnable
2014-12-21 21:32:09 +00:00
{
2016-09-30 19:56:23 +00:00
GriefPrevention instance ;
2014-12-21 21:32:09 +00:00
//player who recently teleported via nether portal
private Player player ;
//where to send the player back to if he hasn't left the portal frame
2017-07-22 07:19:09 +00:00
private Location returnLocation ;
2014-12-21 21:32:09 +00:00
2017-07-22 07:19:09 +00:00
public CheckForPortalTrapTask ( Player player , GriefPrevention plugin , Location locationToReturn )
2014-12-21 21:32:09 +00:00
{
this . player = player ;
2016-09-30 19:56:23 +00:00
this . instance = plugin ;
2017-07-22 07:19:09 +00:00
this . returnLocation = locationToReturn ;
player . setMetadata ( " GP_PORTALRESCUE " , new FixedMetadataValue ( instance , locationToReturn ) ) ;
2014-12-21 21:32:09 +00:00
}
@Override
public void run ( )
{
2017-07-22 07:19:09 +00:00
if ( player . isOnline ( ) & & player . getPortalCooldown ( ) > = 10 )
2016-08-27 02:44:18 +00:00
{
2017-07-23 21:48:16 +00:00
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 ) ;
2017-07-22 07:19:09 +00:00
player . teleport ( returnLocation ) ;
player . removeMetadata ( " GP_PORTALRESCUE " , instance ) ;
2016-08-27 02:44:18 +00:00
}
2016-10-02 08:22:40 +00:00
instance . portalReturnTaskMap . remove ( player . getUniqueId ( ) ) ;
2014-12-21 21:32:09 +00:00
}
}