Java Code Examples for com.griefcraft.model.Protection#removeCache()
The following examples show how to use
com.griefcraft.model.Protection#removeCache() .
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: 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 2
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 3
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 4
Source File: LWC.java From Modern-LWC with MIT License | 4 votes |
/** * Remove protections very quickly with raw SQL calls * * @param sender * @param where * @param shouldRemoveBlocks * @return */ public int fastRemoveProtections(CommandSender sender, String where, boolean shouldRemoveBlocks) { List<Integer> exemptedBlocks = configuration.getIntList("optional.exemptBlocks", new ArrayList<Integer>()); List<Integer> toRemove = new LinkedList<>(); List<Block> removeBlocks = null; int totalProtections = physicalDatabase.getProtectionCount(); int completed = 0; int count = 0; // flush all changes to the database before working on the live database databaseThread.flush(); if (shouldRemoveBlocks) { removeBlocks = new LinkedList<Block>(); } if (where != null && !where.trim().isEmpty()) { where = " WHERE " + where.trim(); } sender.sendMessage("Loading protections via STREAM mode"); try { Statement resultStatement = physicalDatabase.getConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); if (physicalDatabase.getType() == Database.Type.MySQL) { resultStatement.setFetchSize(Integer.MIN_VALUE); } String prefix = physicalDatabase.getPrefix(); ResultSet result = resultStatement.executeQuery( "SELECT id, owner, type, x, y, z, data, blockId, world, password, date, last_accessed FROM " + prefix + "protections" + where); while (result.next()) { Protection protection = physicalDatabase.resolveProtection(result); World world = protection.getBukkitWorld(); // check if the protection is exempt from being removed if (protection.hasFlag(Flag.Type.EXEMPTION) || exemptedBlocks.contains(protection.getBlockId())) { continue; } count++; if (count % 100000 == 0 || count == totalProtections || count == 1) { sender.sendMessage(Colors.Dark_Red + count + " / " + totalProtections); } if (world == null) { continue; } // remove the protection toRemove.add(protection.getId()); // remove the block ? if (shouldRemoveBlocks) { removeBlocks.add(protection.getBlock()); } // Remove it from the cache if it's in there Protection cached = protectionCache.getProtection(protection.getCacheKey()); if (cached != null) { cached.removeCache(); } completed++; } // Close the streaming statement result.close(); resultStatement.close(); // flush all of the queries fullRemoveProtections(sender, toRemove); if (shouldRemoveBlocks) { removeBlocks(sender, removeBlocks); } } catch (SQLException e) { e.printStackTrace(); } return completed; }
Example 5
Source File: PhysDB.java From Modern-LWC with MIT License | 4 votes |
/** * Register a protection * * @param blockId * @param type * @param world * @param player * @param data * @param x * @param y * @param z * @return */ public Protection registerProtection(int blockId, Protection.Type type, String world, String player, String data, int x, int y, int z) { ProtectionCache cache = LWC.getInstance().getProtectionCache(); try { statement = prepare("INSERT INTO " + prefix + "protections (blockId, type, world, owner, password, x, y, z, date, last_accessed) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); statement.setInt(1, blockId); statement.setInt(2, type.ordinal()); statement.setString(3, world); statement.setString(4, player); statement.setString(5, data); statement.setInt(6, x); statement.setInt(7, y); statement.setInt(8, z); statement.setString(9, new Timestamp(new Date().getTime()).toString()); statement.setLong(10, System.currentTimeMillis() / 1000L); statement.executeUpdate(); statement = null; // We need to create the initial transaction for this protection // this transaction is viewable and modifiable during // POST_REGISTRATION Protection protection = loadProtection(world, x, y, z, true); protection.removeCache(); // if history logging is enabled, create it if (LWC.getInstance().isHistoryEnabled() && protection != null) { History transaction = protection.createHistoryObject(); transaction.setPlayer(player); transaction.setType(History.Type.TRANSACTION); transaction.setStatus(History.Status.ACTIVE); // store the player that created the protection transaction.addMetaData("creator=" + player); // now sync the history object to the database transaction.saveNow(); } // Cache it if (protection != null) { cache.addProtection(protection); protectionCount++; } // return the newly created protection return protection; } catch (SQLException e) { printException(e); } return null; }
Example 6
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); } } }*/ } } }