Enabling a Certain Explosion

Discussion in 'Plugin Development' started by Nashor, Mar 27, 2013.

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

    Nashor

    Hello everyone. Today I ask you a question about explosions. I want my plugin to be able to create a working explosion without any interruption from other plugins which disable explosions. To create the explosions, I am using the world.createExplosion() method. If possible, how do I make it so that certain explosions created using this method are not disabled? Thank you.
     
  2. Offline

    Technius

    Explosions created by world.createExplosion have null entities. You can basically do something like this:
    Code:
    @EventHandler
    public void yourEvent(EntityExplodeEvent event)
    {
         if(event.getEntity() == null)return;
        
         //Run your code here
    }
    
     
  3. Offline

    Nashor

    Thanks for the response. I did see that the entity was null but didn't think of this. I just have 2 questions about this though: Would this listener affect other plugins (i.e. let another plugin which uses world.createExplosion() to create its explosion unhindered) or just this one? Also, I suppose the code in your if statement would just be e.setCancelled(false) or am I wrong?
     
  4. Offline

    Technius

    No, it will only affect entity-created explosions.

    The if statement can be translated to something like this:
    Code:
    if the entity is null, then cease the execution of this method
    
     
  5. Offline

    Nashor

    Here is what I will probably do:
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onEntityExplode(EntityExplodeEvent e) {
            Entity entity = e.getEntity();
            if (entity == null) {
                e.setCancelled(false);
            }
        }
    I may change the priority to high or normal if they work. Thanks for the responses.
     
Thread Status:
Not open for further replies.

Share This Page