1.17.x BlockPlaceEvent can't cancel entities

Discussion in 'Spigot Plugin Development' started by Nimblebiter, Jun 27, 2021.

  1. Hey everyone,

    i'm creating a very simple plugin that disables some specific blocks to be placed (tnt ex.)

    blocks like beds, tnt, respawn anchors and work fine.
    however tnt-minecarts and end-crystals don't get cancelled, I believe this is because they are entities but have no clue how to cancel them.


    Code (Java):
     
    public void onBlockPlace(BlockPlaceEvent e) {
    //works
          if(e.getBlock().getType() == Material.TNT) {
                    e.setCancelled(true);
                    return;
              }

    //doesn't work
          if(e.getBlock().getType() == Material.END_CRYSTAL) {
                    e.setCancelled(true);
                    return;
              }
    }
     
    EDIT: also, im not sure how I can disable the use of flint&steel on a block (assuming its not for a nether portal)
     
  2. Use PlayerInteractEvent on that, if Action == Action.RIGHT_CLICK_BLOKC
     
  3. Let me explain step by step:
    1 Create a PlayerInteractEvent
    2 Detect if the Action is Action.RIGHT_CLICK_BLOCK with if(event.getAction() == Action.RIGHT_CLICK_BLOCK)){
    3 If true, get the Item the player is having in his hand, and check if its not null
    4 Check if the item is a (for example) endercrystal and if it is, cancel the event.
     
    • Agree Agree x 2
    • Like Like x 1
  4. You are correct, the reason why it is not firing is because you're spawning an entity instead however, with minecraft it is a vehicle so you can listen with VehicleCreateEvent.
     
  5. Thanks, I already did this but i'm unsure how to check flint&steel when it DOESN'T make a portal. Any tips?
     
  6. Check if the clicked block is obsidian and the item held is flint and steel. If you don't want to prevent fire on obsidian when it does not create a mortal maybe check if any relative blocks are portal blocks in the next tick
     
  7. Check the PortalCreateEvent and check the reason if it is fire.
     
    • Agree Agree x 1
  8. I think you misheard me, im not trying to disable portal creating, im trying to disable everything EXCEPT for portal creating. however I will still incorporate this because I don't flint&steel to be used that isn't for portal creating.


    This helped me with the flint&steel on obsidian/netherrack/soul-soil ty.
     
    • Like Like x 1