Code:
public int getPlayerID(String value) {
// Loop through all the players.
for(Player player : Server.playerHandler.players) {
if(player.playerName.equalsIgnoreCase(value)
// If the username mathes, return this players' ID.
return player.playerId;
}
// Otherwise, no player could be matched, return -1. (like default value or something).
return -1;
}
This loops through your array containing all your players, while it's looping, it checks if the current player's(the one thats being looped through) username is the same as the one you put in as your parameters(like getPlayerID("bob")), if so, it returns this player's ID.
This could work with anything, like if you want it to check for like the players IP, you would put player.connectedFrom or something. (Instead of player.playerName).
Hope this helps