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: Code: for (Entity e : loc.getChunk().getEntities()) { if(e.getLocation().distance(loc) < 1.0) { if (!e.equals(player)) { e.something 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() {
@holy137 THAT INDENTATION! 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.
@Zombie_Striker 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.
@Zombie_Striker Use .equals when comparing things like objects and strings, == is most commonly used for enums.
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