Solved EntityExplodeEvent help

Discussion in 'Spigot Plugin Development' started by MiMiMiEnot, Feb 28, 2020.

  1. Hi all

    l wanna to to remove some blocks in EntityExplodeEvent something like that
    Code (Java):

    @EventHandler
    public void onWitherAndTNT(EntityExplodeEvent e) {
        HashMap<Material, Integer> privatblocks = Settings.getRgsblocks();
        List<Material> blockedblocks = new ArrayList<>();
        for (Map.Entry<Material, Integer> entry : privatblocks.entrySet()) {
            blockedblocks.add(entry.getKey());
        }
        if (!e.blockList().isEmpty()) {
            for (int i = 0; i < e.blockList().size(); i++) {
                if (blockedblocks.contains(e.blockList().get(i).getType()) && Builder.isPrivateBlock(e.blockList().get(i))) {
                    e.blockList().remove(i);
                } else if (e.blockList().get(i).getState() instanceof CreatureSpawner) {
                    Block b = e.blockList().get(i);
                    if (PrivateSetting.inPrivat(b.getLocation()) != null) {
                        e.blockList().remove(i);
                    }
                }
            }
        }
    }
     

    Thats works but if wither are spawned and explode - block destroyed

    Maybe l must to use another event?
     
    • Agree Agree x 1
  2. The event doesn’t trigger when the wither explodes a block?
     
  3. When the wither destroy a block the BlockBreakEvent its called,use that to cancel it
     
  4. something like that.. i not good understood


    BlockBreakEvent Called when a block is broken by a player
     
  5. Did you try debugging it
     
  6. l do that now
     
    • Agree Agree x 1
  7. It's an EntityChangeBlockEvent, so it can be called by any entity that moves (pig, sheep, zombie). On a busy server is this event called a lot, make sure it's an efficient code to reduce lagg.
     
  8. yeah, thank you, i check if that block is a block what i need and after that do all what i need
     
  9. If your problem is solved, would you like to set the thread status to 'solved'? If you have any more questions, feel free to ask :)