Converting a player name string to an object

Discussion in 'Plugin Development' started by unforgiven5232, May 4, 2013.

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


    I have an arraylist that i need to convert to an object to i can send everyone in the arraylist a message, if you know a better way on how to do it, please tell me!


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 1, 2016
  2. Offline


    for(String s : <ArrayList>){
  3. Offline


    Player p = Bukkit.getServer().getPlayer(name);
  4. Offline


    Hey i did .sendMessage(args) but that seperates the lines for each word ex:

    also i tried p.getName() + args and that didnt work :/
  5. BajanAmerican zack6849
    I strongly recommend using getPlayerExact() when you have player.getName() stored because it is faster and most importantly it matches exacly... if your server has similar player names, let's say bob joins the game and its added to the list... then disconnects and bobby joins... then if the loop gets through, the getPlayer("bob") will find "bobby" as a match, which is not what you want since bobby is not the one added to the list, it's bob.

    getPlayer() should only be used when partially matching name inputted by players in commands or stuff like that, not when you need an exact player in a reliable way.

    As said, use getPlayerExact() and for safety's sake check against null before using methods on them.

    Next, if you want the arguments to be built into a single string you can use StringUtils.join(args, ' ', 0, args.length), 0 being the argument to start building from, the first.
  6. Offline


    Can u give an example of the StringUtils.join(args, ' ', 0, args.length), 0
  7. unforgiven5232
    Example of a code example ?! I just gave you a working code, just copy paste it in the message... without the last ", 0" part.
Thread Status:
Not open for further replies.

Share This Page