Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 2 contributors
Commits on Jun 23, 2012
@JonnyD JonnyD Update master ca56875
@Exultant Merge pull request #38 from JonnyD/master
Just realized I didn't commit the latest version of the piston bug fix.
9103cc3
Showing with 49 additions and 77 deletions.
  1. +49 −77 src/com/untamedears/citadel/listener/BlockListener.java
View
126 src/com/untamedears/citadel/listener/BlockListener.java
@@ -94,87 +94,59 @@ public void blockBreak(BlockBreakEvent bbe) {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void pistonExtend(BlockPistonExtendEvent bpee) {
Block piston = bpee.getBlock();
- BlockState state = piston.getState();
- MaterialData data = state.getData();
- BlockFace direction = null;
-
- // Check the block it pushed directly
- if (data instanceof PistonBaseMaterial) {
- direction = ((PistonBaseMaterial) data).getFacing();
- Block block = bpee.getBlock().getRelative(direction);
-
- // Get the bottom half of the door
- if(block.getType() == Material.WOODEN_DOOR || block.getType() == Material.IRON_DOOR){
- Door door = (Door) block.getState().getData();
- if(door.isTopHalf()){
- Location reinforcedPart = new Location(block.getWorld(), block.getX(), block.getY() - 1, block.getZ());
- block = reinforcedPart.getBlock();
- }
- }
-
- Reinforcement reinforcement = plugin.dao.findReinforcement(block);
-
- if (reinforcement != null) {
- bpee.setCancelled(true);
- return;
- }
- }
-
- // if no direction was found, no point in going on
- if (direction == null) return;
-
- // Check the affected blocks
- for (int i = 0; i < bpee.getLength() + 2; i++) {
- Block block = piston.getRelative(direction, i);
-
- if (block.getType() == Material.AIR) break;
-
- // Get the bottom half of the door because bottom half
- // is the part that's stored in the database as reinforced
- if(block.getType() == Material.WOODEN_DOOR || block.getType() == Material.IRON_DOOR){
- Door door = (Door) block.getState().getData();
- if(door.isTopHalf()){
- Location reinforcedPart = new Location(block.getWorld(), block.getX(), block.getY() - 1, block.getZ());
- block = reinforcedPart.getBlock();
- }
- }
-
- Reinforcement reinforcement = plugin.dao.findReinforcement(block);
- if (reinforcement != null) {
- bpee.setCancelled(true);
- break;
- }
- }
+ BlockState state = piston.getState();
+ MaterialData data = state.getData();
+ BlockFace direction = null;
+
+ if (data instanceof PistonBaseMaterial) {
+ direction = ((PistonBaseMaterial) data).getFacing();
+ }
+
+ // if no direction was found, no point in going on
+ if (direction == null)
+ return;
+
+ // Check the affected blocks
+ for (int i = 1; i < bpee.getLength() + 2; i++) {
+ Block block = piston.getRelative(direction, i);
+
+ if (block.getType() == Material.AIR)
+ break;
+
+ AccessDelegate delegate = AccessDelegate.getDelegate(block);
+ Reinforcement reinforcement = delegate.getReinforcement();
+
+ if (reinforcement != null){
+ bpee.setCancelled(true);
+ break;
+ }
+ }
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void pistonRetract(BlockPistonRetractEvent bpre) {
- Block piston = bpre.getBlock();
- BlockState state = piston.getState();
- MaterialData data = state.getData();
- BlockFace direction = null;
-
- // Check the block it pushed directly
- if (data instanceof PistonBaseMaterial) {
- direction = ((PistonBaseMaterial) data).getFacing();
- }
-
- if (direction == null) return;
-
- // the block that the piston moved
- Block moved = piston.getRelative(direction, 2);
- if (moved.getType() == Material.WOODEN_DOOR || moved.getType() == Material.IRON_DOOR_BLOCK) {
- Block below = moved.getRelative(BlockFace.DOWN).getRelative(direction.getOppositeFace());
-
- if (plugin.dao.findReinforcement(below) != null) {
- bpre.setCancelled(true);
- return;
- }
- }
-
- if (plugin.dao.findReinforcement(moved) != null) {
- bpre.setCancelled(true);
- }
+ Block piston = bpre.getBlock();
+ BlockState state = piston.getState();
+ MaterialData data = state.getData();
+ BlockFace direction = null;
+
+ // Check the block it pushed directly
+ if (data instanceof PistonBaseMaterial) {
+ direction = ((PistonBaseMaterial) data).getFacing();
+ }
+
+ if (direction == null)
+ return;
+
+ // the block that the piston moved
+ Block moved = piston.getRelative(direction, 2);
+
+ AccessDelegate delegate = AccessDelegate.getDelegate(moved);
+ Reinforcement reinforcement = delegate.getReinforcement();
+
+ if (reinforcement != null) {
+ bpre.setCancelled(true);
+ }
}
private static final Material matfire = Material.FIRE;

No commit comments for this range

Something went wrong with that request. Please try again.