Getting the Location/Block of an Explosion

Discussion in 'Plugin Development' started by The_Guest, Jan 18, 2011.

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

    The_Guest

    I've been trying different ways of doing this an every way ends up as a NullPointerException.

    Here are a few examples of what I've tried:

    Code:
    Block block = (Block)event.getEntity();
    block.getX();
    
    also:

    Code:
    event.getEntity().getLocation().getBlockX();
    also:

    Code:
    event.getEntity().getLocation().getX();
    also:

    (I actually need to get a block at this location, but it still doesn't work...)
    Code:
    event.getEntity().getWorld().getBlockAt(event.getEntity().getLocation().getBlockX(), event.getEntity().getLocation().getBlockY(), event.getEntity().getLocation().getBlockZ());
    also:

    Code:
    event.getEntity().getLocation().getWorld().getBlockAt(event.getEntity().getLocation().getBlockX(), event.getEntity().getLocation().getBlockY(), event.getEntity().getLocation().getBlockZ());


    I imagine its doing this because the PrimedTnT is the entity and doesn't have a position, but I'm not sure why the event location doesn't work...

    Before you ask, everything else is called correctly, no syntax errors, etc. (I can get messages sent to me triggered by the explosion.)

    I at first tried to get a block from the index, but got out of bounds errors...

    How would you get the X/Y/Z coordinates in this situation?
     
  2. Offline

    Taco

    Hmm... Maybe get the coordinates of TnT as it is being hit?
     
  3. Offline

    The_Guest

    Good idea, although I need to be able to cancel the event too, so if there is a way to get the location without using 2 hooks, that would be best. Anyone else have an idea?
    --- merged: Jan 19, 2011 6:03 PM ---
    Edit: I got a block from the array, which will work as a temporary fix, but if there is a way to get the event location, it would be great if I could get that answer. Thanks!


    EditII: Never-mind, I'll just use the block array that is given to check for block types. Still, the ability to get the event location is needed (or at-least the TNT location), and shouldn't be left out of Bukkit!

    Actually I realized the "block list" will try to match the entire block instead of blockIds, so I'm still looking for an answer!
     
Thread Status:
Not open for further replies.

Share This Page