/** * We listen to BlockPlace events for obvious reasons. * * @param event the event */ @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onBlockPlace(final BlockPlaceEvent event) { /* * ____ _ _ ____ _ * | __ )| | ___ ___| | __ | _ \| | __ _ ___ ___ * | _ \| |/ _ \ / __| |/ / | |_) | |/ _` |/ __/ _ \ * | |_) | | (_) | (__| < | __/| | (_| | (_| __/ * |____/|_|\___/ \___|_|\_\ |_| |_|\__,_|\___\___| */ final Block block = event.getBlockPlaced(); final Block blockAgainst = event.getBlockAgainst(); // We don't care about null blocks. if (block == null || blockAgainst == null) return; final Material mat = block.getType(); final Player player = event.getPlayer(); boolean cancelled = false; // Check if the block may be placed against a certain material. // TODO: Maybe make it an extra check after all. final int againstId = blockAgainst.getTypeId(); if (BlockProperties.isLiquid(againstId)) { if ((mat != Material.WATER_LILY || !BlockProperties.isLiquid(block.getRelative(BlockFace.DOWN).getTypeId())) && !player.hasPermission(Permissions.BLOCKPLACE_AGAINST_LIQUIDS)) cancelled = true; } else if (againstId == Material.AIR.getId()) { if (!player.hasPermission(Permissions.BLOCKPLACE_AGAINST_AIR)) cancelled = true; } // First, the fast place check. if (fastPlace.isEnabled(player)) { if (fastPlace.check(player, block)) cancelled = true; else // Combined speed: if (Improbable.check(player, 1f, System.currentTimeMillis())) cancelled = true; } // Second, the no swing check (player doesn't swing his arm when placing a lily pad). if (!cancelled && mat != Material.WATER_LILY && noSwing.isEnabled(player) && noSwing.check(player)) cancelled = true; // Third, the reach check. if (!cancelled && reach.isEnabled(player) && reach.check(player, block.getLocation())) cancelled = true; // Fourth, the direction check. if (!cancelled && direction.isEnabled(player) && direction.check(player, block.getLocation(), blockAgainst.getLocation())) cancelled = true; // If one of the checks requested to cancel the event, do so. if (cancelled) event.setCancelled(cancelled); }
/** * We listen to ProjectileLaunch events to prevent players from launching projectiles too quickly. * * @param event the event */ @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onProjectileLaunch(final ProjectileLaunchEvent event) { /* * ____ _ _ _ _ _ _ * | _ \ _ __ ___ (_) ___ ___| |_(_) | ___ | | __ _ _ _ _ __ ___| |__ * | |_) | '__/ _ \| |/ _ \/ __| __| | |/ _ \ | | / _` | | | | '_ \ / __| '_ \ * | __/| | | (_) | | __/ (__| |_| | | __/ | |__| (_| | |_| | | | | (__| | | | * |_| |_| \___// |\___|\___|\__|_|_|\___| |_____\__,_|\__,_|_| |_|\___|_| |_| * |__/ */ // The shooter needs to be a player. if (!(event.getEntity().getShooter() instanceof Player)) return; // And the projectile must be one the following: switch (event.getEntityType()) { case ENDER_PEARL: break; case ENDER_SIGNAL: break; case EGG: break; case SNOWBALL: break; case THROWN_EXP_BOTTLE: break; case SPLASH_POTION: break; default: return; } final Player player = (Player) event.getEntity().getShooter(); // Do the actual check... if (speed.isEnabled(player)) { final long now = System.currentTimeMillis(); final Location loc = player.getLocation(); if (Combined.checkYawRate(player, loc.getYaw(), now, loc.getWorld().getName())) event.setCancelled(true); if (speed.check(player)) // If the check was positive, cancel the event. event.setCancelled(true); else if (Improbable.check(player, 1f, now)) // COmbined fighting speed. event.setCancelled(true); } }
/** * Return if t cancel. * * @param player * @param weights * @param now * @return */ public static final boolean check(final Player player, final float weight, final long now) { return instance.checkImprobable(player, weight, now); }