Solved I think this goes in here??

Discussion in 'General Help' started by Dev_Penguin, Oct 18, 2015.

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

    Dev_Penguin

    Ok. So.. I'm new here. And I think this is the appropriate section for this?? Anyway..

    Sooooooooooooo my friend and I are coding plugins for a public server. And we are trying to declare targets for commands. I have looked everywhere but they don't seem to answer my question. My question is how to declare players without deprecation. My code is:

    Player target = Bukkit.getServer().getPlayer(args[0]);

    and they're all deprecated.. Is there any way to define targets using 1.8 code without deprecation? Or is it just needing an @SupressWarnings("deprecation")

    Any advice?
     
  2. Offline

    oceantheskatr

    Deprecation is fine, just suppress as you have. It just means that generally there is a better/newer way to do the same thing, though I don't know if there's a better way than what you're doing.

    (Make sure to do null checks first :))
     
  3. Offline

    Dev_Penguin

    Although we are experienced with coding and such.. May I ask what null checks are? I have not seen this mentioned anywhere.
     
  4. Offline

    teej107

    @Dev_Penguin
    The reason for deprecation is to raise awareness about using UUIDs.
     
  5. Offline

    oceantheskatr

    No problem.

    In this instance, it's more so checking if the player exists before using it.
    You'd do something like this before saying Player p = Bukkit.getServer().getPlayer(args[0]);

    Code:
    if (Bukkit.getServer().getPlayer(args[0]); == null) {
        sender.sendMessage(ChatColor.RED + "Player not found!");
        return true;
    }
    Player p = Bukkit.getServer().getPlayer(args[0]);
    // Do stuff

    The above would check if the player is null, and if so, say that the player wasn't found and then return. It would be null if the player specified hasn't joined the server before, which could also mean the player doesn't exist.
     
  6. Offline

    Dev_Penguin

    Thanks, @oceantheskatr!
     
  7. Offline

    oceantheskatr

Thread Status:
Not open for further replies.

Share This Page