Solved Playernames auto-complete for offline players

Discussion in 'Plugin Development' started by InflamedSebi, Mar 2, 2013.

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

    InflamedSebi

    i need a way to get all matching playernames from a given partial name (case insensitive!) ...

    Bukkit.matchPlayer() only returns online players
    getOfflinePlayer() is like getOfflinePlayerExact() and needs the full name

    and I have no idea, how to get the matches from getOfflinePlayers()

    someone got a solution?
     
  2. Offline

    gomeow

    Afaik impossible
     
  3. Offline

    InflamedSebi

    i know its not impossible ... because i can get a list of the offline players ... and there must be an algorithm for getting all matches from a list (otherwise there couldnt be the matchPlayer() method ... )

    but i m not able to find the sourcecode of that algorithm ...
     
  4. Offline

    gomeow

    Then you could always look through bukkit source code
     
  5. Offline

    InflamedSebi

    i already tried ... but i don't know how to find the sourcecode ... the server.java just contains the abstract body of that and idk where to look for the real code ...
     
  6. surely it's simply something like this:

    Code:
    String partialName = "PlayerNa";
    OfflinePlayer array[] = getServer().getOfflinePlayers();
    List<Player> matchedOfflinePlayers = null;
     
    for (int x = 0; x < array.length; x++) {
     
    String name = array[x].getName();
    if (name.contains(partialName)) {
     
    matchedOfflinePlayers.add((Player) getServer().getOfflinePlayer(name));
     
    }
     
    }
     
  7. Offline

    InflamedSebi

    all i need is a check if String1 contains String2 but case insensitive!

    Code:
    one.toLowerCase().contains(two.toLowerCase())
    this is working but maybe inefficient ...
     
  8. Offline

    gomeow

    InflamedSebi
    That's a bit different than what you originally asked for

    Code:java
    1. public boolean containsIgnoreCase(Collection<String> l, String s) {
    2. Iterator<String> it = l.iterator();
    3. while(it.hasNext()) {
    4. if(it.next().equalsIgnoreCase(s) return true;
    5. }
    6. return false;
    7. }



    Edit: Oops, didnt see you want string contains string:

    Code:java
    1. if(s.length() != s.replaceAll("(?i)+"yourStringHere","").length()) {
    2. //s contains 'yourStringHere'
    3. }
     
Thread Status:
Not open for further replies.

Share This Page