Fixes several bugs in sign protection
This commit is contained in:
parent
6705d2e4b1
commit
9188fd1b96
@ -8,6 +8,7 @@ import org.bukkit.Tag;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.block.data.type.WallSign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -15,9 +16,7 @@ import org.bukkit.event.block.BlockBreakEvent;
|
|||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static net.knarcraft.permissionsigns.PermissionSigns.extensiveSignProtectionEnabled;
|
import static net.knarcraft.permissionsigns.PermissionSigns.extensiveSignProtectionEnabled;
|
||||||
|
|
||||||
@ -64,16 +63,16 @@ public class BlockListener implements Listener {
|
|||||||
* @param direction <p>The direction to check for affected blocks</p>
|
* @param direction <p>The direction to check for affected blocks</p>
|
||||||
*/
|
*/
|
||||||
private void protectSignsInDirection(BlockBreakEvent event, Block block, Player player, BlockFace direction) {
|
private void protectSignsInDirection(BlockBreakEvent event, Block block, Player player, BlockFace direction) {
|
||||||
Block directionBlock = block;
|
Block directionBlock = block.getRelative(direction);
|
||||||
do {
|
while ((direction == BlockFace.DOWN && directionBlock.getBlockData().getMaterial() ==
|
||||||
directionBlock = directionBlock.getRelative(direction);
|
Material.POINTED_DRIPSTONE) || (direction == BlockFace.UP &&
|
||||||
|
isAffectedByGravity(directionBlock.getBlockData().getMaterial()))) {
|
||||||
protectBlockIfPermissionSign(event, directionBlock, player);
|
protectBlockIfPermissionSign(event, directionBlock, player);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} while ((direction == BlockFace.DOWN && directionBlock.getBlockData().getMaterial() ==
|
directionBlock = directionBlock.getRelative(direction);
|
||||||
Material.POINTED_DRIPSTONE) || (direction == BlockFace.UP &&
|
}
|
||||||
isAffectedByGravity(directionBlock.getBlockData().getMaterial())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,28 +85,38 @@ public class BlockListener implements Listener {
|
|||||||
private void protectBlockIfPermissionSign(BlockBreakEvent event, Block block, Player player) {
|
private void protectBlockIfPermissionSign(BlockBreakEvent event, Block block, Player player) {
|
||||||
//Protect the permission sign itself
|
//Protect the permission sign itself
|
||||||
Material material = block.getBlockData().getMaterial();
|
Material material = block.getBlockData().getMaterial();
|
||||||
if (Tag.SIGNS.isTagged(material) || Tag.WALL_SIGNS.isTagged(material)) {
|
if (Tag.SIGNS.isTagged(material)) {
|
||||||
checkIfBlockIsPermissionSign(block, player, event);
|
checkIfBlockIsPermissionSign(block, player, event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Block, Tag<Material>> blocksToCheck = new HashMap<>();
|
lookForAdjacentPermissionSigns(event, block, player);
|
||||||
|
}
|
||||||
|
|
||||||
//Protect any block with a permission sign on it
|
/**
|
||||||
blocksToCheck.put(block.getRelative(BlockFace.UP), Tag.SIGNS);
|
* Looks for permission signs adjacent to the current block
|
||||||
|
*
|
||||||
|
* @param event <p>The triggered block break event</p>
|
||||||
|
* @param block <p>The block to check if it's a sign</p>
|
||||||
|
* @param player <p>The player breaking the block</p>
|
||||||
|
*/
|
||||||
|
private void lookForAdjacentPermissionSigns(BlockBreakEvent event, Block block, Player player) {
|
||||||
|
Block aboveBlock = block.getRelative(BlockFace.UP);
|
||||||
|
if (Tag.STANDING_SIGNS.isTagged(aboveBlock.getBlockData().getMaterial())) {
|
||||||
|
checkIfBlockIsPermissionSign(aboveBlock, player, event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Protect any permission signs attached to the block
|
//Check for any wall permission signs that may be broken by breaking the block
|
||||||
for (BlockFace blockFace : getRelevantBlockFaces()) {
|
for (BlockFace blockFace : getRelevantBlockFaces()) {
|
||||||
if (!(Tag.WALL_SIGNS.isTagged(block.getBlockData().getMaterial()))) {
|
Block adjacentBlock = block.getRelative(blockFace);
|
||||||
blocksToCheck.put(block.getRelative(blockFace), Tag.WALL_SIGNS);
|
if (Tag.WALL_SIGNS.isTagged(adjacentBlock.getBlockData().getMaterial()) &&
|
||||||
}
|
blockFace == ((WallSign) adjacentBlock.getBlockData()).getFacing()) {
|
||||||
}
|
checkIfBlockIsPermissionSign(adjacentBlock, player, event);
|
||||||
|
|
||||||
for (Block blockToCheck : blocksToCheck.keySet()) {
|
|
||||||
if (blocksToCheck.get(blockToCheck).isTagged(blockToCheck.getBlockData().getMaterial())) {
|
|
||||||
checkIfBlockIsPermissionSign(blockToCheck, player, event);
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -165,7 +174,7 @@ public class BlockListener implements Listener {
|
|||||||
private boolean isAffectedByGravity(Material material) {
|
private boolean isAffectedByGravity(Material material) {
|
||||||
//TODO: Find a better way of deciding which blocks are affected by gravity
|
//TODO: Find a better way of deciding which blocks are affected by gravity
|
||||||
return Tag.SAND.isTagged(material) || Tag.ANVIL.isTagged(material) || material == Material.POINTED_DRIPSTONE ||
|
return Tag.SAND.isTagged(material) || Tag.ANVIL.isTagged(material) || material == Material.POINTED_DRIPSTONE ||
|
||||||
Tag.SIGNS.isTagged(material) || material == Material.DRAGON_EGG || material == Material.GRAVEL ||
|
Tag.STANDING_SIGNS.isTagged(material) || material == Material.DRAGON_EGG || material == Material.GRAVEL ||
|
||||||
material == Material.BLACK_CONCRETE_POWDER || material == Material.BLUE_CONCRETE_POWDER ||
|
material == Material.BLACK_CONCRETE_POWDER || material == Material.BLUE_CONCRETE_POWDER ||
|
||||||
material == Material.BROWN_CONCRETE_POWDER || material == Material.CYAN_CONCRETE_POWDER ||
|
material == Material.BROWN_CONCRETE_POWDER || material == Material.CYAN_CONCRETE_POWDER ||
|
||||||
material == Material.LIME_CONCRETE_POWDER || material == Material.GRAY_CONCRETE_POWDER ||
|
material == Material.LIME_CONCRETE_POWDER || material == Material.GRAY_CONCRETE_POWDER ||
|
||||||
|
@ -45,7 +45,7 @@ public class SignListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Material material = block.getBlockData().getMaterial();
|
Material material = block.getBlockData().getMaterial();
|
||||||
if (!Tag.SIGNS.isTagged(material) && !Tag.WALL_SIGNS.isTagged(material)) {
|
if (!Tag.SIGNS.isTagged(material)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user