Return the correct "city" a player is in?

Discussion in 'Plugin Development' started by DiamGamingWTF, Oct 15, 2014.

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

    DiamGamingWTF

    I am trying to obtain the city name that the player is located in:
    Code:
    CityOne:
        Players:
            ad2738UUID
    CityTwo:
        Players:
            ad348UUID
    
    But whenever I attempt to return "ad348", it will return the TOP city name in the config file (which is CityOne in the example). Is there a way to return the correct city name (CityTwo)?

    EDIT: Modified post to make it more understandable of what I need.
     
  2. Offline

    Hawktasard

    DiamGamingWTF
    I never use Yaml, But I guess you can make a list of the cities and then do something like;
    Code:java
    1. List<String> cities = getConfig().getStringList("cities");
    2.  
    3. for(String s : cities) {
    4. System.out.println(s);
    5. }

    That would print out all the cities, You could then use that to get the "cityname.players.whatever" using the "s" thing.
     
  3. Offline

    DiamGamingWTF

    Hawktasard I don't think I explained well enough. (I don't use Yaml either, this is just the config result). The issue is that when I get a players city it seems to return the top city on the entire list. For example:
    Code:
    CityOne:
        Players:
            abc123UUID
    CityTwo:
        Players:
            ad348UUID
    If I try and get the city that ad348 is in it will return CityOne, how do I fix that so it returns CityTwo? (I hope this is better explained). This may seem a lot different to what I posted on the main post, but that's because I am not good when it comes to asking for assistance...

    Ps. It's also not just for the Players. It's for anything I wish to return. So if there was Players: blah and Something: blah, it will still return the highest city on the list for it.
     
  4. Offline

    teej107

  5. Offline

    DiamGamingWTF

  6. Offline

    fireblast709

    DiamGamingWTF normally one would loop over all cities, and loop over all the players in the cities.
    Code:
    // 'needle' is just the search term (from searching a 'needle' in a 'haystack'
    function(needle)
    {
        foreach city in cities
        {
            foreach player in city
           {
               if(player equals needle)
                    return city
            }
        }
        return null
    }
     
  7. Offline

    DiamGamingWTF

    fireblast709 I am pretty new with this kind of stuff, this is all I could think of and it comes up with errors.
    Code:java
    1. public Team getTeam(Player p) {
    2. for (Team t : getConfig()) { //<-- Can only iterate over array
    3. for (Player pl : getConfig().get(Team.teamName + ".Players.")) { //<-- Can only iterate over array
    4. if (pl == p) {//<-- Not sure if correct
    5. return t;
    6. }
    7. }
    8. }
    9. }

    This is most likely completely incorrect.
     
  8. Offline

    fireblast709

    DiamGamingWTF assuming org.bukkit.scoreboard.Team:
    • Config cannot return Teams, you should use city names (Strings)
    • Config cannot return Players, you should use UUIDs
     
  9. Offline

    DiamGamingWTF

    The Team I am using is nothing to do with scoreboards. It's a different class.
     
  10. Offline

    fireblast709

    DiamGamingWTF Unless your Team is ConfigurationSerializable, then I doubt it will return a Team object :p
     
Thread Status:
Not open for further replies.

Share This Page