Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Openable;
import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.type.Door;
import org.bukkit.block.data.type.Switch;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -101,18 +102,18 @@ public void pressButton(PlayerInteractEvent e) {
// needs special handling because buttons attached to ceiling and ground can be
// turned in which case the facing direction indicates this direction
switch (button.getAttachedFace()) {
case CEILING:
attachedBlock = e.getClickedBlock().getRelative(BlockFace.UP);
break;
case FLOOR:
attachedBlock = e.getClickedBlock().getRelative(BlockFace.DOWN);
break;
case WALL:
attachedBlock = e.getClickedBlock().getRelative(button.getFacing().getOppositeFace());
break;
default:
Citadel.getInstance().getLogger().warning("Could not handle button face " + button.getAttachedFace());
return;
case CEILING:
attachedBlock = e.getClickedBlock().getRelative(BlockFace.UP);
break;
case FLOOR:
attachedBlock = e.getClickedBlock().getRelative(BlockFace.DOWN);
break;
case WALL:
attachedBlock = e.getClickedBlock().getRelative(button.getFacing().getOppositeFace());
break;
default:
Citadel.getInstance().getLogger().warning("Could not handle button face " + button.getAttachedFace());
return;
}
// prepare all sides of button itself
setupAdjacentDoors(e.getPlayer(), buttonBlock, button.getFacing().getOppositeFace());
Expand All @@ -122,19 +123,25 @@ public void pressButton(PlayerInteractEvent e) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void redstonePower(BlockRedstoneEvent bre) {
// prevent doors from being opened by redstone
if (bre.getNewCurrent() <= 0 || bre.getOldCurrent() > 0) {
return;
}
// prevent doors from being opened or closed by redstone
Block block = bre.getBlock();
BlockData blockData = block.getBlockData();
if (!(blockData instanceof Openable)) {
if (!(blockData instanceof Openable openable)) {
return;
}
Openable openable = (Openable) blockData;
if (openable.isOpen()) {

if (openable.isOpen() && bre.getOldCurrent() <= 0
|| !openable.isOpen() && bre.getOldCurrent() > 0
) {
return;
}

if (!hasDoorAccess(block, blockData, openable.isOpen())) {
bre.setNewCurrent(bre.getOldCurrent());
}
}

private boolean hasDoorAccess(Block block, BlockData blockData, boolean isInsecure) {
if (blockData instanceof Door) {
// we always store the activation for the lower half of a door
Door door = (Door) blockData;
Expand All @@ -144,28 +151,22 @@ public void redstonePower(BlockRedstoneEvent bre) {
}
Reinforcement rein = ReinforcementLogic.getReinforcementProtecting(block);
if (rein == null) {
return;
return true;
}
if (rein.isInsecure()) {
boolean playerNearby = isAuthorizedPlayerNear(rein, maxRedstoneDistance);
if (!playerNearby) {
bre.setNewCurrent(bre.getOldCurrent());
}
return;
if (isInsecure || rein.isInsecure()) {
return isAuthorizedPlayerNear(rein, maxRedstoneDistance);
}
List<UUID> playersActivating = authorizations.get(block.getLocation());
if (playersActivating == null) {
bre.setNewCurrent(bre.getOldCurrent());
return;
return false;
}
for (UUID uuid : playersActivating) {
if (rein.hasPermission(uuid, CitadelPermissionHandler.getDoors())) {
// single valid perm is enough to open
return;
return true;
}
}
// noone valid found nearby, so deny
bre.setNewCurrent(bre.getOldCurrent());
return false;
}

private void setupAdjacentDoors(Player player, Block block, BlockFace skip) {
Expand Down Expand Up @@ -212,7 +213,7 @@ public void playerStepPressurePlate(PlayerInteractEvent e) {

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void entityStepPressurePlate(EntityInteractEvent e) {
if (!(e.getEntity() instanceof Vehicle)){
if (!(e.getEntity() instanceof Vehicle)) {
return;
}
Material mat = e.getBlock().getType();
Expand All @@ -226,5 +227,4 @@ public void entityStepPressurePlate(EntityInteractEvent e) {
}
}
}

}