org.bukkit.event.block.BlockMultiPlaceEvent Java Examples

The following examples show how to use org.bukkit.event.block.BlockMultiPlaceEvent. 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: LWCBlockListener.java    From Modern-LWC with MIT License 7 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
    LWC lwc = plugin.getLWC();
    Block block = event.getBlock();

    if (block.getType().name().contains("_BED")) {
        for (BlockState state : event.getReplacedBlockStates()) {
            Protection protection = lwc.findProtection(state);

            if (protection != null) {
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
Example #2
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onBlockPlace(final BlockPlaceEvent event) {
  if (event instanceof BlockMultiPlaceEvent) {
    for (BlockState oldState : ((BlockMultiPlaceEvent) event).getReplacedBlockStates()) {
      callEvent(event, oldState, oldState.getBlock().getState(), event.getPlayer());
    }
  } else {
    callEvent(
        event, event.getBlockReplacedState(), event.getBlock().getState(), event.getPlayer());
  }
}
 
Example #3
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onBlockPlace(final BlockPlaceEvent event) {
    if(event instanceof BlockMultiPlaceEvent) {
        for(BlockState oldState : ((BlockMultiPlaceEvent) event).getReplacedBlockStates()) {
            callEvent(event, oldState, oldState.getBlock().getState(), event.getPlayer());
        }
    } else {
        callEvent(event, event.getBlockReplacedState(), event.getBlock().getState(), event.getPlayer());
    }
}
 
Example #4
Source File: CreativeModeListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockMultiPlace(BlockMultiPlaceEvent e) {
    // Cancel any block places if SelectClickType is set
    ClickType clickType = ClickType.getPlayerClickType(e.getPlayer());
    if (clickType instanceof SelectClickType)
        e.setCancelled(true);
}
 
Example #5
Source File: ShopItemListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onMultiBlockPlace(BlockMultiPlaceEvent e) {
    for (BlockState blockState : e.getReplacedBlockStates()) {
        Block below = blockState.getBlock().getRelative(BlockFace.DOWN);

        if (shopUtils.isShop(below.getLocation())) {
            Shop shop = shopUtils.getShop(below.getLocation());
            if (shop.getItem() != null) {
                shop.getItem().resetForPlayer(e.getPlayer());
            }
            e.setCancelled(true);
        }
    }
}
 
Example #6
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerBlockPlace(final BlockMultiPlaceEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("DEBUG: " + e.getEventName());
        if (e.getPlayer() == null) {
            plugin.getLogger().info("DEBUG: player is null");
        } else {
            plugin.getLogger().info("DEBUG: block placed by " + e.getPlayer().getName());
        }
        plugin.getLogger().info("DEBUG: Block is " + e.getBlock().toString());
    }
    if (Settings.allowedFakePlayers.contains(e.getPlayer().getName())) return;

    // plugin.getLogger().info(e.getEventName());
    if (IslandGuard.inWorld(e.getPlayer())) {
        // This permission bypasses protection
        if (e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        Island island = plugin.getGrid().getProtectedIslandAt(e.getBlock().getLocation());
        if (island == null) {
            if (!Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
                Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                e.setCancelled(true);
            }
            return;
        }
        // Island exists
        if (island.getIgsFlag(SettingsFlag.PLACE_BLOCKS) || island.getMembers().contains(e.getPlayer().getUniqueId()))  {
            // Check how many placed
            //plugin.getLogger().info("DEBUG: block placed " + e.getBlock().getType());
            String type = e.getBlock().getType().toString();
            if (!e.getBlock().getState().getClass().getName().endsWith("CraftBlockState")
                    // Not all blocks have that type of class, so we have to do some explicit checking...
                    || e.getBlock().getType().equals(Material.REDSTONE_COMPARATOR_OFF)
                    || type.endsWith("BANNER") // Avoids V1.7 issues
                    || e.getBlock().getType().equals(Material.ENDER_CHEST)
                    || e.getBlock().getType().equals(Material.ENCHANTMENT_TABLE)
                    || e.getBlock().getType().equals(Material.DAYLIGHT_DETECTOR)
                    || e.getBlock().getType().equals(Material.FLOWER_POT)){
                // tile entity placed
                if (Settings.limitedBlocks.containsKey(type) && Settings.limitedBlocks.get(type) > -1) {
                    int count = island.getTileEntityCount(e.getBlock().getType(),e.getBlock().getWorld());
                    if (Settings.limitedBlocks.get(type) <= count) {
                        Util.sendMessage(e.getPlayer(), ChatColor.RED + (plugin.myLocale(e.getPlayer().getUniqueId()).entityLimitReached.replace("[entity]",
                                Util.prettifyText(type))).replace("[number]", String.valueOf(Settings.limitedBlocks.get(type))));
                        e.setCancelled(true);
                        return;
                    }
                }
            }
            return;
        }
        // Outside of protection area or visitor
        Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
        e.setCancelled(true);
    }
}