Solved Entity Selectors

Discussion in 'Plugin Development' started by Zimboni, Feb 10, 2016.

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

    Zimboni

    So, I have a command where the user should be able to target an entity or multiple entities using an entity selector (like @e or @p).
    Those entities don't have to be players, but they of course can be.
    So does anyone have a good way for turning that into an Entity[] array?
    I already searched myself and didn't find anything and now I don't know if that doesn't work or I just didn't find it.
     
  2. Offline

    teej107

    Get a Collection of entities and call toArray(/*array here*/) on it.
     
  3. Offline

    Zimboni

    @teej107
    Ok but what sort of collection? All entities on the server?
    From what you said I guess you mean a collection of all entities that match the entity selector but how should I get that?
     
  4. Offline

    teej107

    @Zimboni There is a method in World to get all the entities. It returns a List I think so it would be a List, that type of Collection.
     
  5. Offline

    Zimboni

    @teej107
    I'm still not so familiar with collection and list stuff in Java so could you send me a code for a method which takes an entity selector (String) as an argument and returns an array of entities?
     
  6. Offline

    teej107

  7. Offline

    Zimboni

  8. Offline

    teej107

    @Zimboni @p just get the nearest player. Just loop through all the players in the world and compare their distances from yours. @r just gets a random entity. For the arguments inside the brackets, you'll need to parse it and then you should be able to pretty much figure it out.
     
    Zimboni likes this.
  9. Offline

    Zimboni

Thread Status:
Not open for further replies.

Share This Page