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:
parent
b78d1e6413
commit
8e7af23a13
|
|
@ -23,11 +23,12 @@ 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.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
|
||||||
//solid blocks blocking them from exiting the frame
|
//solid blocks blocking them from exiting the frame
|
||||||
//if that happens, we detect the problem and send them back through the portal.
|
//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
|
//player who recently teleported via nether portal
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
@ -51,13 +52,14 @@ class CheckForPortalTrapTask implements Runnable
|
||||||
//if still standing in a portal frame, teleport him back through
|
//if still standing in a portal frame, teleport him back through
|
||||||
if(GriefPrevention.instance.isPlayerTrappedInPortal(playerBlock))
|
if(GriefPrevention.instance.isPlayerTrappedInPortal(playerBlock))
|
||||||
{
|
{
|
||||||
this.player.teleport(this.returnLocation);
|
GriefPrevention.instance.rescuePlayerTrappedInPortal(player, returnLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
//otherwise, note that he 'escaped' the portal frame
|
//otherwise, note that he 'escaped' the portal frame
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PlayerEventHandler.portalReturnMap.remove(player.getUniqueId());
|
PlayerEventHandler.portalReturnMap.remove(player.getUniqueId());
|
||||||
|
PlayerEventHandler.portalReturnTaskMap.remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.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.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.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
|
//load the config file
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(messagesFilePath));
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(messagesFilePath));
|
||||||
|
|
|
||||||
|
|
@ -3617,7 +3617,7 @@ public class GriefPrevention extends JavaPlugin
|
||||||
{
|
{
|
||||||
Location oldLocation = player.getLocation();
|
Location oldLocation = player.getLocation();
|
||||||
player.teleport(returnLocation);
|
player.teleport(returnLocation);
|
||||||
sendMessage(player, TextMode.Info, Messages.);
|
sendMessage(player, TextMode.Info, Messages.RescuedFromPortalTrap);
|
||||||
return oldLocation;
|
return oldLocation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -247,5 +247,6 @@ public enum Messages
|
||||||
ConsoleOnlyCommand,
|
ConsoleOnlyCommand,
|
||||||
WorldNotFound,
|
WorldNotFound,
|
||||||
AdjustBlocksAllSuccess,
|
AdjustBlocksAllSuccess,
|
||||||
TooMuchIpOverlap
|
TooMuchIpOverlap,
|
||||||
|
RescuedFromPortalTrap
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,8 @@ import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.bukkit.util.BlockIterator;
|
import org.bukkit.util.BlockIterator;
|
||||||
|
|
||||||
class PlayerEventHandler implements Listener
|
class PlayerEventHandler implements Listener
|
||||||
|
|
@ -766,7 +768,7 @@ class PlayerEventHandler implements Listener
|
||||||
Block playerBlock = player.getLocation().getBlock();
|
Block playerBlock = player.getLocation().getBlock();
|
||||||
if(GriefPrevention.instance.isPlayerTrappedInPortal(playerBlock))
|
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
|
//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, Location> portalReturnMap = new ConcurrentHashMap<UUID, Location>();
|
||||||
|
static ConcurrentHashMap<UUID, BukkitTask> portalReturnTaskMap = new ConcurrentHashMap<UUID, BukkitTask>();
|
||||||
|
|
||||||
//when a player teleports via a portal
|
//when a player teleports via a portal
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||||
|
|
@ -990,10 +993,14 @@ 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
|
||||||
CheckForPortalTrapTask task = new CheckForPortalTrapTask(player, event.getFrom());
|
BukkitTask task = new CheckForPortalTrapTask(player, event.getFrom()).runTaskLater(GriefPrevention.instance, 600L);
|
||||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 600L); //after 30 seconds
|
|
||||||
portalReturnMap.put(player.getUniqueId(), event.getFrom());
|
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
|
//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)
|
if(GriefPrevention.instance.config_claims_portalsRequirePermission)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user