Get world entities?

Discussion in 'Plugin Development' started by algo160, Apr 7, 2013.

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

    algo160

    First of all, treat me as a jNoob with decent C++ Experience:

    I am making a method that finds all Primed TNT entities and removes them.
    My method has one parameter, world (Type World).

    How should i do this? Please, if you are going to give me code, give me a explanation :) I want to learn so i don't have to ask so often.

    jNoob JavaNoob = Algo160;
     
  2. World object has a getEntities() method which gives you a list of entities... you can loop through that and check if entity is instanceof TNTPrimed then do whatever with it.

    I hope you're using an IDE because it greatly helps, expecially by showing you available methods.

    Unless you're trying to cleanup primed TNTs on command, using this to prevent TNTs from blowing up is a really bad way, if you want to prevent TNTs from blowing up then just listen to the ExplosionPrimeEvent.
     
  3. Offline

    algo160

    Digi It does remove the tnt and it listens to ExplosionPrimeEvent
    It only prevents tnt from blowing up..... I need the code to. Cant do loops :(

    Err What did i just say? Makes no sense

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  4. algo160
    I agree on the 2nd post, now rephrase that =)
     
  5. algo160

    You should start off with a bukkit baiscs tutorial ;)
     
  6. Offline

    algo160

    So i am working on a plugin (TNT H8R) and

    2 methods:
    HateWrapper();
    Calls hate(); on all the worlds.
    Hate();
    Loops and gets entities of the world, if any TNT primed it removes them (before it explodes i hope)

    Listeners:
    onPrimed
    onBlockInteract

    Both call HateWrapper();

    Hellsing Tried the one on the BukkiWikki (BukkitWiki as most call it).
    Not helpful. What do you think i should look at?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  7. Use the ExplosionPrimeEvent and then the following:

    Code:
    if (event.getEntity() instanceof TNTPrimed)
        event.setCancelled(true);
     
  8. Offline

    algo160

    Mmk That all? I thought it would be harder to do.
     
  9. Nope, this will block all tnt explosions from every world. If you want to block it per world, use

    if (event.getEntity.getWorld().equals(world))
    // Bla bla bla
     
  10. Offline

    algo160

    Hellsing Wow, didn't think i could do that. I'll look at the Doxygen better nextime :)
     
Thread Status:
Not open for further replies.

Share This Page