stop players breaking a block!

Discussion in 'Plugin Development' started by iPhysX, Apr 1, 2011.

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

    iPhysX

    Code:
    public void onBlockBreak(BlockBreakEvent event) {
        Player player = event.getPlayer();
                Block block = event.getBlock();
    
                if(block.getType() == Material.CHEST && (KeepChest.Permissions.has(player, "keepchest.chest"))){
                }
                if(block.getType() == Material.CHEST && (!KeepChest.Permissions.has(player, "keepchest.chest"))){
    
                    player.sendMessage(ChatColor.RED + "Only admins can destroy chests!");
     
                }
    That is my code so far.
    At the moment, if the player doesnt have the permission it tells them they cant destroy a chest.
    I have been playing around and i can't seem to find how to stop the block being destroyed.
    Any help would be appreciated!
     
  2. Offline

    ssell

    Use

    Code:
    event.setCancelled( true );
    The block will still 'break' client side, but will quickly respawn since nothing actually happened.
     
  3. Offline

    iPhysX

    event.setcancelled(true)

    I don't know how i missed that :D

    thanks for this!
    I realised before i read your post but it was very helpful!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
Thread Status:
Not open for further replies.

Share This Page