Skip to content

Commit

Permalink
Bug fix to piston protection
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam committed Jul 4, 2020
1 parent d92bc34 commit f432d28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/redempt/redlib/protection/ProtectionListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package redempt.redlib.protection;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
Expand All @@ -9,6 +11,7 @@
import redempt.redlib.misc.EventListener;
import redempt.redlib.protection.ProtectionPolicy.ProtectionType;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -65,12 +68,13 @@ protected static <T extends Event> void protectMultiBlock(Class<T> clazz, Protec
List<Block> blocks = null;
try {
blocks = func.apply(e);
} catch (Exception ex) {
} catch (NullPointerException ex) {
continue;
}
if (blocks == null) {
continue;
}
blocks = new ArrayList<>(blocks);
for (Block block : blocks) {
if (!testAll(block, type, player)) {
cancel.accept(e, block);
Expand Down
5 changes: 3 additions & 2 deletions src/redempt/redlib/protection/ProtectionPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.function.Predicate;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -70,12 +71,12 @@ public static void registerProtections() {
ProtectionListener.protect(PlayerBucketFillEvent.class, ProtectionType.USE_BUCKETS, e -> e.getPlayer(), e -> e.getBlockClicked());
ProtectionListener.protect(PlayerBucketEmptyEvent.class, ProtectionType.USE_BUCKETS, e -> e.getPlayer(), e -> e.getBlockClicked());
ProtectionListener.protectMultiBlock(BlockPistonExtendEvent.class, ProtectionType.PISTONS, e -> null, (e, b) -> e.setCancelled(true), e -> {
List<Block> blocks = e.getBlocks();
List<Block> blocks = new ArrayList<>(e.getBlocks());
blocks.add(e.getBlock());
return blocks;
});
ProtectionListener.protectMultiBlock(BlockPistonRetractEvent.class, ProtectionType.PISTONS, e -> null, (e, b) -> e.setCancelled(true), e -> {
List<Block> blocks = e.getBlocks();
List<Block> blocks = new ArrayList<>(e.getBlocks());
blocks.add(e.getBlock());
return blocks;
});
Expand Down

0 comments on commit f432d28

Please sign in to comment.