refactor portal trap check method

This commit is contained in:
RoboMWM 2016-09-29 23:56:36 -07:00
parent 068fb172bb
commit b78d1e6413
3 changed files with 31 additions and 47 deletions

View File

@ -49,7 +49,7 @@ class CheckForPortalTrapTask implements Runnable
Block playerBlock = this.player.getLocation().getBlock(); Block playerBlock = this.player.getLocation().getBlock();
//if still standing in a portal frame, teleport him back through //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); this.player.teleport(this.returnLocation);
} }
@ -60,28 +60,4 @@ class CheckForPortalTrapTask implements Runnable
PlayerEventHandler.portalReturnMap.remove(player.getUniqueId()); 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;
}
} }

View File

@ -3591,4 +3591,33 @@ public class GriefPrevention extends JavaPlugin
claim.isAdminClaim() && claim.parent != null && GriefPrevention.instance.config_pvp_noCombatInAdminSubdivisions || claim.isAdminClaim() && claim.parent != null && GriefPrevention.instance.config_pvp_noCombatInAdminSubdivisions ||
!claim.isAdminClaim() && GriefPrevention.instance.config_pvp_noCombatInPlayerLandClaims; !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;
}
} }

View File

@ -764,7 +764,7 @@ class PlayerEventHandler implements Listener
{ {
PlayerEventHandler.portalReturnMap.remove(player.getUniqueId()); PlayerEventHandler.portalReturnMap.remove(player.getUniqueId());
Block playerBlock = player.getLocation().getBlock(); Block playerBlock = player.getLocation().getBlock();
if(playerBlock.getType() == Material.PORTAL || isInNonOccludingBlock(playerBlock)) if(GriefPrevention.instance.isPlayerTrappedInPortal(playerBlock))
{ {
player.teleport(returnLocation); 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 //when a player spawns, conditionally apply temporary pvp protection
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
void onPlayerRespawn (PlayerRespawnEvent event) void onPlayerRespawn (PlayerRespawnEvent event)