Skip to content
Permalink
Browse files

Prevent HiddenSwitch getting triggered in a few invalid angles

  • Loading branch information
me4502 committed Oct 18, 2019
1 parent 14069ba commit 6c24357ed8159183b93cb9d651cc4a340b804847
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/main/java/com/sk89q/craftbook/mechanics/HiddenSwitch.java
@@ -8,6 +8,7 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.type.WallSign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -62,18 +63,17 @@ public boolean testBlock(Block switchBlock, BlockFace eventFace, Player player)
ChangedSign s = null;
Block testBlock = null;
if(anyside) {

for(BlockFace face : LocationUtil.getDirectFaces()) {
testBlock = switchBlock.getRelative(face);
if(SignUtil.isWallSign(testBlock)) {
if(SignUtil.isWallSign(testBlock) && ((WallSign) testBlock.getBlockData()).getFacing() == face) {
s = CraftBookBukkitUtil.toChangedSign(testBlock);
break;
}
}
} else {
BlockFace face = eventFace.getOppositeFace();
testBlock = switchBlock.getRelative(face);
if(SignUtil.isWallSign(testBlock)) {
if(SignUtil.isWallSign(testBlock) && ((WallSign) testBlock.getBlockData()).getFacing() == face) {
s = CraftBookBukkitUtil.toChangedSign(testBlock);
}
}
@@ -136,7 +136,10 @@ public void onRightClick(PlayerInteractEvent event) {
if(!player.hasPermission("craftbook.mech.hiddenswitch.use"))
return;

if (!isValidWallSign(event.getClickedBlock().getRelative(1, 0, 0)) && !isValidWallSign(event.getClickedBlock().getRelative(-1, 0, 0)) && !isValidWallSign(event.getClickedBlock().getRelative(0, 0, 1)) && !isValidWallSign(event.getClickedBlock().getRelative(0, 0, -1)))
if (!isValidWallSign(event.getClickedBlock().getRelative(1, 0, 0))
&& !isValidWallSign(event.getClickedBlock().getRelative(-1, 0, 0))
&& !isValidWallSign(event.getClickedBlock().getRelative(0, 0, 1))
&& !isValidWallSign(event.getClickedBlock().getRelative(0, 0, -1)))
return;

if(!ProtectionUtil.canUse(event.getPlayer(), event.getClickedBlock().getLocation(), event.getBlockFace(), event.getAction()))

0 comments on commit 6c24357

Please sign in to comment.
You can’t perform that action at this time.