Java Code Examples for org.bukkit.event.block.BlockFromToEvent#setCancelled()

The following examples show how to use org.bukkit.event.block.BlockFromToEvent#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: DisplayProtectionListener.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void block(BlockFromToEvent event) {
    if (!useEnhanceProtection) {
        return;
    }
    if (DisplayItem.getNowUsing() != DisplayType.REALITEM) {
        return;
    }
    final Block targetBlock = event.getToBlock();
    final Block shopBlock = targetBlock.getRelative(BlockFace.DOWN);
    final Shop shop = getShopNature(shopBlock.getLocation(),true);
    if (shop == null) {
        return;
    }
    event.setCancelled(true);
    if (shop.getDisplay() != null) {
        shop.getDisplay().remove();
    }
    sendAlert(
            "[DisplayGuard] Liuqid "
                    + targetBlock.getLocation()
                    + " trying flow to top of shop, QuickShop already cancel it.");
}
 
Example 2
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onLiquidFlow(BlockFromToEvent event) {
    if (event.isCancelled()) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (GameCreator.isInArea(event.getBlock().getLocation(), game.getPos1(), game.getPos2())) {
            if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
                Block block = event.getToBlock();
                if (block.getType() == Material.AIR
                        || game.getRegion().isBlockAddedDuringGame(block.getLocation())) {
                    game.getRegion().addBuiltDuringGame(block.getLocation());
                } else {
                    event.setCancelled(true);
                }
            } else if (game.getStatus() != GameStatus.DISABLED) {
                event.setCancelled(true);
            }
        }
    }

}
 
Example 3
Source File: SeaLevelRise.java    From GlobalWarming with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Only allow sea-level blocks to flow if they are below the custom sea-level
 * - Track any new blocks originating from sea-level blocks
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockFromToEvent(BlockFromToEvent event) {
    if (event.getBlock().hasMetadata(SEALEVEL_BLOCK)) {
        boolean isWaterFixed = isOverride;
        if (!isWaterFixed) {
            final World world = event.getBlock().getWorld();
            final WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(world.getUID());
            final int deltaSeaLevel = (int) seaMap.getValue(climateEngine.getTemperature());
            final int customSeaLevel = baseSeaLevel + deltaSeaLevel;
            isWaterFixed = event.getBlock().getY() == event.getToBlock().getY() &&
                    event.getBlock().getY() > customSeaLevel;
        }

        if (!isWaterFixed) {
            isWaterFixed = !isSameChunk(event.getBlock().getChunk(), event.getToBlock().getChunk());
        }

        if (isWaterFixed) {
            event.setCancelled(true);
        } else {
            event.getToBlock().setMetadata(SEALEVEL_BLOCK, BLOCK_TAG);
        }
    }
}
 
Example 4
Source File: ChunkEventHelper.java    From ClaimChunk with MIT License 6 votes vote down vote up
public static void handleToFromEvent(@Nonnull BlockFromToEvent e) {
    if (e.isCancelled()) return;

    // Only continue if we should stop the spread from the config.
    if (!config.getBool("protection", "blockFluidSpreadIntoClaims")) return;

    // If the block isn't water or lava, we don't protect it.
    Material blockType = e.getBlock().getType();
    if (blockType != Material.WATER && blockType != Material.LAVA) return;

    Chunk from = e.getBlock().getChunk();
    Chunk to = e.getToBlock().getChunk();

    // If the from and to chunks have the same owner or if the to chunk is
    // unclaimed, the flow is allowed.
    final ChunkHandler CHUNK = ClaimChunk.getInstance().getChunkHandler();
    if (getChunksSameOwner(CHUNK, from, to) || !CHUNK.isClaimed(to)) return;

    // Cancel the flow
    e.setCancelled(true);
}
 
Example 5
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onLiquidFlow(BlockFromToEvent event) {
    if (event.isCancelled()) {
        return;
    }

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (GameCreator.isInArea(event.getBlock().getLocation(), game.getPos1(), game.getPos2())) {
            if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
                Block block = event.getToBlock();
                if (block.getType() == Material.AIR
                        || game.getRegion().isBlockAddedDuringGame(block.getLocation())) {
                    game.getRegion().addBuiltDuringGame(block.getLocation());
                } else {
                    event.setCancelled(true);
                }
            } else if (game.getStatus() != GameStatus.DISABLED) {
                event.setCancelled(true);
            }
        }
    }

}
 
Example 6
Source File: ShopItemListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onLiquidFlow(BlockFromToEvent e) {
    Block b = e.getToBlock();
    Block below = b.getRelative(BlockFace.DOWN);

    if (shopUtils.isShop(below.getLocation())) e.setCancelled(true);
}
 
Example 7
Source File: CoreObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockFromTo(BlockFromToEvent event) {
    if (lava.contains(event.getToBlock())){
        event.setCancelled(true);
    }
    if (!event.isCancelled()) {
        Block to = event.getToBlock();
        Block from = event.getBlock();
        if (CoreObjective.getClosestCore(to.getX(), to.getY(), to.getZ()).equals(this)) {
            if ((from.getType().equals(Material.LAVA) || from.getType().equals(Material.STATIONARY_LAVA)) && to.getType().equals(Material.AIR)) {
                double minY = 256;
                for (Block block : getCore()) {
                    if (block.getY() < minY)
                        minY = block.getY();
                }
                if (minY - to.getY() >= leak && !this.complete) {
                    this.complete = true;
                    event.setCancelled(false);
                    if (this.show)
                        ChatUtil.getGlobalChannel().sendLocalizedMessage(new UnlocalizedChatMessage(ChatColor.RED + "{0}", new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_LEAKED, team.getCompleteName() + ChatColor.RED, name)));
                    ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, null);
                    Bukkit.getServer().getPluginManager().callEvent(compEvent);
                }
            }
        }
    }
}
 
Example 8
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) {
    Location location = BukkitUtil.adapt(event.getBlock().getLocation());
    if (manager.isPlotWorld(location)) {
        PlotId id = manager.getPlotId(location);
        if (id == null) {
            event.setCancelled(true);
        } else {
            event.setCancelled(api.isPlotLocked(id));
        }
    }
}
 
Example 9
Source File: BlockPhysicsListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onLiquidFlow(BlockFromToEvent e) {
    Block block = e.getToBlock();

    if (block.getType() == Material.PLAYER_HEAD || block.getType() == Material.PLAYER_WALL_HEAD || Tag.SAPLINGS.isTagged(block.getType())) {
        String item = BlockStorage.checkID(block);

        if (item != null) {
            e.setCancelled(true);
        }
    }
}
 
Example 10
Source File: RegionInteractListener.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
	if(!Config.REGION_WATERFLOW.getBoolean()) {
		Material type = event.getBlock().getType();

		if((type == Material.WATER || type == CompatibilityUtils.Mat.WATER.get() || type == Material.LAVA || type == CompatibilityUtils.Mat.LAVA.get())
				&& RegionManager.get(event.getBlock()) == null
				&& RegionManager.get(event.getToBlock()) != null) {
			event.setCancelled(true);
		}
	}
}
 
Example 11
Source File: LWCBlockListener.java    From Modern-LWC with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockFromTo(BlockFromToEvent event) {
    Block block = event.getBlock();
    LWC lwc = this.plugin.getLWC();
    if (block.getType() == Material.WATER && lwc.isProtectable(event.getToBlock())) {
        if (lwc.findProtection(event.getToBlock().getLocation()) != null) {
            event.setCancelled(true);
            return;
        }
    }
}
 
Example 12
Source File: BlockEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockFromTo(BlockFromToEvent event) {
    final Block fromBlock = event.getBlock();
    final Block toBlock = event.getToBlock();
    final World world = fromBlock.getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    final GDPermissionUser user = CauseContextHelper.getEventUser(fromBlock.getLocation(), PlayerTracker.Type.NOTIFIER);
    if (user == null) {
        return;
    }

    Location location = toBlock.getLocation();
    GDClaim targetClaim = this.storage.getClaimAt(location);
    if (targetClaim.isWilderness()) {
        return;
    }

    if (fromBlock.isLiquid()) {
        final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.LIQUID_FLOW, fromBlock, toBlock, user, TrustTypes.BUILDER, true);
        if (result == Tristate.FALSE) {
            event.setCancelled(true);
            return;
        }
    } else if (handleBlockBreak(event, location, targetClaim, event.getBlock(), event.getToBlock(), user, false)) {
        event.setCancelled(true);
    }
}
 
Example 13
Source File: EnvironmentControlListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void noMelt(final BlockFromToEvent event) {
    event.setCancelled(true);
}
 
Example 14
Source File: WorldFreeze.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onLiquidFlow(BlockFromToEvent event) {
    if (!match.isRunning()) {
        event.setCancelled(true);
    }
}
 
Example 15
Source File: BlockPlaceRegion.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onBLiquidFlow(BlockFromToEvent event) {
    if (!event.isCancelled() && region.contains(new BlockRegion(null, event.getToBlock().getLocation().toVector())) && filter.evaluate(event.getToBlock(), event).equals(FilterState.DENY)) {
        event.setCancelled(true);
    }
}
 
Example 16
Source File: BlockEventRegion.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
    if (filter.evaluate(event.getToBlock(), event).equals(FilterState.DENY) && region.contains(new BlockRegion(null, event.getToBlock().getLocation().toVector()))) {
        event.setCancelled(true);
    }
}
 
Example 17
Source File: BlockFromToListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
    try {
        final Block block = event.getBlock();
        final Location location = block.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        final Material material = block.getType();
        final Block toBlock = event.getToBlock();
        final Location toLocation = toBlock.getLocation();

        if (material.equals(Material.WATER) || material.equals(Material.LAVA)) {
            final Island toIsland = islandManager.getIslandViaLocation(toLocation);
            if (island != toIsland)
                event.setCancelled(true);
        }

        if (!IridiumSkyblock.getUpgrades().oresUpgrade.enabled) return;

        if (event.getFace() == BlockFace.DOWN) return;

        if (!isSurroundedByWater(toLocation))
            return;

        final int oreLevel = island.getOreLevel();
        final World world = location.getWorld();
        if (world == null) return;

        final String worldName = world.getName();
        final Config config = IridiumSkyblock.getConfiguration();
        List<String> islandOreUpgrades;
        if (worldName.equals(config.worldName)) islandOreUpgrades = IridiumSkyblock.oreUpgradeCache.get(oreLevel);
        else if (worldName.equals(config.netherWorldName)) islandOreUpgrades = IridiumSkyblock.netherOreUpgradeCache.get(oreLevel);
        else return;

        Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> {
            final Material toMaterial = toBlock.getType();
            if (!(toMaterial.equals(Material.COBBLESTONE) || toMaterial.equals(Material.STONE)))
                return;

            final Random random = new Random();
            final String oreUpgrade = islandOreUpgrades.get(random.nextInt(islandOreUpgrades.size()));

            final XMaterial oreUpgradeXmaterial = XMaterial.valueOf(oreUpgrade);
            final Material oreUpgradeMaterial = oreUpgradeXmaterial.parseMaterial(true);
            if (oreUpgradeMaterial == null) return;

            toBlock.setType(oreUpgradeMaterial);

            final BlockState blockState = toBlock.getState();
            blockState.update(true);

            if (Utils.isBlockValuable(toBlock)) {
                final XMaterial xmaterial = XMaterial.matchXMaterial(material);
                island.valuableBlocks.compute(xmaterial.name(), (name, original) -> {
                    if (original == null) return 1;
                    return original + 1;
                });
                if (island.updating)
                    island.tempValues.add(location);
                island.calculateIslandValue();
            }
        });
    } catch (Exception ex) {
        IridiumSkyblock.getInstance().sendErrorMessage(ex);
    }
}
 
Example 18
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 3 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void BlockFromToEvent(BlockFromToEvent e) {

    if (e.getBlock().hasMetadata("ce.Ice"))
        e.setCancelled(true);

}