Solved Target players with specific item

Discussion in 'Plugin Development' started by Higgsboson728, Oct 30, 2015.

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

    Higgsboson728

    For my plugin, I want mobs (spawned by the plugin) to attack players who are holding specific items. Can anyone willing to help post the code please? Thanks.
     
  2. Offline

    RoboticPlayer

    I won't give you code, but I can tell you how to do it. First, create a local variable which spawns the mob you want. Then, loop through the nearby entities with the Entity#getNearbyEntities() method. If the entity isn't a player, ignore it. Then, get the player who is the nearby entity and check Player#getItemInHand().
     
  3. Offline

    Higgsboson728

    Thanks for replying.
    May I ask how you loop through all entities on the server? Internet isn't helping me.

    @henderry2019
     
  4. Offline

    RoboticPlayer

    @Higgsboson728 Why do you need to loop through all entities on the server? Just loop through the nearby entities of the mob that you spawned. If you have to loop through all entities on the server, use the World#getEntities() method.
     
  5. Offline

    Zombie_Striker

    Not happening on this forum. We don't give out code.

    If you mean how to get all the entities to loop through, use Entity.getNearbyEntities(x distance, y distance, z distance). If you don't know how to loop, learn basic java, since that's a part of Java that you should learn early on.
     
  6. Offline

    Higgsboson728

Thread Status:
Not open for further replies.

Share This Page