diff --git a/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java b/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java index c85fe7a..57aaa1d 100644 --- a/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java +++ b/src/me/ryanhamshire/GriefPrevention/CheckForPortalTrapTask.java @@ -49,7 +49,7 @@ class CheckForPortalTrapTask implements Runnable Block playerBlock = this.player.getLocation().getBlock(); //if still standing in a portal frame, teleport him back through - if(playerBlock.getType() == Material.PORTAL || isInNonOccludingBlock(playerBlock)) + if(GriefPrevention.instance.isPlayerTrappedInPortal(playerBlock)) { this.player.teleport(this.returnLocation); } @@ -60,28 +60,4 @@ class CheckForPortalTrapTask implements Runnable PlayerEventHandler.portalReturnMap.remove(player.getUniqueId()); } } - - boolean isInNonOccludingBlock(Block block) - { - Material playerBlock = block.getType(); - //Most blocks you can "stand" inside but cannot pass through (isSolid) usually can be seen through (!isOccluding) - //This can cause players to technically be considered not in a portal block, yet in reality is still stuck in the portal animation. - if ((!playerBlock.isSolid() || playerBlock.isOccluding())) //If it is _not_ such a block, - { - //Check the block above - playerBlock = block.getRelative(BlockFace.UP).getType(); - if ((!playerBlock.isSolid() || playerBlock.isOccluding())) - return false; //player is not stuck - } - //Check if this block is also adjacent to a portal - if (block.getRelative(BlockFace.EAST).getType() == Material.PORTAL - || block.getRelative(BlockFace.WEST).getType() == Material.PORTAL - || block.getRelative(BlockFace.NORTH).getType() == Material.PORTAL - || block.getRelative(BlockFace.SOUTH).getType() == Material.PORTAL) - return true; - return false; - } - - - } diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index bab39e2..4b6830e 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -3591,4 +3591,33 @@ public class GriefPrevention extends JavaPlugin claim.isAdminClaim() && claim.parent != null && GriefPrevention.instance.config_pvp_noCombatInAdminSubdivisions || !claim.isAdminClaim() && GriefPrevention.instance.config_pvp_noCombatInPlayerLandClaims; } + + protected boolean isPlayerTrappedInPortal(Block block) + { + Material playerBlock = block.getType(); + if (playerBlock == Material.PORTAL) + return true; + //Most blocks you can "stand" inside but cannot pass through (isSolid) usually can be seen through (!isOccluding) + //This can cause players to technically be considered not in a portal block, yet in reality is still stuck in the portal animation. + if ((!playerBlock.isSolid() || playerBlock.isOccluding())) //If it is _not_ such a block, + { + //Check the block above + playerBlock = block.getRelative(BlockFace.UP).getType(); + if ((!playerBlock.isSolid() || playerBlock.isOccluding())) + return false; //player is not stuck + } + //Check if this block is also adjacent to a portal + return block.getRelative(BlockFace.EAST).getType() == Material.PORTAL + || block.getRelative(BlockFace.WEST).getType() == Material.PORTAL + || block.getRelative(BlockFace.NORTH).getType() == Material.PORTAL + || block.getRelative(BlockFace.SOUTH).getType() == Material.PORTAL; + } + + public Location rescuePlayerTrappedInPortal(Player player, Location returnLocation) + { + Location oldLocation = player.getLocation(); + player.teleport(returnLocation); + sendMessage(player, TextMode.Info, Messages.); + return oldLocation; + } } diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index f21211e..906aa05 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -764,7 +764,7 @@ class PlayerEventHandler implements Listener { PlayerEventHandler.portalReturnMap.remove(player.getUniqueId()); Block playerBlock = player.getLocation().getBlock(); - if(playerBlock.getType() == Material.PORTAL || isInNonOccludingBlock(playerBlock)) + if(GriefPrevention.instance.isPlayerTrappedInPortal(playerBlock)) { player.teleport(returnLocation); } @@ -787,27 +787,6 @@ class PlayerEventHandler implements Listener } } - boolean isInNonOccludingBlock(Block block) - { - Material playerBlock = block.getType(); - //Most blocks you can "stand" inside but cannot pass through (isSolid) usually can be seen through (!isOccluding) - //This can cause players to technically be considered not in a portal block, yet in reality is still stuck in the portal animation. - if ((!playerBlock.isSolid() || playerBlock.isOccluding())) //If it is _not_ such a block, - { - //Check the block above - playerBlock = block.getRelative(BlockFace.UP).getType(); - if ((!playerBlock.isSolid() || playerBlock.isOccluding())) - return false; //player is not stuck - } - //Check if this block is also adjacent to a portal - if (block.getRelative(BlockFace.EAST).getType() == Material.PORTAL - || block.getRelative(BlockFace.WEST).getType() == Material.PORTAL - || block.getRelative(BlockFace.NORTH).getType() == Material.PORTAL - || block.getRelative(BlockFace.SOUTH).getType() == Material.PORTAL) - return true; - return false; - } - //when a player spawns, conditionally apply temporary pvp protection @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) void onPlayerRespawn (PlayerRespawnEvent event)