broaden nether portal trap check
This commit is contained in:
parent
3894223f83
commit
1b77f12a4b
|
|
@ -20,6 +20,8 @@ package me.ryanhamshire.GriefPrevention;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
//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
|
||||||
|
|
@ -45,8 +47,9 @@ class CheckForPortalTrapTask implements Runnable
|
||||||
//if player has logged out, do nothing
|
//if player has logged out, do nothing
|
||||||
if(!player.isOnline()) return;
|
if(!player.isOnline()) return;
|
||||||
|
|
||||||
|
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(this.player.getLocation().getBlock().getType() == Material.PORTAL)
|
if(playerBlock.getType() == Material.PORTAL || isInNonOccludingBlock(playerBlock))
|
||||||
{
|
{
|
||||||
this.player.teleport(this.returnLocation);
|
this.player.teleport(this.returnLocation);
|
||||||
}
|
}
|
||||||
|
|
@ -57,4 +60,28 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -759,7 +759,8 @@ class PlayerEventHandler implements Listener
|
||||||
if(returnLocation != null)
|
if(returnLocation != null)
|
||||||
{
|
{
|
||||||
PlayerEventHandler.portalReturnMap.remove(player.getUniqueId());
|
PlayerEventHandler.portalReturnMap.remove(player.getUniqueId());
|
||||||
if(player.getLocation().getBlock().getType() == Material.PORTAL)
|
Block playerBlock = player.getLocation().getBlock();
|
||||||
|
if(playerBlock.getType() == Material.PORTAL || isInNonOccludingBlock(playerBlock))
|
||||||
{
|
{
|
||||||
player.teleport(returnLocation);
|
player.teleport(returnLocation);
|
||||||
}
|
}
|
||||||
|
|
@ -782,6 +783,27 @@ 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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user