Portal trap check changes (unfinished)

- Cancel existing rescue tasks on successful teleport
- Send the player a message when they are rescued (unfinished)

Someday, I will make this OOP-compliant
This commit is contained in:
RoboMWM 2016-09-30 10:48:19 -07:00
parent b78d1e6413
commit 8e7af23a13
5 changed files with 18 additions and 7 deletions

View File

@ -23,11 +23,12 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
//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.
class CheckForPortalTrapTask implements Runnable
class CheckForPortalTrapTask extends BukkitRunnable
{
//player who recently teleported via nether portal
private Player player;
@ -51,13 +52,14 @@ class CheckForPortalTrapTask implements Runnable
//if still standing in a portal frame, teleport him back through
if(GriefPrevention.instance.isPlayerTrappedInPortal(playerBlock))
{
this.player.teleport(this.returnLocation);
GriefPrevention.instance.rescuePlayerTrappedInPortal(player, returnLocation);
}
//otherwise, note that he 'escaped' the portal frame
else
{
PlayerEventHandler.portalReturnMap.remove(player.getUniqueId());
PlayerEventHandler.portalReturnTaskMap.remove(player.getUniqueId());
}
}
}

View File

@ -1616,6 +1616,7 @@ public abstract class DataStore
this.addDefault(defaults, Messages.ConsoleOnlyCommand, "That command may only be executed from the server console.", null);
this.addDefault(defaults, Messages.WorldNotFound, "World not found.", null);
this.addDefault(defaults, Messages.TooMuchIpOverlap, "Sorry, there are too many players logged in with your IP address.", null);
this.addDefault(defaults, Messages.RescuedFromPortalTrap, "Automatically rescued you from a nether portal. If this was a mistake, use /UndoRescue to return to your prior location.", null);
//load the config file
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(messagesFilePath));

View File

@ -3617,7 +3617,7 @@ public class GriefPrevention extends JavaPlugin
{
Location oldLocation = player.getLocation();
player.teleport(returnLocation);
sendMessage(player, TextMode.Info, Messages.);
sendMessage(player, TextMode.Info, Messages.RescuedFromPortalTrap);
return oldLocation;
}
}

View File

@ -247,5 +247,6 @@ public enum Messages
ConsoleOnlyCommand,
WorldNotFound,
AdjustBlocksAllSuccess,
TooMuchIpOverlap
TooMuchIpOverlap,
RescuedFromPortalTrap
}

View File

@ -70,6 +70,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.BlockIterator;
class PlayerEventHandler implements Listener
@ -766,7 +768,7 @@ class PlayerEventHandler implements Listener
Block playerBlock = player.getLocation().getBlock();
if(GriefPrevention.instance.isPlayerTrappedInPortal(playerBlock))
{
player.teleport(returnLocation);
GriefPrevention.instance.rescuePlayerTrappedInPortal(player, returnLocation);
}
}
@ -974,6 +976,7 @@ class PlayerEventHandler implements Listener
//remember where players teleport from (via portals) in case they're trapped at the destination
static ConcurrentHashMap<UUID, Location> portalReturnMap = new ConcurrentHashMap<UUID, Location>();
static ConcurrentHashMap<UUID, BukkitTask> portalReturnTaskMap = new ConcurrentHashMap<UUID, BukkitTask>();
//when a player teleports via a portal
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
@ -990,9 +993,13 @@ 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
CheckForPortalTrapTask task = new CheckForPortalTrapTask(player, event.getFrom());
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 600L); //after 30 seconds
BukkitTask task = new CheckForPortalTrapTask(player, event.getFrom()).runTaskLater(GriefPrevention.instance, 600L);
portalReturnMap.put(player.getUniqueId(), event.getFrom());
//Cancel existing rescue task
if (portalReturnTaskMap.containsKey(player.getUniqueId()))
portalReturnTaskMap.get(player.getUniqueId()).cancel();
portalReturnTaskMap.put(player.getUniqueId(), task);
//FEATURE: if the player teleporting doesn't have permission to build a nether portal and none already exists at the destination, cancel the teleportation
if(GriefPrevention.instance.config_claims_portalsRequirePermission)