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


    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


    Afaik impossible
  3. Offline


    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


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


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

    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


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

    this is working but maybe inefficient ...
  8. Offline


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

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

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

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

Share This Page