Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler
- public void onBlockBreak(BlockBreakEvent event) {
- if (!LWC.ENABLED || event.isCancelled()) {
- return;
- }
- LWC lwc = plugin.getLWC();
- Player player = event.getPlayer();
- Block block = event.getBlock();
- boolean ignoreBlockDestruction = Boolean
- .parseBoolean(lwc.resolveProtectionConfiguration(block, "ignoreBlockDestruction"));
- if (ignoreBlockDestruction) {
- return;
- }
- ProtectionCache cache = lwc.getProtectionCache();
- String cacheKey = cache.cacheKey(block.getLocation());
- // In the event they place a block, remove any known nulls there
- if (cache.isKnownNull(cacheKey)) {
- cache.remove(cacheKey);
- }
- Protection protection = lwc.findProtection(block.getLocation());
- if (protection == null) {
- return;
- }
- boolean canAccess = lwc.canAccessProtection(player, protection);
- boolean canAdmin = lwc.canAdminProtection(player, protection);
- // when destroying a chest, it's possible they are also destroying a
- // double chest
- // in the event they're trying to destroy a double chest, we should just
- // move
- // the protection to the chest that is not destroyed, if it is not that
- // one already.
- if (protection.isOwner(player) && DoubleChestMatcher.PROTECTABLES_CHESTS.contains(block.getType())) {
- Block doubleChest = lwc.findAdjacentDoubleChest(block);
- if (doubleChest != null) {
- // if they destroyed the protected block we want to move it aye?
- if (lwc.blockEquals(protection.getBlock(), block)) {
- // correct the block
- BlockCache blockCache = BlockCache.getInstance();
- protection.setBlockId(blockCache.getBlockId(doubleChest));
- protection.setX(doubleChest.getX());
- protection.setY(doubleChest.getY());
- protection.setZ(doubleChest.getZ());
- protection.saveNow();
- }
- // Repair the cache
- protection.radiusRemoveCache();
- if (protection.getProtectionFinder() != null) {
- protection.getProtectionFinder().removeBlock(block.getState());
- }
- lwc.getProtectionCache().addProtection(protection);
- return;
- }
- }
- try {
- LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection,
- LWCProtectionDestroyEvent.Method.BLOCK_DESTRUCTION, canAccess, canAdmin);
- lwc.getModuleLoader().dispatchEvent(evt);
- if ((evt.isCancelled() || !canAccess) && !plugin.getLWC().hasPermission(player, "lwc.force.destroy.block")) {
- event.setCancelled(true);
- }
- } catch (Exception e) {
- event.setCancelled(true);
- lwc.sendLocale(player, "protection.internalerror", "id", "BLOCK_BREAK");
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement