Implement #114
This commit is contained in:
parent
d079fcf379
commit
04bc32336c
|
|
@ -23,6 +23,7 @@ import org.bukkit.Material;
|
|||
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
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
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()))
|
||||
|
|
|
|||
|
|
@ -766,17 +766,18 @@ class PlayerEventHandler implements Listener
|
|||
//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);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -857,6 +858,14 @@ class PlayerEventHandler implements Listener
|
|||
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();
|
||||
|
|
@ -997,7 +1006,7 @@ class PlayerEventHandler implements Listener
|
|||
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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user