Solved List entity + damage

Discussion in 'Plugin Development' started by klofno1, Jul 19, 2013.

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

    klofno1

    Hi I'd like my plugin to check for nearest entity and if the entity is not a player, it gets killed. After it is killed the player who started the check, via a command , and all the nearby players in a 10,10,10 ratio have to be healed.

    In short : a mob sacrifice used for healing

    Could anyone explain me how?

    I was thinking about this :

    Code:java
    1. for(LivingEntity e : Bukkit.getWorld("world").getLivingEntities()){
    2. List<Entity> entitylist = e.getNearbyEntities(10,10,10);
    3. for(Entity en : entitylist){
    4. if(en instanceof Entity){
    5. //add code to kill entity
    6. // add code to heal the player + nearby players
    7. }
    8. }
    9.  
     
  2. Offline

    CubieX

    Your approach is not that bad.
    Get all near entities around the checking player (no need to cycle through all entities in a world, so the first for-loop is not necessary).
    The checking player can be fetched in the onCommand method, as he is the sender.
    Then check if there is a living entity nearby which is NOT a Player (!(instanceof Player)), and if so, kill it and omit this check for the rest of the loop.
    In the same loop, you gather all players nearby in an ArrayList for example, and after the loop
    has been completed, heal all gathered players nearby by settIng their health.

    EDIT:
    What event is beeing used here?
    Seems like the player is not using a command to start the check.

    In this case, you can get the checking player by using e.getPlayer()
    Then do your getNearbyEntities() and then use the for-loop to check and gather players around to heal and check for a non-player entity to kill.
     
  3. Offline

    Terraquis

    Hey, I'm trying to do sort of the same thing; could you post an example? Thanks.
     
  4. Offline

    xTrollxDudex

    Do you realize how old this thread is? -_-

    OP was last seen almost 2 months ago...
     
Thread Status:
Not open for further replies.

Share This Page