Java Code Examples for com.griefcraft.lwc.LWC#ENABLED
The following examples show how to use
com.griefcraft.lwc.LWC#ENABLED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler public void onBlockRedstoneChange(BlockRedstoneEvent event) { if (!LWC.ENABLED) { return; } LWC lwc = plugin.getLWC(); Block block = event.getBlock(); if (block == null) { return; } Protection protection = lwc.findProtection(block.getLocation()); if (protection == null) { return; } LWCRedstoneEvent evt = new LWCRedstoneEvent(event, protection); lwc.getModuleLoader().dispatchEvent(evt); if (evt.isCancelled()) { event.setNewCurrent(event.getOldCurrent()); } }
Example 2
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler public void onStructureGrow(StructureGrowEvent event) { if (!LWC.ENABLED) { return; } LWC lwc = LWC.getInstance(); // the blocks that were changed / replaced List<BlockState> blocks = event.getBlocks(); for (BlockState block : blocks) { if (!lwc.isProtectable(block.getBlock())) { continue; } // we don't have the block id of the block before it // so we have to do some raw lookups (these are usually cache hits // however, at least!) Protection protection = lwc.getPhysicalDatabase().loadProtection(block.getWorld().getName(), block.getX(), block.getY(), block.getZ()); if (protection != null) { event.setCancelled(true); } } }
Example 3
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityChangeBlock(EntityChangeBlockEvent event) { if (!LWC.ENABLED) { return; } LWC lwc = LWC.getInstance(); Block block = event.getBlock(); if (!lwc.isProtectable(block)) { return; } Protection protection = lwc.findProtection(block); if (protection != null) { event.setCancelled(true); } }
Example 4
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler public void onSignChange(SignChangeEvent event) { if (!LWC.ENABLED || event.isCancelled()) { return; } LWC lwc = plugin.getLWC(); Block block = event.getBlock(); Player player = event.getPlayer(); if (block == null) { return; } Protection protection = lwc.findProtection(block.getLocation()); if (protection == null) { return; } boolean canAccess = lwc.canAccessProtection(player, protection); if (!canAccess) { event.setCancelled(true); } }
Example 5
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGH) public void onBlockExplode(BlockExplodeEvent event) { if (!LWC.ENABLED || event.isCancelled()) { return; } LWC lwc = plugin.getLWC(); for (Block block : event.blockList()) { Protection protection = plugin.getLWC().findProtection(block.getLocation()); if (protection != null) { boolean ignoreExplosions = Boolean .parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "ignoreExplosions")); if (!(ignoreExplosions || protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS))) { event.setCancelled(true); } } } }
Example 6
Source File: LWCEntityListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGH) public void onEntityExplode(EntityExplodeEvent event) { if (!LWC.ENABLED || event.isCancelled()) { return; } LWC lwc = LWC.getInstance(); for (Block block : event.blockList()) { Protection protection = plugin.getLWC().findProtection(block.getLocation()); if (protection != null) { boolean ignoreExplosions = Boolean .parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "ignoreExplosions")); if (!(ignoreExplosions || protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS))) { event.setCancelled(true); } } } }
Example 7
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 5 votes |
@EventHandler public void onBlockPistonRetract(BlockPistonRetractEvent event) { if ((!LWC.ENABLED) || (event.isCancelled())) { return; } LWC lwc = this.plugin.getLWC(); for (Block block : event.getBlocks()) { Protection protection = lwc.findProtection(block); if (protection != null) { event.setCancelled(true); return; } } }
Example 8
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 5 votes |
@EventHandler public void onBlockPistonExtend(BlockPistonExtendEvent event) { if (!LWC.ENABLED || event.isCancelled()) { return; } LWC lwc = this.plugin.getLWC(); for (Block block : event.getBlocks()) { Protection protection = lwc.findProtection(block); if (protection != null) { event.setCancelled(true); return; } } }
Example 9
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 5 votes |
@SuppressWarnings("deprecation") @EventHandler(ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { if (!LWC.ENABLED) { return; } LWC lwc = plugin.getLWC(); Player player = event.getPlayer(); Block block = event.getBlockPlaced(); 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); } // check if the block is blacklisted if (blacklistedBlocks.contains(block.getType())) { // it's blacklisted, check for a protected chest for (Protection protection : lwc.findAdjacentProtectionsOnAllSides(block)) { if (protection != null) { if (!lwc.canAccessProtection(player, protection) || (protection.getType() == Protection.Type.DONATION && !lwc.canAdminProtection(player, protection))) { // they can't access the protection .. event.setCancelled(true); return; } } } } }
Example 10
Source File: LWCServerListener.java From Modern-LWC with MIT License | 5 votes |
@EventHandler public void onPluginDisable(PluginDisableEvent event) { if (!LWC.ENABLED) { return; } Plugin disabled = event.getPlugin(); // Removes any modules registered by the disabled plugin plugin.getLWC().getModuleLoader().removeModules(disabled); }
Example 11
Source File: LWCPlayerListener.java From Modern-LWC with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onPlayerDropItem(PlayerDropItemEvent event) { if (event.isCancelled() || !LWC.ENABLED) { return; } Player player = event.getPlayer(); LWCDropItemEvent evt = new LWCDropItemEvent(player, event); plugin.getLWC().getModuleLoader().dispatchEvent(evt); if (evt.isCancelled()) { event.setCancelled(true); } }
Example 12
Source File: LWCPlayerListener.java From Modern-LWC with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerQuit(PlayerQuitEvent event) { if (!LWC.ENABLED) { return; } // remove the place from the player cache and reset anything they can // access LWCPlayer.removePlayer(event.getPlayer()); }
Example 13
Source File: CreditsModule.java From Modern-LWC with MIT License | 4 votes |
public void run() { while (LWC.ENABLED) { synchronized (scrolling) { Iterator<Map.Entry<CommandSender, Integer>> iter = scrolling.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<CommandSender, Integer> entry = iter.next(); CommandSender sender = entry.getKey(); int index = entry.getValue(); // Done! if (index >= credits.length) { iter.remove(); continue; } // if they're a player, and not online, don't send if ((sender instanceof Player) && !((Player) sender).isOnline()) { iter.remove(); continue; } // if it's 0, we should bulk send the first few if (index == 0) { for (int i = 0; i < FIRST_SEND; i++) { if (index >= credits.length) { break; } sender.sendMessage(credits[index]); index++; } } else { sender.sendMessage(credits[index]); index++; } // update the index entry.setValue(index); } } try { Thread.sleep(UPDATE_INTERVAL); } catch (Exception e) { } } }
Example 14
Source File: LWCBlockListener.java From Modern-LWC with MIT License | 4 votes |
@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) { event.setCancelled(true); } } catch (Exception e) { event.setCancelled(true); lwc.sendLocale(player, "protection.internalerror", "id", "BLOCK_BREAK"); e.printStackTrace(); } }
Example 15
Source File: LWCEntityListener.java From Modern-LWC with MIT License | 4 votes |
@EventHandler(ignoreCancelled = true) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (!LWC.ENABLED || event.isCancelled()) { return; } LWC lwc = plugin.getLWC(); if (event.getDamager() instanceof Player) { Player player = (Player) event.getDamager(); Entity entity = event.getEntity(); EntityBlock entityBlock = new EntityBlock(entity); boolean ignoreBlockDestruction = Boolean .parseBoolean(lwc.resolveProtectionConfiguration(entityBlock, "ignoreBlockDestruction")); if (ignoreBlockDestruction) { return; } if (event.getEntityType().equals(EntityType.ARMOR_STAND)) { if (event.getDamage() < 1.0 || ((Player) event.getDamager()).getGameMode().equals(GameMode.CREATIVE)) { // Armor Stand Broke ProtectionCache cache = lwc.getProtectionCache(); String cacheKey = cache.cacheKey(entityBlock.getLocation()); // In the event they place a block, remove any known nulls there if (cache.isKnownNull(cacheKey)) { cache.remove(cacheKey); } Protection protection = lwc.findProtection(entityBlock); if (protection == null) { return; } boolean canAccess = lwc.canAccessProtection(player, protection); boolean canAdmin = lwc.canAdminProtection(player, protection); try { // Removing protection LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection, LWCProtectionDestroyEvent.Method.ENTITY_DESTRUCTION, canAccess, canAdmin); lwc.getModuleLoader().dispatchEvent(evt); protection.remove(); protection.removeAllPermissions(); protection.removeCache(); if (evt.isCancelled() || !canAccess) { event.setCancelled(true); } } catch (Exception e) { event.setCancelled(true); lwc.sendLocale(player, "protection.internalerror", "id", "BLOCK_BREAK"); e.printStackTrace(); } } /*else { // Armor Stand Punched LWC.getInstance().log("Armor Stand Punched"); if(plugin.getLWC().isProtectable(entity.getType())){ int A = 50000 + entity.getUniqueId().hashCode(); Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A); boolean canAccess = lwc.canAccessProtection(player, protection); boolean canAdmin = lwc.canAdminProtection(player, protection); Set<String> actions = lwc.wrapPlayer(player).getActionNames(); Module.Result result = Module.Result.CANCEL; // TODO: Finish this implementation if (protection != null) { LWCEntityDamageByEntityEvent evt = new LWCEntityDamageByEntityEvent(event, protection, actions, canAccess, canAdmin); lwc.getModuleLoader().dispatchEvent(evt); result = evt.getResult(); } else { } if (result == Module.Result.ALLOW) { return; } if (player.hasPermission("lwc.lockentity." + entity.getType()) || player.hasPermission("lwc.lockentity.all")) { if (onPlayerEntityInteract(p, entity, e.isCancelled())) { chunkUnload(entity.getWorld().getName(), A); e.setCancelled(true); } } if (protection != null) { if (canAccess) return; e.setCancelled(true); } } }*/ } } }