Basic question on Stopping Block Placement

Discussion in 'Plugin Development' started by chriztopia, Aug 18, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    chriztopia

    The most basic question how do u stop block placement? Im not having a good programming day.

    I want to stop players from being able to placeblocks but they are allowed to use redstone.
     
  2. Offline

    kyle1320

    Code:
    @EventHandler
    public void onPlace(BlockPlaceEvent event) {
            event.setCancelled(true);
    }
    Seems to work just fine for me :)

    EDIT: Oh but you want them to be able to use redstone? Sorry haha thought you tried something but it still let them place redstone. Hold on.. Okay, try something like this:

    Code:
    @EventHandler
        public void onPlace(BlockPlaceEvent event) {
            if (isRedstone(event.getBlock())){
                event.setCancelled(false);
            }else {
                event.setCancelled(true);
            }
        }
     
        private boolean isRedstone(Block block) {
            if(block.getType() == Material.REDSTONE_WIRE ||
                block.getType() == Material.REDSTONE_TORCH_ON ||
                block.getType() == Material.DIODE_BLOCK_OFF){
                return true;
            }else {
                return false;
            }
        }
     
  3. Offline

    edragy

    Are you trying to stop lever interaction and stuff (buttons levers and stuff like that) if thats what you want to block you have to use leverInteractEvent and buttonInteractEvent. Cancell those
     
  4. Offline

    turtlelover111

    I Was Wondering If You Guys Could Help Me, In My Plugin I Want
    Hi I Was Wondering If You Could Help Me With This, I Want To Disable Redstone Completely, I Wrote This Could But I Can Still Place Redstone...


    @EventHandler
    public void onPlayerBlockPlace (BlockPlace event) {
    Player p = event.getplayer();
    Block block = event.getPlacedBlock();
    if(((Object) block).getTypeId()==55){
    event.getPlayer().sendMessage("You are not allowed to place this!");
    event.setCancelled(true);
     
Thread Status:
Not open for further replies.

Share This Page