Arguments of second half of command?

Discussion in 'Plugin Development' started by PolarCraft, Dec 31, 2013.

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

    PolarCraft

    Okay how could i do this for the first half? /heal
    And it will heal the sender.
    And how could i do this for the second half? /heal <player>

    Current code:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("heal")) {
    2. if(sender.hasPermission("heal") && ((sender.isOp()))) {
    3. if (args.length == 0) {
    4. p.setHealth(20);
    5. p.sendMessage(ChatColor.GOLD + "You have been healed!");
    6. }
    7. } else if (args.length == 1){
    8. Player t = (Bukkit.getServer().getPlayer(args[0]));
    9. if (t == null)
    10. {
    11. sender.sendMessage(args[0] + " is not online!");
    12. return true;
    13. }
    14. else
    15. {
    16. t.setHealth(20);
    17. t.sendMessage(ChatColor.GOLD +"You have been healed by: " + ChatColor.GREEN + sender.getName() + ChatColor.GOLD + "!");
    18. }
    19. }
    20. }
    21. return false;
    22. }
    23. }
    24.  



    [Edit] It keeps doing the first argument.
     
  2. Offline

    Wizehh

    uhm.. this is what I use; feel free to compare:
    Code:java
    1. } else if(args.length == 1) {
    2. if(p.getServer().getPlayer(args [0]) != null) {
    3. Player targetPlayer = p.getServer().getPlayer(args [0]);
    4. targetPlayer.setHealth(20.0);
    5. targetPlayer.setFireTicks(0);
    6. for (PotionEffect effect : targetPlayer.getActivePotionEffects())
    7. targetPlayer.removePotionEffect(effect.getType());
    8. targetPlayer.sendMessage(ChatColor.GRAY + "You have been healed by " + ChatColor.AQUA + sender.getName());
    9. sender.sendMessage(ChatColor.GRAY + "You have healed " + ChatColor.AQUA + targetPlayer.getDisplayName());
    10.  
    11. } else {
    12. p.sendMessage(ChatColor.DARK_RED + "" + ChatColor.ITALIC + args[0] + ChatColor.RESET + ChatColor.DARK_RED + " is not online!");
    13.  
    14. }
     
  3. Offline

    PolarCraft

    Wizehh That is the same way I am doing it but yours is shorter. But since i wanted to heal the player if they type /heal it is not working.
     
  4. Offline

    Wizehh

    PolarCraft What do you mean, "it's not working"? Do you mean that it just heals you, not the player in args[0]?
     
  5. Offline

    1Rogue

    You have two closing brackets after your "if" statement block.

    Code:java
    1. if (args.length == 0) {
    2. p.setHealth(20);
    3. p.sendMessage(ChatColor.GOLD + "You have been healed!");
    4. }
    5. } else if //...


    Would help if you followed at least some kind of coding convention.
     
    AoH_Ruthless and Wizehh like this.
Thread Status:
Not open for further replies.

Share This Page