/** * Query the rule's filter with the given objects. * If the query is denied, cancel the event and set the deny message. * If the query is allowed, un-cancel the event. * If the query abstains, do nothing. * @return false if the query abstained, otherwise true */ protected static boolean processQuery(Event event, EventRule rule, IQuery query) { if(rule.filter() == null) { return false; } switch(rule.filter().query(query)) { case ALLOW: if(event instanceof Cancellable) { ((Cancellable) event).setCancelled(false); } return true; case DENY: if(event instanceof GeneralizingEvent) { ((GeneralizingEvent) event).setCancelled(true, rule.message()); } else if(event instanceof Cancellable) { ((Cancellable) event).setCancelled(true); } return true; default: return false; } }
private void forbidIfInProtectedTerritory(Player breaker, Block destroyed, Cancellable event, boolean destroy) { if (breaker == null) { return; } if (FPermission.hasPermission(breaker, FPermission.BUILD)) { return; } Region region = board.getByChunk(destroyed.getChunk()); if (region == null || region.isNeutral()) { if (wildernessProtected) { event.setCancelled(true); ParsingUtil.sendMessage(breaker, (destroy ? FMessage.PROTECTION_CANNOT_DESTROY_WILDERNESS : FMessage.PROTECTION_CANNOT_BUILD_WILDERNESS).getMessage()); } return; } Faction bFaction = factions.getByMember(breaker); Faction owner = region.getOwner(); Relation rel = owner.getRelation(bFaction); if (!rel.canBuild()) { event.setCancelled(true); ParsingUtil.sendMessage(breaker, (destroy ? FMessage.PROTECTION_CANNOT_DESTROY_FACTION : FMessage.PROTECTION_CANNOT_BUILD_FACTION).getMessage(), region.getOwner()); } }
/** * Fire this event. */ public void fire() { if (getVanilla() == null || getVanilla().getType() == Material.AIR || getWrapper() instanceof GenericItem) return; if (getEvent() instanceof Cancellable) // Cancel events by default. ((Cancellable) getEvent()).setCancelled(true); try { for (Method m : ReflectionUtil.getMethods(getWrapper().getClass(), getClass())) { ItemListener l = m.getAnnotation(ItemListener.class); if (l != null && (l.value() == null || Arrays.asList(l.value().getUsages()).contains(getUsage()))) m.invoke(getWrapper(), this); } handle(); } catch (Exception e) { e.printStackTrace(); Core.warn("Error using " + player.getName() + "'s " + getWrapper().getClass().getSimpleName() + "!"); getPlayer().sendMessage(ChatColor.RED + "There was an error while using this item."); } }
public void handle(String msg, CommandSender sender, Cancellable event) { if (Config.get().hiddenMode && !sender.hasPermission("camerastudio.use") && !sender.isOp()) return; if (msg.startsWith("/cam") || msg.startsWith("/camerastudio")) { event.setCancelled(true); List<String> args = Lists.newArrayList(msg.split(" ")); if (args.size() > 1) { args.remove(0); } Traveller traveller = null; if (sender instanceof ConsoleCommandSender) { traveller = new BukkitTraveller(null); } else { Player player = (Player) sender; traveller = Travellers.impl().get(player.getUniqueId()); } CmdCam.get().preExec(traveller, args); } }
private void handleCommand(CommandSender sender, String s, Cancellable event) { if (s.isEmpty()) { return; } if (this.plugin.getConfiguration().get(ConfigKeys.OPS_ENABLED)) { return; } if (s.charAt(0) == '/') { s = s.substring(1); } if (s.startsWith("minecraft:")) { s = s.substring("minecraft:".length()); } if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) { event.setCancelled(true); sender.sendMessage(Message.OP_DISABLED.asString(this.plugin.getLocaleManager())); } }
@SuppressWarnings("null") @Override public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) { if (isDelayed == Kleenean.TRUE) { Skript.error("Can't cancel an event anymore after is has already passed", ErrorQuality.SEMANTIC_ERROR); return false; } cancel = matchedPattern == 0; final Class<? extends Event>[] es = ScriptLoader.getCurrentEvents(); if (es == null) return false; for (final Class<? extends Event> e : es) { if (Cancellable.class.isAssignableFrom(e) || BlockCanBuildEvent.class.isAssignableFrom(e)) return true; // TODO warning if some event(s) cannot be cancelled even though some can (needs a way to be suppressed) } if (ScriptLoader.isCurrentEvent(PlayerLoginEvent.class)) Skript.error("A connect event cannot be cancelled, but the player may be kicked ('kick player by reason of \"...\"')", ErrorQuality.SEMANTIC_ERROR); else Skript.error(Utils.A(ScriptLoader.getCurrentEventName()) + " event cannot be cancelled", ErrorQuality.SEMANTIC_ERROR); return false; }
private boolean post(Event cause, Block block, BlockState oldState, BlockState newState, Player bukkit, boolean cancel) { ArcadePlayer player = null; if (bukkit != null) { player = this.plugin.getPlayer(bukkit); } BlockTransformEvent event = new BlockTransformEvent( this.plugin, block, cause, newState, oldState, player); this.plugin.getEventBus().publish(event); boolean canceled = cancel && event.isCanceled() && cause instanceof Cancellable; if (canceled) { ((Cancellable) cause).setCancelled(true); } return event.isCanceled(); }
/** * Updates the pearl holder * @param pearl The pearl to update * @param holder The pearl holder * @param event The event */ private void updatePearlHolder(ExilePearl pearl, InventoryHolder holder, Cancellable event) { if (holder instanceof Chest) { updatePearl(pearl, (Chest)holder); } else if (holder instanceof DoubleChest) { updatePearl(pearl, (Chest) ((DoubleChest) holder).getLeftSide()); } else if (holder instanceof Furnace) { updatePearl(pearl, (Furnace) holder); } else if (holder instanceof Dispenser) { updatePearl(pearl, (Dispenser) holder); } else if (holder instanceof Dropper) { updatePearl(pearl, (Dropper) holder); } else if (holder instanceof Hopper) { updatePearl(pearl, (Hopper) holder); } else if (holder instanceof BrewingStand) { updatePearl(pearl, (BrewingStand) holder); } else if (holder instanceof Player) { updatePearl(pearl, (Player) holder); }else { event.setCancelled(true); } }
public boolean check(Event e) { if (!(e instanceof Cancellable)) { return false; } if (((Cancellable) e).isCancelled()) { if (boo == true) { return true; } else { return false; } } else { if (boo == false) { return true; } else { return false; } } }
boolean canEdit(Player player, ArmorStand as){ ignoreNextInteract = true; ArrayList<Event> events = new ArrayList<Event>(); events.add(new PlayerInteractEntityEvent(player, as, EquipmentSlot.HAND)); events.add(new PlayerInteractAtEntityEvent(player, as, as.getLocation().toVector(), EquipmentSlot.HAND)); //events.add(new PlayerArmorStandManipulateEvent(player, as, player.getEquipment().getItemInMainHand(), as.getItemInHand(), EquipmentSlot.HAND)); for(Event event : events){ if(!(event instanceof Cancellable)) continue; try{ plugin.getServer().getPluginManager().callEvent(event); } catch(IllegalStateException ise){ ise.printStackTrace(); ignoreNextInteract = false; return false; //Something went wrong, don't allow edit just in case } if(((Cancellable)event).isCancelled()){ ignoreNextInteract = false; return false; } } ignoreNextInteract = false; return true; }
private void checkLimits(Cancellable event, EntityType entityType, Location location) { if (entityType == null) { return; // Only happens on "other-plugins", i.e. EchoPet } String islandName = WorldGuardHandler.getIslandNameAt(location); if (islandName == null) { event.setCancelled(true); // Only allow spawning on active islands... return; } if (entityType.getEntityClass().isAssignableFrom(Ghast.class) && location.getWorld().getEnvironment() != World.Environment.NETHER) { // Disallow ghasts for now... event.setCancelled(true); return; } us.talabrek.ultimateskyblock.api.IslandInfo islandInfo = plugin.getIslandInfo(islandName); if (islandInfo == null) { // Disallow spawns on inactive islands event.setCancelled(true); return; } if (!plugin.getLimitLogic().canSpawn(entityType, islandInfo)) { event.setCancelled(true); } }
public static void runCommand(CommandSender sender, String command) { if (CraftoAPI.instance() != null && CraftoAPI.instance().getServiceManager().getService(CommandService.class).isAvailable()) { CommandService cmdService = CommandService.instance().get(); if (cmdService.processCompletely(sender, command)) { return; } } if (CraftoPlugin.instance() != null && CraftoPlugin.instance().getCommands() != null) { CraftoCommands commands = CraftoPlugin.instance().getCommands(); Cancellable cancellable = new SimpleCancellable(); commands.handleCommandEvent(sender, command, cancellable); if (!cancellable.isCancelled()) { // Command wasnt handled by craftocommands, so it has to be a bukkit command Bukkit.getServer().dispatchCommand(sender, command); } } else { Bukkit.getServer().dispatchCommand(sender, command); } }
private void cancelBowSpleefEntityEvent(Entity entity, Cancellable cancellable) { boolean isBowspleefEntity = false; List<MetadataValue> metadatas = entity.getMetadata(BOWSPLEEF_METADATA_KEY); for (MetadataValue value : metadatas) { if (value.getOwningPlugin() != getHeavySpleef().getPlugin()) { continue; } isBowspleefEntity = value.asBoolean(); } if (isBowspleefEntity) { entity.remove(); cancellable.setCancelled(true); } }
public MessageWithStatus masterBroken(Cancellable event, Sign sign, Player player) { BankSet bank = bankManager.getBank(sign.getBlock().getLocation()); if (bank == null) return null; if (!bank.getOwner().equals(player.getName())) { if (can_override_break.check(player)) { return new BasicMessage("break override allowed", Status.INFO); } else { event.setCancelled(true); return new BasicMessage(Status.WARNING, "Cannot destroy a MondoChest which does not belong to you"); } } // If we're here, actually delete the bank int num_slaves = bank.numChests(); bankManager.removeBank(sign.getWorld().getName(), bank); playerManager.getState(player).setLastClickedMaster(null); return new BasicMessage(Status.SUCCESS, "removed bank and %d slave%s", num_slaves, pluralize(num_slaves) ); }
public MessageWithStatus slaveBroken(Cancellable event, Sign sign, Player player) { Map<ChestManager, BankSet> slaves = bankManager.getWorldSlaves(sign.getWorld().getName()); int removed = 0; for (Chest chest: slaveFinder().nearbyChests(sign)) { ChestManager info = new ChestManager(chest, false); if (slaves.containsKey(info)) { BankSet bs = slaves.get(info); if (bs.getAccess(player).canRemoveChests() || can_override_break.check(player)) { if (bs.removeChest(chest)) { bankManager.markChanged(bs); } removed++; } else { event.setCancelled(true); return new BasicMessage(Status.WARNING, "No access to remove this slave sign"); } } } return new BasicMessage(Status.SUCCESS, "Removed %d chests", removed); }
private static void handleExplode(Cancellable evt, List<Block> blocks) { if (!controlExplode) return; if (explodeControlType.equalsIgnoreCase("NoBlockBreak")) { blocks.clear(); } if (explodeControlType.equalsIgnoreCase("NoExplode")) { evt.setCancelled(true); } }
@Override public LuaValue onCalled(Varargs parameters) { LuaAccessor accessor = (LuaAccessor) parameters.arg(1); if (accessor.getObject() instanceof Event) { Event event = (Event) accessor.getObject(); if (event instanceof Cancellable) { Cancellable cancellable = (Cancellable) event; cancellable.setCancelled(true); } } return LuaValue.NIL; }
private void sendCancelMessage(EventRule rule, IEventQuery query) { if(rule.message() != null && query.getEvent() instanceof Cancellable && ((Cancellable) query.getEvent()).isCancelled() && query instanceof IPlayerQuery) { MatchPlayer player = getMatch().getPlayer(((IPlayerQuery) query).getPlayerId()); if(player != null) player.sendWarning(rule.message(), false); } }
boolean cancel(Cancellable event, @Nullable MatchPlayer actor, @Nullable BaseComponent message) { logger.fine("Cancel " + event + " actor=" + actor); event.setCancelled(true); if(actor != null && message != null) { actor.sendWarning(message, true); } return true; }
/** * Query the given damage event and cancel it if the result was denied. */ public Filter.QueryResponse processDamageEvent(Event event, ParticipantState victim, DamageInfo damageInfo) { Filter.QueryResponse response = queryDamage(checkNotNull(event), victim, damageInfo); if(response.isDenied() && event instanceof Cancellable) { ((Cancellable) event).setCancelled(true); } return response; }
@Override public void setCancelled(boolean cancel) { super.setCancelled(cancel); if(this.propagateCancel && this.cause instanceof Cancellable) { ((Cancellable) this.cause).setCancelled(cancel); } }
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { Cancellable cancellable = new de.alphahelix.alphalibary.reflection.nms.netty.Cancellable(); Object pckt = msg; if (ChannelAbstract.PACKET_CLASS.isAssignableFrom(msg.getClass())) { pckt = INCChannel.this.onPacketSend(this.owner, msg, cancellable); } if (cancellable.isCancelled()) { return; } super.write(ctx, pckt, promise); }
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Cancellable cancellable = new de.alphahelix.alphalibary.reflection.nms.netty.Cancellable(); Object pckt = msg; if (ChannelAbstract.PACKET_CLASS.isAssignableFrom(msg.getClass())) { pckt = INCChannel.this.onPacketReceive(this.owner, msg, cancellable); } if (cancellable.isCancelled()) { return; } super.channelRead(ctx, pckt); }
public static void cancelEventIfNotOwned(Player ply, Chunk chunk, Cancellable e) { if (ply.hasPermission("claimchunk.admin")) return; if (Config.getBool("protection", "blockPlayerChanges")) { if (!e.isCancelled()) { if (!canEdit(chunk.getWorld(), chunk.getX(), chunk.getZ(), ply.getUniqueId())) { e.setCancelled(true); Utils.toPlayer(ply, Config.getColor("errorColor"), Utils.getMsg("chunkNoEdit")); } } } }
private void handle(Cancellable event, Player player) { Game game = Skywars.getInstance().getGame(player); if (game != null) { if (game.isState(Game.GameState.LOBBY) || game.isState(Game.GameState.PREPARATION) || game.isState(Game.GameState.ENDING) || game.isState(Game.GameState.STARTING)) { event.setCancelled(true); // Cancel, game isn't active return; } GamePlayer gamePlayer = game.getGamePlayer(player); if (gamePlayer != null) { if (gamePlayer.isTeamClass()) { if (gamePlayer.getTeam().isPlayer(player)) { if (!game.getPlayers().contains(gamePlayer)) { event.setCancelled(true); } } } else { if (gamePlayer.getPlayer() == player) { if (!game.getPlayers().contains(gamePlayer)) { event.setCancelled(true); } } } } } else { if (Skywars.getInstance().isSingleServerMode()) { event.setCancelled(true); } } }
@Override public void setCancelled(boolean cancel) { Event event = getEvent(); if (event instanceof Cancellable) { ((Cancellable) event).setCancelled(cancel); } }
private boolean checkLoginStatus(Player player, Cancellable cancelEvent) { //thread-safe if (plugin.isInSession(player) || plugin.getConfig().getBoolean("commandOnlyProtection")) { return true; } if (!plugin.getConfig().getBoolean("protectAll") && !player.hasPermission(plugin.getName().toLowerCase() + ".protect") ) { //we don't need to protect this player return true; } cancelEvent.setCancelled(true); return false; }
@Override @Nullable protected Boolean[] get(final Event e) { if (!(e instanceof Cancellable)) return new Boolean[0]; return new Boolean[] {((Cancellable) e).isCancelled()}; }
@Override public void execute(final Event e) { if (e instanceof Cancellable) ((Cancellable) e).setCancelled(cancel); if (e instanceof PlayerInteractEvent) { ((PlayerInteractEvent) e).setUseItemInHand(cancel ? Result.DENY : Result.DEFAULT); ((PlayerInteractEvent) e).setUseInteractedBlock(cancel ? Result.DENY : Result.DEFAULT); } else if (e instanceof BlockCanBuildEvent) { ((BlockCanBuildEvent) e).setBuildable(!cancel); } else if (e instanceof PlayerDropItemEvent) { PlayerUtils.updateInventory(((PlayerDropItemEvent) e).getPlayer()); } }
private void handleEvent(Player player, Cancellable event) { Flag flag = this.GetFlagInstanceAtLocation(player.getLocation(), player); if(flag != null) { event.setCancelled(true); } }
private void handleEvent(World world, Cancellable event) { Flag flag = this.GetFlagInstanceAtLocation(world.getSpawnLocation(), null); if(flag == null) return; event.setCancelled(true); }
@EventHandler(priority = EventPriority.LOWEST) public void anyPlayerEvent(PlayerEvent event){ if(!(event instanceof Cancellable)) return; if (!usingBeeLoginMod) return; Player player = event.getPlayer(); if (!loginStatus.get(player.getName().toLowerCase())) { ((Cancellable) event).setCancelled(true); } }
/** * Used by BlockSpreadEvent and BlockFormEvent to test conditions. */ private void handleStateChange(World world, Block block, Cancellable event, Object... filter) { Match match = Cardinal.getMatch(world); if (match == null) { return; } for (AppliedRegion reg : get(match, ApplyType.BLOCK, ApplyType.BLOCK_PLACE)) { if (apply(reg, block.getLocation(), null, event, filter)) { break; } } }
private boolean apply(AppliedRegion region, Vector position, Player player, Cancellable event, Object... objects) { if (position == null || region.contains(position)) { FilterState result = region.evaluate(objects); if (result.hasResult() && !result.toBoolean()) { event.setCancelled(true); region.sendMessage(player); } return result.hasResult(); } return false; }
@Override public boolean check(Event e) { Boolean cancel = false; if (e instanceof Cancellable) { cancel = ((Cancellable) e).isCancelled(); } if (cancel == true) { return true; } else { return false; } }
@Override public boolean check(Event e) { Boolean cancel = false; if (e instanceof Cancellable) { cancel = ((Cancellable) e).isCancelled(); } if (cancel == true) { return false; } else { return true; } }
@EventHandler public void disableBlacklistedPotionUse(UseItemEvent e) { boolean wasCancelled = e.isCancelled(); Material material = e.getItemStack().getType(); if (material.equals(Material.POTION) || material.equals(Material.SPLASH_POTION) || material.equals(Material.LINGERING_POTION)) { Player p = e.getCause().getFirstPlayer(); if (p != null && helper.getWorldGuard().hasPermission(p, "worldguard.override.potions")) return; PotionData potionType = ((PotionMeta) e.getItemStack().getItemMeta()).getBasePotionData(); if (helper.isBlacklistedPotion(potionType, e.getWorld())) { e.setCancelled(true); if (e.getOriginalEvent() instanceof Cancellable) ((Cancellable) e.getOriginalEvent()).setCancelled(true); if (p != null && !wasCancelled) { p.sendMessage(ChatColor.RED + "Sorry, potions with " + potionType.getType().name() + " can't be used."); p.updateInventory(); } } } }
/** * Checks if a rule is active for a given player and cancels it * @param rule The rule to check * @param event The event * @param player The player to check * @param notify whether to notify the player */ protected void checkAndCancelRule(ExileRule rule, Cancellable event, Player player, boolean notify) { if (event == null || player == null) { return; } UUID playerId = player.getUniqueId(); if (isRuleActive(rule, playerId)) { ((Cancellable)event).setCancelled(true); if (notify) { msg(player, Lang.ruleCantDoThat, rule.getActionString()); } } }
private void processEvent(Cancellable event, Player player) { if (!SteelCore.SPECTATOR_SUPPORT) { Optional<Challenger> ch = CommonCore.getChallenger(player.getUniqueId()); if (ch.isPresent() && ch.get().isSpectating()) { event.setCancelled(true); return; } } }
public static Cancellable handleStatisticsIncrease(EntityPlayer entityHuman, net.minecraft.stats.StatBase statistic, int current, int incrementation) { Player player = ((EntityPlayerMP) entityHuman).getBukkitEntity(); Event event; if (statistic instanceof net.minecraft.stats.Achievement) { if (current != 0) { return null; } event = new PlayerAchievementAwardedEvent(player, CraftStatistic.getBukkitAchievement((net.minecraft.stats.Achievement) statistic)); } else { org.bukkit.Statistic stat = CraftStatistic.getBukkitStatistic(statistic); switch (stat) { case FALL_ONE_CM: case BOAT_ONE_CM: case CLIMB_ONE_CM: case DIVE_ONE_CM: case FLY_ONE_CM: case HORSE_ONE_CM: case MINECART_ONE_CM: case PIG_ONE_CM: case PLAY_ONE_TICK: case SWIM_ONE_CM: case WALK_ONE_CM: // Do not process event for these - too spammy return null; default: } if (stat.getType() == Type.UNTYPED) { event = new PlayerStatisticIncrementEvent(player, stat, current, current + incrementation); } else if (stat.getType() == Type.ENTITY) { EntityType entityType = CraftStatistic.getEntityTypeFromStatistic(statistic); event = new PlayerStatisticIncrementEvent(player, stat, current, current + incrementation, entityType); } else { Material material = CraftStatistic.getMaterialFromStatistic(statistic); event = new PlayerStatisticIncrementEvent(player, stat, current, current + incrementation, material); } } entityHuman.worldObj.getServer().getPluginManager().callEvent(event); return (Cancellable) event; }