org.bukkit.event.Cancellable#setCancelled ( )源码实例Demo

下面列出了org.bukkit.event.Cancellable#setCancelled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: uSkyBlock   文件: SpawnEvents.java
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);
    }
}
 
源代码2 项目: MineTinker   文件: ModManager.java
/**
 * 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;
}
 
源代码3 项目: BedWars   文件: PlayerListener.java
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);
                }
            }
        }
    }
}
 
源代码4 项目: ClaimChunk   文件: ChunkEventHelper.java
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);
}
 
源代码5 项目: LuckPerms   文件: BukkitPlatformListener.java
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()));
    }
}
 
源代码6 项目: HeavySpleef   文件: FlagBowspleef.java
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);
	}
}
 
源代码7 项目: PGM   文件: EventFilterMatchModule.java
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;
}
 
源代码8 项目: PGM   文件: DamageMatchModule.java
/** 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;
}
 
源代码9 项目: ProjectAres   文件: EventFilterMatchModule.java
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;
}
 
源代码10 项目: ShopChest   文件: IslandWorldListener.java
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;
}
 
源代码11 项目: ClaimChunk   文件: ChunkEventHelper.java
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);
    }
}
 
源代码12 项目: ClaimChunk   文件: ChunkEventHelper.java
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);
}
 
源代码13 项目: Skript   文件: ClickEventTracker.java
/**
 * 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;
	}
}
 
源代码14 项目: CombatLogX   文件: NoEntryExpansion.java
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;
    }
}
 
源代码15 项目: DungeonsXL   文件: DWorldListener.java
/**
 * @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);
    }
}
 
源代码16 项目: ShopChest   文件: ASkyBlockListener.java
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;
}
 
源代码17 项目: ShopChest   文件: BentoBoxListener.java
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;
}
 
源代码18 项目: ShopChest   文件: USkyBlockListener.java
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;
}
 
源代码19 项目: ShopChest   文件: WorldGuardListener.java
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;
}
 
源代码20 项目: ShopChest   文件: TownyListener.java
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;
}
 
 方法所在类
 同类方法