Java Code Examples for com.griefcraft.model.Protection#remove()
The following examples show how to use
com.griefcraft.model.Protection#remove() .
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: Towny.java From Modern-LWC with MIT License | 6 votes |
public void unclaimTowny(TownUnclaimEvent event) throws NotRegisteredException, TownyException { if (towny == null) { return; } List<WorldCoord> wcl = AreaSelectionUtil.selectWorldCoordArea(event.getTown(), event.getWorldCoord(), new String[]{"auto"}); wcl = AreaSelectionUtil.filterOwnedBlocks(event.getTown(), wcl); for (WorldCoord wc : wcl) { PlotBlockData pbd = new PlotBlockData(wc.getTownBlock()); for (int z = 0; z < pbd.getSize(); z++) for (int x = 0; x < pbd.getSize(); x++) for (int y = pbd.getHeight(); y > 0; y--) { Block b = event.getWorldCoord().getBukkitWorld().getBlockAt((pbd.getX() * pbd.getSize()) + x, y, (pbd.getZ() * pbd.getSize()) + z); LWC lwc = LWC.getInstance(); Protection protection = lwc.getPhysicalDatabase() .loadProtection(event.getWorldCoord().getWorldName(), b.getX(), b.getY(), b.getZ()); if (protection != null) { protection.remove(); } } } }
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: PhysDB.java From Modern-LWC with MIT License | 5 votes |
/** * Remove all protections for a given player * * @param player * @return the amount of protections removed */ public int removeProtectionsByPlayer(String player) { int removed = 0; for (Protection protection : loadProtectionsByPlayer(player)) { protection.remove(); removed++; } return removed; }
Example 4
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 5
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 6
Source File: LWCUtil.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
public static void removeProtection(Block block) { if (!isLWCLoaded()) { return; } Protection protection = LWC.getInstance().getProtectionCache().getProtection(block); if (protection != null) { protection.remove(); } }
Example 7
Source File: AdminRemove.java From Modern-LWC with MIT License | 4 votes |
@Override public void onCommand(LWCCommandEvent event) { if (event.isCancelled()) { return; } if (!event.hasFlag("a", "admin")) { return; } LWC lwc = event.getLWC(); CommandSender sender = event.getSender(); String[] args = event.getArgs(); if (!args[0].equals("remove")) { return; } // we have the right command event.setCancelled(true); if (args.length < 2) { lwc.sendSimpleUsage(sender, "/lwc admin remove <id>"); return; } int protectionId; try { protectionId = Integer.parseInt(args[1]); } catch (Exception e) { lwc.sendLocale(sender, "protection.admin.remove.invalidid"); return; } Protection protection = lwc.getPhysicalDatabase().loadProtection(protectionId); if (protection != null) { protection.remove(); } lwc.sendLocale(sender, "protection.admin.remove.finalize"); }
Example 8
Source File: DestroyModule.java From Modern-LWC with MIT License | 4 votes |
@Override public void onDestroyProtection(LWCProtectionDestroyEvent event) { if (event.isCancelled()) { return; } if (event.getMethod() != LWCProtectionDestroyEvent.Method.BLOCK_DESTRUCTION && event.getMethod() != LWCProtectionDestroyEvent.Method.ENTITY_DESTRUCTION) { return; } LWC lwc = event.getLWC(); Protection protection = event.getProtection(); Player player = event.getPlayer(); boolean isOwner = protection.isOwner(player); if (isOwner) { if (!lwc.isAdmin(player) && Boolean.parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "readonly-remove"))) { lwc.sendLocale(player, "protection.accessdenied"); event.setCancelled(true); return; } // bind the player of destroyed the protection // We don't need to save the history we modify because it will be saved anyway immediately after this for (History history : protection.getRelatedHistory(History.Type.TRANSACTION)) { if (history.getStatus() != History.Status.ACTIVE) { continue; } history.addMetaData("destroyer=" + player.getName()); history.addMetaData("destroyerTime=" + System.currentTimeMillis() / 1000L); } protection.remove(); if (!Boolean.parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "quiet"))) { BlockCache blockCache = BlockCache.getInstance(); lwc.sendLocaleToActionBar(player, "protection.unregistered", "block", LWC.materialToString(blockCache.getBlockType(protection.getBlockId()))); } return; } event.setCancelled(true); }
Example 9
Source File: FreeModule.java From Modern-LWC with MIT License | 4 votes |
@Override public void onProtectionInteract(LWCProtectionInteractEvent event) { if (event.getResult() != Result.DEFAULT) { return; } if (!event.hasAction("free")) { return; } LWC lwc = event.getLWC(); Protection protection = event.getProtection(); Player player = event.getPlayer(); event.setResult(Result.CANCEL); /* Due to treating entities as blocks some issues are triggered * such as when clicking an armor stand the block is air. * I feel there is something better to be done here but this works */ if (protection.getBlock().getType() == Material.AIR) { if (!protection.toString().contains("ARMOR_STAND")) { return; } } if (!lwc.isAdmin(player) && Boolean.parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "readonly-remove"))) { lwc.sendLocale(player, "protection.accessdenied"); return; } if (lwc.hasAdminPermission(player, "lwc.admin.remove") || protection.isOwner(player)) { LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection, LWCProtectionDestroyEvent.Method.COMMAND, true, true); lwc.getModuleLoader().dispatchEvent(evt); if (!evt.isCancelled()) { // bind the player of destroyed the protection // We don't need to save the history we modify because it will // be saved anyway immediately after this for (History history : protection.getRelatedHistory(History.Type.TRANSACTION)) { if (history.getStatus() != History.Status.ACTIVE) { continue; } history.addMetaData("destroyer=" + player.getName()); history.addMetaData("destroyerTime=" + System.currentTimeMillis() / 1000L); } protection.remove(); if (protection.getBlock() instanceof EntityBlock) { lwc.sendLocaleToActionBar(player, "protection.interact.remove.finalize", "block", EntityBlock.getEntity().getType().name()); } else { lwc.sendLocaleToActionBar(player, "protection.interact.remove.finalize", "block", !protection.toString().contains("ARMOR_STAND") ? LWC.materialToString(protection.getBlock()) : "ARMOR_STAND"); } } lwc.removeModes(player); } else { if (protection.getBlock() instanceof EntityBlock) { lwc.sendLocale(player, "protection.interact.error.notowner", "block", EntityBlock.getEntity().getType().name()); } else { lwc.sendLocale(player, "protection.interact.error.notowner", "block", LWC.materialToString(protection.getBlock())); } lwc.removeModes(player); } }
Example 10
Source File: FreeModule.java From Modern-LWC with MIT License | 4 votes |
@Override public void onEntityInteractProtection(LWCProtectionInteractEntityEvent event) { if (event.getResult() != Result.DEFAULT) { return; } if (!event.hasAction("free")) { return; } LWC lwc = event.getLWC(); Protection protection = event.getProtection(); Player player = event.getPlayer(); event.setResult(Result.CANCEL); if (protection.getBlock().getType() != Material.AIR) { return; } if (!lwc.isAdmin(player) && Boolean.parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "readonly-remove"))) { lwc.sendLocale(player, "protection.accessdenied"); return; } if (lwc.hasAdminPermission(player, "lwc.admin.remove") || protection.isOwner(player)) { LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection, LWCProtectionDestroyEvent.Method.COMMAND, true, true); lwc.getModuleLoader().dispatchEvent(evt); if (!evt.isCancelled()) { // bind the player of destroyed the protection // We don't need to save the history we modify because it will // be saved anyway immediately after this for (History history : protection.getRelatedHistory(History.Type.TRANSACTION)) { if (history.getStatus() != History.Status.ACTIVE) { continue; } history.addMetaData("destroyer=" + player.getName()); history.addMetaData("destroyerTime=" + System.currentTimeMillis() / 1000L); } protection.remove(); lwc.sendLocaleToActionBar(player, "protection.interact.remove.finalize", "block", event.getEvent().getRightClicked().getType().name()); } lwc.removeModes(player); } else { lwc.sendLocale(player, "protection.interact.error.notowner", "block", event.getEvent().getRightClicked().getType().name()); lwc.removeModes(player); } }
Example 11
Source File: ProtectionFinder.java From Modern-LWC with MIT License | 4 votes |
/** * Try and load a protection for a given block. If succeded, cache it locally * * @param block * @param noAutoCache if a match is found, don't cache it to be the protection we use * @return */ protected Result tryLoadProtection(BlockState block, boolean noAutoCache) { if (matchedProtection != null) { return Result.E_FOUND; } LWC lwc = LWC.getInstance(); ProtectionCache cache = lwc.getProtectionCache(); // Check the cache if ((matchedProtection = cache.getProtection(block)) != null) { searched = true; if (matchedProtection.getProtectionFinder() == null) { fullMatchBlocks(); matchedProtection.setProtectionFinder(this); cache.addProtection(matchedProtection); } return Result.E_FOUND; } // Manual intervention is required if (block.getType() == Material.REDSTONE_WIRE || block.getType() == Material.REDSTONE_WALL_TORCH || block.getType() == Material.REDSTONE_TORCH) { return Result.E_ABORT; } // don't bother trying to load it if it is not protectable if (!lwc.isProtectable(block)) { return Result.E_NOT_FOUND; } // Null-check if (block.getWorld() == null) { return Result.E_NOT_FOUND; } Protection protection = lwc.getPhysicalDatabase().loadProtection(block.getWorld().getName(), block.getX(), block.getY(), block.getZ()); if (protection != null) { if (protection.getProtectionFinder() == null) { protection.setProtectionFinder(this); fullMatchBlocks(); cache.addProtection(matchedProtection); } // ensure it's the right block if (protection.getBlockId() > 0) { if (protection.isBlockInWorld()) { if (noAutoCache) { return Result.E_FOUND; } this.matchedProtection = protection; searched = true; } else { // Removing orrupted protection protection.remove(); } } } return this.matchedProtection != null ? Result.E_FOUND : Result.E_NOT_FOUND; }
Example 12
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); } } }*/ } } }