Java Code Examples for org.bukkit.event.Cancellable#setCancelled()
The following examples show how to use
org.bukkit.event.Cancellable#setCancelled() .
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: ModManager.java From MineTinker with GNU General Public License v3.0 | 6 votes |
/** * Checks the durability of the Tool * * @param cancellable the Event (implements Cancelable) * @param player the Player * @param tool the Tool * @return false: if broken; true: if enough durability */ public boolean durabilityCheck(@NotNull Cancellable cancellable, @NotNull Player player, @NotNull ItemStack tool) { ItemMeta meta = tool.getItemMeta(); if (meta instanceof Damageable) { if (config.getBoolean("UnbreakableTools", true) && tool.getType().getMaxDurability() - ((Damageable) meta).getDamage() <= 2) { cancellable.setCancelled(true); if (config.getBoolean("Sound.OnBreaking", true)) { player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 0.5F, 0.5F); } return false; } } return true; }
Example 2
Source File: PlayerListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
public static void onItemPickup(Player player, Item item, Cancellable cancel) { if (cancel.isCancelled()) { return; } if (Main.isPlayerInGame(player)) { GamePlayer gPlayer = Main.getPlayerGameProfile(player); Game game = gPlayer.getGame(); if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) { cancel.setCancelled(true); } else { for (ItemSpawner spawner : game.getSpawners()) { if (spawner.getMaxSpawnedResources() > 0) { spawner.remove(item); } } } } }
Example 3
Source File: ChunkEventHelper.java From ClaimChunk with MIT License | 6 votes |
public static void handleEntityEvent(@Nonnull Player ply, @Nonnull Entity ent, @Nonnull Cancellable e) { if (e.isCancelled()) return; // If entities aren't protected, we don't need to check if this // one is -_- // If PvP is disabled, all entities (including players) are protected. // If PvP is enabled, all entities except players are protected. boolean protectEntities = config.getBool("protection", "protectEntities"); boolean blockPvp = ent.getType() == EntityType.PLAYER && config.getBool("protection", "blockPvp"); if (!protectEntities && !blockPvp) { return; } // Admins have permission to do anything in claimed chunks. if (Utils.hasAdmin(ply)) return; // Check if the player is able to edit in both the chunk they're in as // well as the chunk the animal is in. boolean canPlayerEditEntityChunk = getCanEdit(ent.getLocation().getChunk(), ply.getUniqueId()); if (!blockPvp && canPlayerEditEntityChunk) { return; } // Cancel the event e.setCancelled(true); }
Example 4
Source File: FlagBowspleef.java From HeavySpleef with GNU General Public License v3.0 | 6 votes |
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); } }
Example 5
Source File: SpawnEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
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); } }
Example 6
Source File: BukkitPlatformListener.java From LuckPerms with MIT License | 6 votes |
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.contains(":")) { s = s.substring(s.indexOf(':') + 1); } 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())); } }
Example 7
Source File: ClickEventTracker.java From Skript with GNU General Public License v3.0 | 5 votes |
/** * Processes a click event from a player. * @param player Player who caused it. * @param event The event. * @param hand Slot associated with the event. * @return If the event should be passed to scripts. */ public boolean checkEvent(Player player, Cancellable event, EquipmentSlot hand) { UUID uuid = player.getUniqueId(); TrackedEvent first = firstEvents.get(uuid); if (first != null && first.event != event) { // We've checked an event before, and it is not this one if (!modifiedEvents.contains(first.event)) { // Do not modify cancellation status of event, Skript did not touch it // This avoids issues like #2389 return false; } // Ignore this, but set its cancelled status based on one set to first event if (event instanceof PlayerInteractEvent) { // Handle use item/block separately // Failing to do so caused issue SkriptLang/Skript#2303 PlayerInteractEvent firstClick = (PlayerInteractEvent) first.event; PlayerInteractEvent click = (PlayerInteractEvent) event; click.setUseInteractedBlock(firstClick.useInteractedBlock()); click.setUseItemInHand(firstClick.useItemInHand()); } else { event.setCancelled(first.event.isCancelled()); } return false; } else { // Remember and run this firstEvents.put(uuid, new TrackedEvent(event, hand)); return true; } }
Example 8
Source File: TownyListener.java From ShopChest with MIT License | 5 votes |
private boolean handleForLocation(Player player, Location loc, Cancellable e) { TownBlock townBlock = TownyUniverse.getTownBlock(loc); if (townBlock == null) return false; try { Town town = townBlock.getTown(); Optional<Resident> playerResident = town.getResidents().stream() .filter(r -> r.getName().equals(player.getName())) .findFirst(); if (!playerResident.isPresent()) { e.setCancelled(true); plugin.debug("Cancel Reason: Towny (no resident)"); return true; } Resident resident = playerResident.get(); String plotType = townBlock.getType().name(); boolean cancel = (resident.isMayor() && !Config.townyShopPlotsMayor.contains(plotType)) || (resident.isKing() && !Config.townyShopPlotsKing.contains(plotType)) || (!resident.isKing() && !resident.isMayor() && !Config.townyShopPlotsResidents.contains(plotType)); if (cancel) { e.setCancelled(true); plugin.debug("Cancel Reason: Towny (no permission)"); return true; } } catch (NotRegisteredException ignored) { } return false; }
Example 9
Source File: WorldGuardListener.java From ShopChest with MIT License | 5 votes |
private boolean handleForLocation(Player player, Location loc, Cancellable e, IWrappedFlag<WrappedState> flag) { if (flag == null) { // Flag may have not been registered successfully, so ignore them. return false; } WrappedState state = wgWrapper.queryFlag(player, loc, flag).orElse(WrappedState.DENY); if (state == WrappedState.DENY) { e.setCancelled(true); plugin.debug("Cancel Reason: WorldGuard"); return true; } return false; }
Example 10
Source File: USkyBlockListener.java From ShopChest with MIT License | 5 votes |
private boolean handleForLocation(Player player, Location loc, Cancellable e) { IslandInfo islandInfo = uSkyBlockAPI.getIslandInfo(loc); if (islandInfo == null) return false; if (!player.getName().equals(islandInfo.getLeader()) && !islandInfo.getMembers().contains(player.getName())) { e.setCancelled(true); plugin.debug("Cancel Reason: uSkyBlock"); return true; } return false; }
Example 11
Source File: BentoBoxListener.java From ShopChest with MIT License | 5 votes |
private boolean handleForLocation(Player player, Location loc, Cancellable e) { boolean allowed = checkIsland((Event) e, player, loc, BentoBoxShopFlag.SHOP_FLAG); if (!allowed) { e.setCancelled(true); plugin.debug("Cancel Reason: BentoBox"); return true; } return false; }
Example 12
Source File: ASkyBlockListener.java From ShopChest with MIT License | 5 votes |
private boolean handleForLocation(Player player, Location loc, Cancellable e) { Island island = ASkyBlockAPI.getInstance().getIslandAt(loc); if (island == null) return false; if (!player.getUniqueId().equals(island.getOwner()) && !island.getMembers().contains(player.getUniqueId())) { e.setCancelled(true); plugin.debug("Cancel Reason: ASkyBlock"); return true; } return false; }
Example 13
Source File: DWorldListener.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
/** * @param event the event * @param entity the entity * @param interact true = interact; false = break */ public void onTouch(Cancellable event, Entity entity, boolean interact) { GameWorld gameWorld = plugin.getGameWorld(entity.getWorld()); if (gameWorld == null) { return; } GameRuleContainer rules = gameWorld.getDungeon().getRules(); Set<ExMob> prot = interact ? rules.getState(GameRule.INTERACTION_PROTECTED_ENTITIES) : rules.getState(GameRule.DAMAGE_PROTECTED_ENTITIES); if (prot.contains(caliburn.getExMob(entity))) { event.setCancelled(true); } }
Example 14
Source File: NoEntryExpansion.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
public final void preventEntry(Cancellable e, Player player, Location fromLoc, Location toLoc) { ICombatManager combatManager = getPlugin().getCombatManager(); if(!combatManager.isInCombat(player)) return; LivingEntity enemy = combatManager.getEnemy(player); sendNoEntryMessage(player, enemy); BukkitScheduler scheduler = Bukkit.getScheduler(); NoEntryHandler handler = getNoEntryHandler(); NoEntryMode noEntryMode = handler.getNoEntryMode(); switch(noEntryMode) { case KILL: player.setHealth(0.0D); break; case CANCEL: e.setCancelled(true); break; case TELEPORT: if(enemy != null) player.teleport(enemy); else e.setCancelled(true); break; case KNOCKBACK: e.setCancelled(true); scheduler.runTaskLater(getPlugin().getPlugin(), () -> knockbackPlayer(player, fromLoc, toLoc), 1L); break; case VULNERABLE: case NOTHING: default: break; } }
Example 15
Source File: ChunkEventHelper.java From ClaimChunk with MIT License | 5 votes |
private static void handlePistonEvent(@Nonnull Block piston, @Nonnull List<Block> blocks, @Nonnull BlockFace direction, @Nonnull Cancellable e) { if (e.isCancelled()) return; // If we don't protect against pistons, no work is needed. if (!config.getBool("protection", "blockPistonsIntoClaims")) return; Chunk pistonChunk = piston.getChunk(); List<Chunk> blockChunks = new ArrayList<>(); blockChunks.add(piston.getRelative(direction).getChunk()); // Add to the list of chunks possible affected by this piston // extension. This list should never be >2 in size but the world // is a weird place. for (Block block : blocks) { Chunk to = block.getRelative(direction).getChunk(); boolean added = false; for (Chunk ablockChunk : blockChunks) { if (getChunksEqual(ablockChunk, to)) { added = true; break; } } if (!added) blockChunks.add(to); } // If the from and to chunks have the same owner or if the to chunk is // unclaimed, the piston can extend into the blockChunk. final ChunkHandler CHUNK = ClaimChunk.getInstance().getChunkHandler(); boolean die = false; for (Chunk blockChunk : blockChunks) { if (!getChunksSameOwner(CHUNK, pistonChunk, blockChunk) && CHUNK.isClaimed(blockChunk)) { die = true; break; } } if (!die) return; e.setCancelled(true); }
Example 16
Source File: ChunkEventHelper.java From ClaimChunk with MIT License | 5 votes |
private static void cancelWorldEvent(@Nonnull Chunk chunk, @Nonnull Cancellable e, @SuppressWarnings("SameParameterValue") @Nonnull String config) { if (e.isCancelled()) return; // If this type of thing isn't protected against, we can skip the // checks. if (!ChunkEventHelper.config.getBool("protection", config)) return; final ChunkHandler CHUNK = ClaimChunk.getInstance().getChunkHandler(); // If the chunk is claimed, prevent the spreading. if (CHUNK.isClaimed(chunk)) { e.setCancelled(true); } }
Example 17
Source File: IslandWorldListener.java From ShopChest with MIT License | 5 votes |
private boolean handleForLocation(Player player, Location loc, Cancellable e) { if (!loc.getWorld().getName().equals(IslandWorldApi.getIslandWorld().getName())) return false; if (!IslandWorldApi.canBuildOnLocation(player, loc, true)) { e.setCancelled(true); plugin.debug("Cancel Reason: IslandWorld"); return true; } return false; }
Example 18
Source File: EventFilterMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
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; }
Example 19
Source File: DamageMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
/** Query the given damage event and cancel it if the result was denied. */ public Filter.QueryResponse processDamageEvent( Cancellable event, ParticipantState victim, DamageInfo damageInfo) { Filter.QueryResponse response = queryDamage(checkNotNull(event), victim, damageInfo); if (response.isDenied()) { event.setCancelled(true); } return response; }
Example 20
Source File: EventFilterMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
boolean cancel(Cancellable event, @Nullable MatchPlayer actor, @Nullable Component message) { match.getLogger().fine("Cancel " + event + " actor=" + actor); event.setCancelled(true); if (actor != null && message != null) { actor.sendWarning(message); } return true; }