Solved Bukkit.getPlayer?

Discussion in 'Plugin Development' started by ADAMATOR1234, Aug 10, 2014.

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

    ADAMATOR1234

    Code:java
    1. package me.ADAMATOR1234;
    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.event.Listener;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class main extends JavaPlugin implements Listener
    14. {
    15. Logger myPluginLogger = Bukkit.getLogger();
    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[0]) != null)
    40. {
    41. Player playerToHurt = Bukkit.getPlayer(args[0]);
    42. double damageAmount = Double.parseDouble(args[1]);
    43. playerToHurt.damage(damageAmount);
    44. playerToHurt.sendMessage(ChatColor.RED + "You were hurt by " + player.getDisplayName());
    45. }
    46. else player.sendMessage(ChatColor.DARK_RED + "Can't Find Player " + args[0]);
    47. }
    48.  
    49.  
    50.  
    51.  
    52.  
    53.  
    54. }
    55.  
    56. return true;
    57. }
    58.  
    59.  
    60.  
    61. }
    62.  

    So, I'm following someone's tutorial on how to make a damage plugin (/hurt <player> <amount>). However, the line of code is crossing itself out...? Says it's deprecated, guessing that's due to the new UUID system (correct me if wrong). Is there a way to get around this? Here's my main class so far (couldn't be asked to do it on pastebin, sorry?):
     
  2. Offline

    Gater12

  3. Offline

    ADAMATOR1234

    Gater12 I am using the 1.7.10 dev build. So what should I do now?
     
  4. Offline

    Gater12

    ADAMATOR1234
    Ignore it. It really has no effect when compiling. You can also @SurpressWarnings("deprecation")
     
  5. Offline

    Necrodoom

    ADAMATOR1234 read the link and understand the reasons for deprecation, and why you can still use it.
     
    Zupsub likes this.
  6. Offline

    zDylann

    The code will still compile. Deprecation is used to warn/acknowledge that the method may not be available in the future. In this case, bukkit is just trying to inform you of the UUID conversion change.
     
  7. Offline

    ADAMATOR1234

    Necrodoom Reading is fun when you can accomplish things fast, getting a neat, compact reply from people who actually know about this (unlike me) is better.:)

    Thanks guys, but why do I still get this "IllegalArgument" error then?
    Capture.PNG
     
  8. Offline

    Gater12

    ADAMATOR1234
    Do you have a duplicate plugin in your plugins folder?
    Do you have any other classes that extends JavaPlugin? (Your main class should only extends JavaPlugin)
    Did you create a new instance of you main class somewhere? (pass instance instead)
     
  9. Offline

    ADAMATOR1234

    Gater12 None of those, I believe. Sorry, I'm kinda new to the hole concept of plugin development. Plus main, the one in the screenshot, is the only class I have made.

    Here, if it helps, take another screenshot.
    Capture.PNG
     
  10. Offline

    ZodiacTheories

  11. Offline

    ADAMATOR1234

    I guess not, no.
     
  12. Offline

    mythbusterma

    ADAMATOR1234

    The error indicates that, for some reason, your plugin is being initialized twice. This could be caused by instantiating your class or two plugins of the same name (possibly).
     
  13. Offline

    ZodiacTheories

  14. Offline

    ADAMATOR1234

    I need to...?
     
  15. Offline

    Zupsub

    Your plugin will crash if someone types zero / only one argument.
    If you add the check, you can return false, which will cause bukkit to print the usage message. See the bukkit wiki for more help.
     
  16. Offline

    Necrodoom

  17. Offline

    ADAMATOR1234

    Could someone just um, edit the code and re-paste it? I think that's the best option, after all, ima nub.
     
  18. Offline

    xigsag

    I assume more complex plugins will require later versions (1.7.10 builds), but I'm doing fine with just a 1.7.9 build bukkit and craftbukkit jar, and it isn't giving me any errors so far. Will probably only update if the versions become incompatible (block updates, 1.8, major bug fixes, etc)
     
  19. Offline

    ZodiacTheories

    Necrodoom

    Just for future, if ADAMATOR1234 wanted to make a command with more than one argument, he would need to check for the args.length
     
  20. Why are you implementing Listener? You're not even listening for anything. :p

    Hey more experienced guys...
    Would, he, in this case... Need to add:

    getServer().getPluginManager().registerEvents(this, this);

    To his on enable? Because he implements listener? Or would he only need to do that if he actually had an @EventHandler{body} ?
     
  21. Offline

    ADAMATOR1234

    xYourFreindx That was from a past plugin I was making, I just didn't remove it. I fixed it. Not sure how though...
     
  22. ADAMATOR1234
    You fixed your initial problem?
    If so, don't forget to use the "edit thread" tool at the top right and mark this as solved.
    Also, if you find out what was causing you issues, could you post it here, so that people in the future that have the same problem as you may refer to this thread for help in figuring out something that may or may not be obvious.
     
  23. Offline

    ADAMATOR1234

    Ok, I'll try and see what it was. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page