Cancels explosions near permission signs
This commit is contained in:
parent
0e8f2bd066
commit
69d182ec10
@ -10,10 +10,13 @@ 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.block.data.type.WallSign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.block.BlockExplodeEvent;
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -33,6 +36,16 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockExplode(BlockExplodeEvent event) {
|
||||||
|
preventExplosion(event.blockList(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
|
preventExplosion(event.blockList(), event);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
@ -54,6 +67,26 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevents explosions from destroying permission signs
|
||||||
|
*
|
||||||
|
* @param blocks <p>The blocks affected by the explosion</p>
|
||||||
|
* @param event <p>The explosion event to cancel if a permission sign is found</p>
|
||||||
|
*/
|
||||||
|
private void preventExplosion(List<Block> blocks, Cancellable event) {
|
||||||
|
for (Block block : blocks) {
|
||||||
|
if (!Tag.SIGNS.isTagged(block.getBlockData().getMaterial())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Sign sign = (Sign) block.getState();
|
||||||
|
boolean registered = SignManager.getSign(sign.getLocation()) != null;
|
||||||
|
if (registered) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protects signs on falling blocks in the given direction
|
* Protects signs on falling blocks in the given direction
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user