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(PluginCommand.java:46) ~[cb.
    jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    0) ~[cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServe
    r.java:701) ~[cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:956) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java
    :817) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :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(NetworkManager.java:157
    ) [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
    ar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:6
    67) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2
    60) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5
    58) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java
    :469) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6
    28) [cb.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljav
    a/util/Collection;
    at com.live.nicilas0301.TitleShow.onCommand(TitleShow.java:33) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cb.
    jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    ... 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

    AoH_Ruthless

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

    Sabersamus

    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