Disable breaking specific block

Discussion in 'Plugin Development' started by GlPlays, Aug 13, 2021.

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

    GlPlays

    how to disable breaking enchanted table unless they in creative ?
     
  2. Offline

    KarimAKL

    @GlPlays Listen to the BlockBreakEvent, then check the type of block and the player's game mode.
     
  3. Offline

    xpaintall

    Code:
     @EventHandler
        public void onBreak(BlockBreakEvent event) {
            Player player = event.getPlayer();
            if(!(player.getGameMode() == GameMode.CREATIVE)) {
                if(event.getBlock().getType() == Material.ENCHANTMENT_TABLE) {
                    event.setCancelled(true);
                }
            }
        }
    I hope this helps!
     
  4. Offline

    GlPlays

    thank you that works
     
    Last edited: Aug 13, 2021
Thread Status:
Not open for further replies.

Share This Page