Particle Damage

Discussion in 'Plugin Development' started by holy137, Oct 28, 2015.

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


    I need help with making my particles do damage.
    I tried alot but i could not figure it out.
    i got this code from a tutorial:
                                    for (Entity e : loc.getChunk().getEntities()) {
                                        if(e.getLocation().distance(loc) < 1.0) {
                                            if (!e.equals(player)) {
    I tried to some stuff with it but it didnt work.
    The event is a playerinteract event.
    Its located in the new bukkit runnable - public void run() {
  2. Offline



    Why not use e.getNearbyEntities(x distance,y distance, z distance)?

    Don't use e.equals. It can throw a NPE if the entity is null. Use == instead

    BTW, it would be nice to see how this code is being used.
  3. Offline


    It will not throw an NPE, if the entity "is null" then it wouldn't be in that collection in the first place.

    edit: As the posts below mine have said, you should use equals when comparing objects (although not needed in this instance). It could throw an NPE if "e" was null but you can just do !player.equals(e) to make sure that doesn't happen.
    Last edited: Oct 28, 2015
  4. Offline


    @Zombie_Striker Use .equals when comparing things like objects and strings, == is most commonly used for enums.
  5. What is wrong with that? And the code tags can also mess up indentation
    Because a particle is not an entity
    No, just no. == is for comparing instances or singleton stuff, one needs to make null checks and then use equals
Thread Status:
Not open for further replies.

Share This Page