1.15.2 Make a block unbreakable

Discussion in 'Spigot Plugin Development' started by Jaume, May 11, 2020.

  1. Hello, I need to make a block (well, some blocks) completely unbreakable. What events should I listen to and cancel? I haven't played Minecraft in a long time and I'm afraid there might be new mechanics that I don't know about. I also need to make sure it can't be moved in any way or broken via exploits/glitchs.
  2. BlockBreakEvent#setCancelled
    Though, it only works if a player is the one breaking the block.
    If you want to completely disable this block from changing material you could make a repeating task and call Block#setType
  3. BlockPistonEvent#setCancelled
  4. I'm aware of BlockPistonEvent and BlockBreakEvent, I was asking how to prevent more creative ways to break blocks (in case they exist). Or is it really enough with cancelling explosions, pistons and block break events? Is it possible to increase the "toughness" of a block so high that it is effectively like bedrock? If that was possible, I wouldn't even need to listen to any event.
  5. I'm not sure of a way to change a blocks toughness, I think that is determined by the material.
    You could take a look at BlockEvent and just go through all the events and see which ones can destroy a block.
  6. You can find all block events in the java docs.
  7. I think by other ways they mean ways like commands and WE
  8. I'm sorry, what I need is for survival players to not be able to break/move/modify the block in any possible way.
  9. You can use WorldGuard with worldedit to make areas not breakable
  10. 1. Don't respond to old threads
    2. Its called Plugin Developing, not Plugin Downloading ;)
    • Agree Agree x 3
  11. I don't like responding to old threads, but in case someone gets stuck with the same problem:
    1. Listen to BlockBreakEvent and BlockPistonExtendEvent
    2. Check for the gamemode with Player#getGameMode()
    3. If it's GameMode.SURVIVAL, then cancel the event.