Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RoboMWM authored and Minidodo1 committed Jun 14, 2018
1 parent ea248df commit 7a9480d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
15 changes: 8 additions & 7 deletions src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;

//players can be "trapped" in a portal frame if they don't have permission to break
Expand All @@ -35,24 +36,24 @@ class CheckForPortalTrapTask extends BukkitRunnable
private Player player;

//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.instance = plugin;
this.returnLocation = locationToReturn;
player.setMetadata("GP_PORTALRESCUE", new FixedMetadataValue(instance, locationToReturn));
}

@Override
public void run()
{
//if player has logged out, do nothing
if(!player.isOnline())
if(player.isOnline() && player.getPortalCooldown() >= 10)
{
instance.portalReturnTaskMap.remove(player.getUniqueId());
return;
player.teleport(returnLocation);
player.removeMetadata("GP_PORTALRESCUE", instance);
}
player.setPortalCooldown(0);
instance.portalReturnTaskMap.remove(player.getUniqueId());
}
}
4 changes: 2 additions & 2 deletions src/me/ryanhamshire/GriefPrevention/GriefPrevention.java
Original file line number Diff line number Diff line change
Expand Up @@ -3704,10 +3704,10 @@ public void run()

//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>();
public void startRescueTask(Player player)
public void startRescueTask(Player player, Location location)
{
//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
if (portalReturnTaskMap.containsKey(player.getUniqueId()))
Expand Down
31 changes: 20 additions & 11 deletions src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -766,17 +766,18 @@ else if(address.equals(playerData.ipAddress.toString()))
//create a thread to load ignore information
new IgnoreLoaderThread(playerID, playerData.ignoredPlayers).start();

//is he possibly stuck in a portal frame?
//Because people can't read update notes, this try-catch will be here for a while
try
//is he stuck in a portal frame?
if (player.hasMetadata("GP_PORTALRESCUE"))
{
player.setPortalCooldown(0);
}
catch (NoSuchMethodError e)
{
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.");
instance.getServer().dispatchCommand(instance.getServer().getConsoleSender(), "version");
new BukkitRunnable()
{
@Override
public void run()
{
player.teleport((Location)player.getMetadata("GP_PORTALRESCUE").get(0).value());
player.removeMetadata("GP_PORTALRESCUE", instance);
}
}.runTaskLater(instance, 1L);
}


Expand Down Expand Up @@ -857,6 +858,14 @@ void onPlayerQuit(PlayerQuitEvent event)
UUID playerID = player.getUniqueId();
PlayerData playerData = this.dataStore.getPlayerData(playerID);
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)
{
isBanned = player.isBanned();
Expand Down Expand Up @@ -997,7 +1006,7 @@ void onPlayerPortal(PlayerPortalEvent event)
if(event.getCause() == TeleportCause.NETHER_PORTAL)
{
//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
if(!instance.claimsEnabledForWorld(event.getTo().getWorld())) return;
Expand Down

0 comments on commit 7a9480d

Please sign in to comment.