This commit is contained in:
RoboMWM 2017-07-22 00:19:09 -07:00
parent d079fcf379
commit 04bc32336c
3 changed files with 30 additions and 20 deletions

View File

@ -23,6 +23,7 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
//players can be "trapped" in a portal frame if they don't have permission to break //players can be "trapped" in a portal frame if they don't have permission to break
@ -35,24 +36,24 @@ class CheckForPortalTrapTask extends BukkitRunnable
private Player player; private Player player;
//where to send the player back to if he hasn't left the portal frame //where to send the player back to if he hasn't left the portal frame
//private Location returnLocation; private Location returnLocation;
public CheckForPortalTrapTask(Player player, GriefPrevention plugin) public CheckForPortalTrapTask(Player player, GriefPrevention plugin, Location locationToReturn)
{ {
this.player = player; this.player = player;
this.instance = plugin; this.instance = plugin;
this.returnLocation = locationToReturn;
player.setMetadata("GP_PORTALRESCUE", new FixedMetadataValue(instance, locationToReturn));
} }
@Override @Override
public void run() public void run()
{ {
//if player has logged out, do nothing if(player.isOnline() && player.getPortalCooldown() >= 10)
if(!player.isOnline())
{ {
instance.portalReturnTaskMap.remove(player.getUniqueId()); player.teleport(returnLocation);
return; player.removeMetadata("GP_PORTALRESCUE", instance);
} }
player.setPortalCooldown(0);
instance.portalReturnTaskMap.remove(player.getUniqueId()); instance.portalReturnTaskMap.remove(player.getUniqueId());
} }
} }

View File

@ -3704,10 +3704,10 @@ public class GriefPrevention extends JavaPlugin
//Track scheduled "rescues" so we can cancel them if the player happens to teleport elsewhere so we can cancel it. //Track scheduled "rescues" so we can cancel them if the player happens to teleport elsewhere so we can cancel it.
ConcurrentHashMap<UUID, BukkitTask> portalReturnTaskMap = new ConcurrentHashMap<UUID, BukkitTask>(); ConcurrentHashMap<UUID, BukkitTask> portalReturnTaskMap = new ConcurrentHashMap<UUID, BukkitTask>();
public void startRescueTask(Player player) public void startRescueTask(Player player, Location location)
{ {
//Schedule task to reset player's portal cooldown after 20 seconds //Schedule task to reset player's portal cooldown after 20 seconds
BukkitTask task = new CheckForPortalTrapTask(player, this).runTaskLater(GriefPrevention.instance, 400L); BukkitTask task = new CheckForPortalTrapTask(player, this, location).runTaskLater(GriefPrevention.instance, 400L);
//Cancel existing rescue task //Cancel existing rescue task
if (portalReturnTaskMap.containsKey(player.getUniqueId())) if (portalReturnTaskMap.containsKey(player.getUniqueId()))

View File

@ -766,17 +766,18 @@ class PlayerEventHandler implements Listener
//create a thread to load ignore information //create a thread to load ignore information
new IgnoreLoaderThread(playerID, playerData.ignoredPlayers).start(); new IgnoreLoaderThread(playerID, playerData.ignoredPlayers).start();
//is he possibly stuck in a portal frame? //is he stuck in a portal frame?
//Because people can't read update notes, this try-catch will be here for a while if (player.hasMetadata("GP_PORTALRESCUE"))
try
{ {
player.setPortalCooldown(0); new BukkitRunnable()
} {
catch (NoSuchMethodError e) @Override
{ public void run()
instance.getLogger().severe("Nether portal trap rescues will not function and you will receive a nice stack trace every time a player uses a nether portal."); {
instance.getLogger().severe("Please update your server mod (Craftbukkit/Spigot/Paper), as mentioned in the update notes."); player.teleport((Location)player.getMetadata("GP_PORTALRESCUE").get(0).value());
instance.getServer().dispatchCommand(instance.getServer().getConsoleSender(), "version"); player.removeMetadata("GP_PORTALRESCUE", instance);
}
}.runTaskLater(instance, 1L);
} }
@ -857,6 +858,14 @@ class PlayerEventHandler implements Listener
UUID playerID = player.getUniqueId(); UUID playerID = player.getUniqueId();
PlayerData playerData = this.dataStore.getPlayerData(playerID); PlayerData playerData = this.dataStore.getPlayerData(playerID);
boolean isBanned; boolean isBanned;
//If player is not trapped in a portal and has a pending rescue task, remove the associated metadata
//Why 9? No idea why, but this is decremented by 1 when the player disconnects.
if (player.getPortalCooldown() < 9)
{
player.removeMetadata("GP_PORTALRESCUE", instance);
}
if(playerData.wasKicked) if(playerData.wasKicked)
{ {
isBanned = player.isBanned(); isBanned = player.isBanned();
@ -997,7 +1006,7 @@ class PlayerEventHandler implements Listener
if(event.getCause() == TeleportCause.NETHER_PORTAL) if(event.getCause() == TeleportCause.NETHER_PORTAL)
{ {
//FEATURE: when players get trapped in a nether portal, send them back through to the other side //FEATURE: when players get trapped in a nether portal, send them back through to the other side
instance.startRescueTask(player); instance.startRescueTask(player, player.getLocation());
//don't track in worlds where claims are not enabled //don't track in worlds where claims are not enabled
if(!instance.claimsEnabledForWorld(event.getTo().getWorld())) return; if(!instance.claimsEnabledForWorld(event.getTo().getWorld())) return;