How can i make a created exsplotion to only blow up spawners?

Discussion in 'Spigot Plugin Development' started by Sykerpateion, May 25, 2018.

  1. Hello, im traying to make created exsplotion to only blow up Spawners. But i just know how to stopp all of the blocks to exsplode up. Can someone help me??
  2. I would make my own "explosion" it will iterate over an amount of blocks in a radius and checks if it's a spawner, and if it's a spawner it breaks.
  3. Theres a better way to handle that.

    This is what I would do:
    • Create a custom explosion and set with a hashmap it's explosion location and who made this.
    • Listen to BlockExplodeEvent and check if the location is equal to your custom explosion location. Also, if it's a TNT, no need to create a hashmap unless this tnt is custom and you should focus on EntityExplodeEvent since TNT is an entity .
    • BlockExplodeEvent and EntityExplodeEvent has a method to get the block list that explosion destroyed by looping through it.
    • Java.util.List<Block> blockList()
    • Then you could just block breaking all blocks and allow it to break only the specific ones(Spawners).
  4. This isn't a better way, just a lot slower and involves a lot more event callers. My way is simple lightweight and can be customized. Yours just has pointless steps that in the end lead back to the same result as mine.
  5. If op knows how to iterate through all that sure, but you're right, your way is better than mine.
    • Optimistic Optimistic x 1