.getPlayer is crossed out

Discussion in 'Plugin Development' started by EthanWu13, Aug 7, 2014.

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

    EthanWu13

    I am trying to make a plugin that you /hurt and it hurts you. But I keep on getting errors and I think it is the getPlayer(args[1]), the whole thing is underline and the .getPlayer is crossed out.


    Code:java
    1. package me.EthanWu13.XtremeJerks;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class XJ extends JavaPlugin
    13. {
    14. Logger myPluginLogger = Bukkit.getLogger();
    15. int i;
    16.  
    17. @Override
    18. public void onEnable()
    19. {
    20.  
    21. }
    22.  
    23. @Override
    24. public void onDisable()
    25. {
    26.  
    27. }
    28.  
    29. public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args)
    30. {
    31. if(theSender instanceof Player)
    32. {
    33. Player player = (Player) theSender;
    34.  
    35. // hurt <PLAYER> <AMOUNT>
    36.  
    37. if(commandLabel.equalsIgnoreCase("hurt"))
    38. {
    39. if(Bukkit.getPlayer(args[1]) != null)
    40. {
    41. try
    42. {
    43. Player playerToHurt = Bukkit.getPlayer(args[1]);
    44. double damageAmount = Double.parseDouble(args[1]);
    45. playerToHurt.damage(damageAmount);
    46. playerToHurt.sendMessage(ChatColor.RED + "You were hurted by " + player.getName());
    47. }
    48. catch(NumberFormatException exception)
    49. {
    50. player.sendMessage(ChatColor.RED + args[1] + " is not a valid number!");
    51. }
    52. }
    53. else player.sendMessage("Can't Find Player" + args[0]);
    54. }
    55.  
    56.  
    57.  
    58.  
    59.  
    60. }
    61.  
    62. return true;
    63. }
    64.  
     
  2. Offline

    Dubehh

    The method
    Code:java
    1. getPlayer(String)
    is deprecated.
    So I think you mean a 'warning', not an error :).

    I am not sure what deprecated actually means, but it warns you for using that certain method for future builds.
    On this point, I think you can use getPlayer(String) without problems. But I am not the java legend, and someone might quote me on this :p

    EDIT: Can you post the errors please? (stacktrace)
     
  3. Offline

    ZodiacTheories

    EthanWu13

    Don't worry about it, the warning will be removed in future updates, your code will still run fine (even though I haven't looked at it).
     
  4. Offline

    artish1

    EthanWu13
    Bukkit is going to be using UUID's (Because minecraft is going to be using UUID's instead of String-type names/identifiers (Due to minecraft going to allow people to change their names)), so they deprecated the Bukkit.getPlayer(String name); method to warn people to change from using String identifiers to UUID's (.getUniqueID), although even if it is deprecated, it does not mean it won't work/is broken.
     
Thread Status:
Not open for further replies.

Share This Page