Java Code Examples for com.griefcraft.lwc.LWC#canAccessProtection()
The following examples show how to use
com.griefcraft.lwc.LWC#canAccessProtection() .
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 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 2
Source File: LWCPlayerListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler public void minecartBreak(VehicleDestroyEvent e) { Entity entity = e.getVehicle(); if (plugin.getLWC().isProtectable(e.getVehicle().getType())) { int A = 50000 + entity.getUniqueId().hashCode(); LWC lwc = LWC.getInstance(); Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A); if ((((entity instanceof StorageMinecart)) || ((entity instanceof HopperMinecart))) && (protection != null)) { if (e.getAttacker() instanceof Projectile) { e.setCancelled(true); } Player p = (Player) e.getAttacker(); boolean canAccess = lwc.canAccessProtection(p, protection); if (canAccess) { protection.remove(); protection.removeAllPermissions(); protection.removeCache(); return; } e.setCancelled(true); } } }
Example 3
Source File: LWCPlayerListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerArmorStandManipulate(PlayerArmorStandManipulateEvent e) { Entity entity = e.getRightClicked(); if (plugin.getLWC().isProtectable(e.getRightClicked().getType())) { int A = 50000 + entity.getUniqueId().hashCode(); LWC lwc = LWC.getInstance(); Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A); Player p = e.getPlayer(); boolean canAccess = lwc.canAccessProtection(p, protection); if (onPlayerEntityInteract(p, entity, e.isCancelled())) { e.setCancelled(true); } if (protection != null) { if (canAccess) return; e.setCancelled(true); } } }
Example 4
Source File: RedstoneModule.java From Modern-LWC with MIT License | 5 votes |
@Override public void onRedstone(LWCRedstoneEvent event) { if (event.isCancelled()) { return; } LWC lwc = event.getLWC(); Protection protection = event.getProtection(); // check for a player using it ProtectionFinder finder = protection.getProtectionFinder(); if (finder != null) { for (BlockState found : finder.getBlocks()) { if (DoorMatcher.PRESSURE_PLATES.contains(found.getType())) { // find a player that is using it int x = found.getX(); int y = found.getY(); int z = found.getZ(); Player player = lwc.findPlayer(x - 1, x + 1, y, y + 1, z - 1, z + 1); if (player != null) { if (!lwc.canAccessProtection(player, protection)) { event.setCancelled(true); } else { // bypass the denyRedstone/REDSTONE flag check return; } } } } } boolean hasFlag = protection.hasFlag(Flag.Type.REDSTONE); boolean denyRedstone = lwc.getConfiguration().getBoolean("protections.denyRedstone", false); if ((!hasFlag && denyRedstone) || (hasFlag && !denyRedstone)) { event.setCancelled(true); } }
Example 5
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 6
Source File: LWCPlayerListener.java From Modern-LWC with MIT License | 5 votes |
@EventHandler public void hangingBreakByEvent(HangingBreakByEntityEvent event) { Entity entity = event.getEntity(); if (plugin.getLWC().isProtectable(event.getEntity().getType())) { int A = 50000 + entity.getUniqueId().hashCode(); LWC lwc = LWC.getInstance(); Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A); if (event.getRemover() instanceof Projectile && protection != null) { event.setCancelled(true); } if (event.getRemover() instanceof Player) { Player p = (Player) event.getRemover(); if (p.hasPermission("lwc.lockentity." + entity.getType()) || p.hasPermission("lwc.lockentity.all")) { if (onPlayerEntityInteract(p, entity, event.isCancelled())) { event.setCancelled(true); } } if (!event.isCancelled() && protection != null) { boolean canAccess = lwc.canAccessProtection(p, protection); if (canAccess) { protection.remove(); protection.removeAllPermissions(); protection.removeCache(); return; } event.setCancelled(true); } } } }
Example 7
Source File: LWCPlayerListener.java From Modern-LWC with MIT License | 5 votes |
@EventHandler public void itemFrameItemRemoval(EntityDamageByEntityEvent e) { if (e.isCancelled()) return; Entity entity = e.getEntity(); if (plugin.getLWC().isProtectable(e.getEntity().getType())) { int A = 50000 + entity.getUniqueId().hashCode(); LWC lwc = LWC.getInstance(); Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A); if (!(entity instanceof Player)) { if (e.getDamager() instanceof Projectile) { if (protection != null) { e.setCancelled(true); } if ((((entity instanceof StorageMinecart)) || ((entity instanceof HopperMinecart))) && (protection != null)) { e.setCancelled(true); } } if (e.getDamager() instanceof Player) { Player p = (Player) e.getDamager(); if (protection != null && !lwc.canAccessProtection(p, protection)) { e.setCancelled(true); } if (p.hasPermission("lwc.lockentity." + e.getEntityType()) || p.hasPermission("lwc.lockentity.all")) { if (onPlayerEntityInteract(p, entity, e.isCancelled())) { e.setCancelled(true); } } if ((((entity instanceof StorageMinecart)) || ((entity instanceof HopperMinecart))) && (protection != null)) { e.setCancelled(true); } } } } }
Example 8
Source File: LWCPlayerListener.java From Modern-LWC with MIT License | 5 votes |
@EventHandler public void onDeath(EntityDeathEvent e) { Entity entity = e.getEntity(); if (plugin.getLWC().isProtectable(e.getEntity().getType())) { int A = 50000 + entity.getUniqueId().hashCode(); Player player = e.getEntity().getKiller(); LWC lwc = LWC.getInstance(); Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A); if (protection != null) { boolean canAccess = lwc.canAccessProtection(player, protection); boolean canAdmin = lwc.canAdminProtection(player, protection); try { if (player != null) { LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection, LWCProtectionDestroyEvent.Method.ENTITY_DESTRUCTION, canAccess, canAdmin); lwc.getModuleLoader().dispatchEvent(evt); } else { protection.remove(); protection.removeAllPermissions(); protection.removeCache(); } } catch (Exception ex) { if (player != null) { lwc.sendLocale(player, "protection.internalerror", "id", "ENTITY_DEATH"); } lwc.sendLocale(Bukkit.getServer().getConsoleSender(), "protection.internalerror", "id", "ENTITY_DEATH"); ex.printStackTrace(); } } } }
Example 9
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 10
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); } } }*/ } } }