Get a player by name

Discussion in 'Plugin Development' started by skyshiny99, Jul 6, 2014.

Thread Status:
Not open for further replies.
  1. Hi,
    with Minecraft 1.6.4 I could use sender.getServer().getPlayer(args[0]), but this method is now deprecated and I must use an UUID now. Is there still a way to get a player by a given name? (I may store the UUIDs of all players when they login, but I don't want to do it at this way)

    Update: I've tried an other way:
    Player p = null;
    for(Player p2 : Bukkit.getOnlinePlayers()) {
    if(p2.getName().equalsIgnoreCase(args[0]) p = p2;
    if(p==null) {
    sender.sendMessage("§cThe player could not be found.");
    return true;
    But this also doesn't work:
    [12:28:46 INFO]: skyshiny issued server command: /titleshow skyshiny A
    [12:28:46 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'titl
    eshow' in plugin TitleShow v1.0
    at org.bukkit.command.PluginCommand.execute( ~[cb.
    at org.bukkit.command.SimpleCommandMap.dispatch(
    0) ~[cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServe ~[cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerCon [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(
    :817) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(
    :28) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.NetworkManager.a(
    ) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [cb.j
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(
    67) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(
    60) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(
    58) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    :469) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    28) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljav
    at ~[?:?]
    at org.bukkit.command.PluginCommand.execute( ~[cb.
    ... 13 more

    Line 33 which causes the error contains:
    for(Player p2 : Bukkit.getOnlinePlayers()) {

    And another update: Using the deprecated method causes the same error as above.

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


    It is not because of how you get the player. Paste the full command on pastebin
  3. Offline


    I have pointed out the problem.

    bukkit recently changed from a Player[] to a Collection<Player> if I recall correctly.
    The problem could be building with a new version of bukkit, but running against an older CraftBukkit
Thread Status:
Not open for further replies.

Share This Page