Java Code Examples for org.bukkit.event.block.BlockPlaceEvent#getBlock()

The following examples show how to use org.bukkit.event.block.BlockPlaceEvent#getBlock() . 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: BlockPlaceListener.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMonitorBlockPlace(BlockPlaceEvent 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;

        if (!Utils.isBlockValuable(block)) return;

        final Material material = block.getType();
        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);

        Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), island::calculateIslandValue);
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 2
Source File: LockListener.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlace(BlockPlaceEvent e) {

    final Block b = e.getBlock();

    if (b.getType() != Material.HOPPER) {
        return;
    }

    final Player p = e.getPlayer();

    if (!Util.isOtherShopWithinHopperReach(b, p)) {
        return;
    }

    if (QuickShop.getPermissionManager().hasPermission(p, "quickshop.other.open")) {
        MsgUtil.sendMessage(p, MsgUtil.getMessage("bypassing-lock", p));
        return;
    }

    MsgUtil.sendMessage(p, MsgUtil.getMessage("that-is-locked", p));
    e.setCancelled(true);
}
 
Example 3
Source File: SignEditListener.java    From NyaaUtils with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlock();
    ItemStack item = event.getItemInHand();
    if (block != null && item != null &&
            isSign(item.getType()) &&
            isSign(block.getType())) {
        Player player = event.getPlayer();
        if ((player.isOp() && player.getGameMode().equals(GameMode.CREATIVE)) ||
                !item.hasItemMeta() || !(item.getItemMeta() instanceof BlockStateMeta) ||
                !player.hasPermission("nu.se.player")) {
            return;
        }
        SignContent c = SignContent.fromItemStack(item);
        if (!c.getContent().isEmpty()) {
            signContents.put(event.getPlayer().getUniqueId(), c);
        }
    }
}
 
Example 4
Source File: PricklyBlock.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean effect(Event event, Player player) {
	if(event instanceof BlockPlaceEvent) {
		BlockPlaceEvent e = (BlockPlaceEvent) event;
		Block b = e.getBlock();
		b.setMetadata("ce.mine", new FixedMetadataValue(main, getOriginalName()));
		String coord = b.getX() + " " + b.getY() + " " + b.getZ();
		b.getRelative(0,1,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
		b.getRelative(0,-1,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
		b.getRelative(1,0,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
		b.getRelative(0,0,1).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
		b.getRelative(0,0,-1).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
		b.getRelative(-1,0,0).setMetadata("ce.mine.secondary", new FixedMetadataValue(main, coord));
	} else if(event instanceof PlayerMoveEvent) {
		if(!player.getGameMode().equals(GameMode.CREATIVE) && !player.hasPotionEffect(PotionEffectType.CONFUSION)) {
			player.damage(Damage);
			player.sendMessage(ChatColor.DARK_GREEN + "A nearbly Block is hurting you!");
			player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, NauseaDuration, NauseaLevel));
		}
	}
	return false;
}
 
Example 5
Source File: MonstersIncListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
    Block block = e.getBlock();
    Location loc = e.getBlock().getLocation();

    if(isDoor(block)) {
        doorLocs.add(loc);
    }
}
 
Example 6
Source File: GameMap.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void blockPlaceCheck(BlockPlaceEvent event)
{
	if(event.getPlayer().getGameMode() != GameMode.CREATIVE)
	{
		Block b = event.getBlock();
		UnplaceableBlock block = this.unplaceableBlocks.get(b.getType());
		if(block != null)
		{
			if(block.isData((byte)-1) || block.isData(b.getData()))
				event.setCancelled(true);
		}
	}
}
 
Example 7
Source File: DWorldListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlock();

    DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(block.getWorld());
    if (gameWorld == null) {
        return;
    }

    if (gameWorld.onPlace(event.getPlayer(), block, event.getBlockAgainst(), event.getItemInHand())) {
        event.setCancelled(true);
    }
}
 
Example 8
Source File: Tnt.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlock();
    if (block.getType().equals(Material.TNT) && instantIgnite && !event.isCancelled()) {
        event.getBlock().setType(Material.AIR);
        TNTPrimed tnt = (TNTPrimed) GameHandler.getGameHandler().getMatchWorld().spawnEntity(block.getLocation().add(new Vector(0.5, 0.5, 0.5)), EntityType.PRIMED_TNT);
        Bukkit.getServer().getPluginManager().callEvent(new ExplosionPrimeEvent(tnt));
    }
}
 
Example 9
Source File: Game.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
public void onPlayerPlaceBlock(BlockPlaceEvent event, SpleefPlayer player) {
	PlayerBlockPlaceEvent spleefEvent = new PlayerBlockPlaceEvent(this, player, event.getBlock());
	eventBus.callEvent(spleefEvent);
	
	if (spleefEvent.isCancelled()) {
		event.setCancelled(true);
		return;
	}
	
	boolean disableBuild = getPropertyValue(GameProperty.DISABLE_BUILD);
	
	if (disableBuild) {
		event.setCancelled(true);
	}
}
 
Example 10
Source File: ChestProtectListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onBlockPlace(BlockPlaceEvent event) {
	Block block = event.getBlock();
	Material type = block.getType();
	Player player = event.getPlayer();
	if (Utils.isChest(type)) {
		if (plugin.getProtectedChests().isChestProtected(block, player)) {
			Log.debug("Cancelled placing of chest block by '" + player.getName() + "' at '"
					+ Utils.getLocationString(block) + "': Protected chest nearby");
			event.setCancelled(true);
		}
	} else if (type == Material.HOPPER) {
		if (plugin.getProtectedChests().isProtectedChestAroundHopper(block, player)) {
			Log.debug("Cancelled placing of hopper block by '" + player.getName() + "' at '"
					+ Utils.getLocationString(block) + "': Protected chest nearby");
			event.setCancelled(true);
		}
	} else if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.ACTIVATOR_RAIL) {
		Block upperBlock = block.getRelative(BlockFace.UP);
		if (Utils.isChest(upperBlock.getType()) && plugin.getProtectedChests().isChestProtected(upperBlock, player)) {
			Log.debug("Cancelled placing of rail block by '" + player.getName() + "' at '"
					+ Utils.getLocationString(block) + "': Protected chest nearby");
			event.setCancelled(true);
			return;
		}
	}
}
 
Example 11
Source File: ChestListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
void onBlockPlace(BlockPlaceEvent event) {
	Block block = event.getBlock();
	if (Utils.isChest(block.getType())) {
		plugin.onChestPlacement(event.getPlayer(), block);
	}
}
 
Example 12
Source File: BlockPlaceListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onBlockPlace(BlockPlaceEvent 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 Player player = event.getPlayer();
        final User user = User.getUser(player);

        final Material material = block.getType();
        final XMaterial xmaterial = XMaterial.matchXMaterial(material);
        final Config config = IridiumSkyblock.getConfiguration();
        final Integer max = config.limitedBlocks.get(xmaterial);
        if (max != null) {
            if (island.valuableBlocks.getOrDefault(xmaterial.name(), 0) >= max) {
                player.sendMessage(Utils.color(IridiumSkyblock.getMessages().blockLimitReached
                        .replace("%prefix%", config.prefix)));
                event.setCancelled(true);
                return;
            }
        }

        if (user.islandID == island.getId()) {
            for (Mission mission : IridiumSkyblock.getMissions().missions) {
                final Map<String, Integer> levels = island.getMissionLevels();
                levels.putIfAbsent(mission.name, 1);

                final MissionData level = mission.levels.get(levels.get(mission.name));
                if (level == null) continue;
                if (level.type != MissionType.BLOCK_PLACE) continue;

                final List<String> conditions = level.conditions;

                if (
                        conditions.isEmpty()
                                ||
                                conditions.contains(xmaterial.name())
                                ||
                                conditions.contains(((Crops) block.getState().getData()).getState().toString())
                )
                    island.addMission(mission.name, 1);
            }
        }

        if (!island.getPermissions(user).placeBlocks)
            event.setCancelled(true);
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 13
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlace(BlockPlaceEvent event) {
	Block block = event.getBlock();
	block.setMetadata("blockPlaced", new FixedMetadataValue(MineTinker.getPlugin(), System.currentTimeMillis()));
}
 
Example 14
Source File: BlockListener.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlace(BlockPlaceEvent e) {

    final Material type = e.getBlock().getType();
    final Block placingBlock = e.getBlock();
    final Player player = e.getPlayer();

    if (type != Material.CHEST) {
        return;
    }
    Block chest = null;
    //Chest combine mechanic based checking
    if (player.isSneaking()) {
        Block blockAgainst = e.getBlockAgainst();
        if (blockAgainst.getType() == Material.CHEST && placingBlock.getFace(blockAgainst) != BlockFace.UP && placingBlock.getFace(blockAgainst) != BlockFace.DOWN && !(((Chest) blockAgainst.getState()).getInventory() instanceof DoubleChestInventory)) {
            chest = e.getBlockAgainst();
        } else {
            return;
        }
    } else {
        //Get all chest in vertical Location
        BlockFace placingChestFacing = ((Directional) (placingBlock.getState().getBlockData())).getFacing();
        for (BlockFace face : Util.getVerticalFacing()) {
            //just check the right side and left side
            if (face != placingChestFacing && face != placingChestFacing.getOppositeFace()) {
                Block nearByBlock = placingBlock.getRelative(face);
                if (nearByBlock.getType() == Material.CHEST
                        //non double chest
                        && !(((Chest) nearByBlock.getState()).getInventory() instanceof DoubleChestInventory)
                        //same facing
                        && placingChestFacing == ((Directional) nearByBlock.getState().getBlockData()).getFacing()) {
                    if (chest == null) {
                        chest = nearByBlock;
                    } else {
                        //when multiply chests competed, minecraft will always combine with right side
                        if (placingBlock.getFace(nearByBlock) == Util.getRightSide(placingChestFacing)) {
                            chest = nearByBlock;
                        }
                    }
                }
            }
        }
    }
    if (chest == null) {
        return;
    }

    Shop shop = getShopPlayer(chest.getLocation(), false);
    if (shop != null) {
        if (!QuickShop.getPermissionManager().hasPermission(player, "quickshop.create.double")) {
            e.setCancelled(true);
            MsgUtil.sendMessage(player, MsgUtil.getMessage("no-double-chests", player));

        } else if (!shop.getModerator().isModerator(player.getUniqueId())) {
            e.setCancelled(true);
            MsgUtil.sendMessage(player, MsgUtil.getMessage("not-managed-shop", player));
        }
    }
}
 
Example 15
Source File: SpawnerPlaceListener.java    From MineableSpawners with MIT License 4 votes vote down vote up
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onSpawnerPlace(BlockPlaceEvent e) {
    Block block = e.getBlock();
    Material material = block.getType();

    // check if item is spawner
    if (material != XMaterial.SPAWNER.parseMaterial()) {
        return;
    }

    // check if valid entity type
    ItemStack item = e.getItemInHand();
    EntityType entityType = MineableSpawners.getApi().getEntityTypeFromItemStack(item);
    if (entityType == null) {
        return;
    }

    // check if user is bypassing
    Player player = e.getPlayer();
    boolean bypassing = player.getGameMode().equals(GameMode.CREATIVE) || player.hasPermission("mineablespawners.bypass");
    if (bypassing) {
        handlePlacement(player, block, entityType, 0);
        return;
    }

    // check if blacklisted world
    if (plugin.getConfigurationHandler().getList("placing", "blacklisted-worlds").contains(player.getWorld().getName())) {
        player.sendMessage(plugin.getConfigurationHandler().getMessage("placing", "blacklisted"));
        e.setCancelled(true);
        return;
    }

    // check if charging/has enough
    double cost = 0;
    if (plugin.getEcon() != null && plugin.getConfigurationHandler().getBoolean("placing", "charge")) {
        if (!allSamePrice && prices.containsKey(entityType)) {
            cost = prices.getOrDefault(entityType, 0.0);
        } else {
            cost = globalPrice;
        }

        if (!plugin.getEcon().withdrawPlayer(player, cost).transactionSuccess()) {
            String missing = df.format(cost - plugin.getEcon().getBalance(player));
            player.sendMessage(plugin.getConfigurationHandler().getMessage("placing", "not-enough-money").replace("%missing%", missing).replace("%cost%", cost + ""));
            e.setCancelled(true);
            return;
        }
    }

    // place
    handlePlacement(player, block, entityType, cost);
}
 
Example 16
Source File: BlockPlace.java    From FunnyGuilds with Apache License 2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlace(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    Block block = event.getBlock();
    Material type = block.getType();

    Location blockLocation = block.getLocation();
    if (!ProtectionSystem.build(player, blockLocation, true)) {
        return;
    }

    // always cancel to prevent breaking other protection
    // plugins or plugins using BlockPlaceEvent (eg. special ability blocks)
    event.setCancelled(true);

    // disabled bugged-blocks or blacklisted item
    if (!this.config.buggedBlocks || this.config.buggedBlocksExclude.contains(type)) {
        return;
    }

    // remove one item from the player
    ItemStack itemInHand = event.getItemInHand();
    if ((itemInHand.getAmount() - 1) == 0) {
        // wondering why? because bukkit and you probably don't want dupe glitches
        if (Reflections.USE_PRE_9_METHODS) {
            player.setItemInHand(null);
        } else {
            itemInHand.setAmount(0);
        }
    } else {
        itemInHand.setAmount(itemInHand.getAmount() - 1);
    }

    // if the player is standing on the placed block add some velocity to prevent glitching
    // side effect: velocity with +y0.4 is like equivalent to jumping while building, just hold right click, that's real fun!
    Location playerLocation = player.getLocation();
    boolean sameColumn = (playerLocation.getBlockX() == blockLocation.getBlockX()) && (playerLocation.getBlockZ() == blockLocation.getBlockZ());
    double distanceUp = (playerLocation.getY() - blockLocation.getBlockY());
    boolean upToTwoBlocks = (distanceUp > 0) && (distanceUp <= 2);
    if (sameColumn && upToTwoBlocks) {
        player.setVelocity(ANTI_GLITCH_VELOCITY);
    }

    // delay, because we cannot do {@link Block#setType(Material)} immediately
    Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> {

        // fake place for bugged block
        block.setType(type);

        // start timer and return the item to the player if specified to do so
        ItemStack returnItem = event.getItemInHand().clone();
        returnItem.setAmount(1);

        Bukkit.getScheduler().runTaskLater(FunnyGuilds.getInstance(), () -> {
            event.getBlockReplacedState().update(true);
            if (!player.isOnline()) {
                return;
            }
            if (this.config.buggedBlockReturn) {
                player.getInventory().addItem(returnItem);
            }
        }, this.config.buggedBlocksTimer);

    });
}