Plugin command help

Discussion in 'Spigot Plugin Development' started by alessio2010, May 12, 2017.

  1. Hello! I can't figure out how to make this command work
    Here is my code
    I can't figure out how to make a command where the arg[1] is entered counts as the number of hearts
    Like /sethearts <player> <hearts>
    The player part works but not the hearts part.
  2. Basically, you are trying to set the max health as a String.class, either you cast your arg[1] as a double / int or you use something similar to "Double.parseDouble(arg[1])"
  3. Okay, I set it to double instead of private but the setMaxHealth it gives me the following error
    The method setMaxHealth(double) in the type Damageable is not applicable for the arguments (String)
    I guess that the args[1] If i can't do it that way
    how do i do it so what they enter at <hearts> is used for the number in setMaxHealth()
  4. setMaxHealth(Double.parseDouble(arg[1]);
  5. Change
    Code (Text):
               Private Health = target.setMaxHealth(args[1]);
               if (args.length > 1) {
    Code (Text):

    That _should_ do it and not using a deprecated method.

    Edit: no need for a variable, made it one line.
    #5 Tarluin, May 12, 2017
    Last edited: May 12, 2017
  6. Both of those didn't work but i figured it out, thanks though, it was nice of you guys to help :D
  7. Hey post your fix so when someone searches for the same thing later on they find an answer :)
  8. Damageable dmPlayer = (Damageable)player;
    if (args.length > 1) {
    if (args.length > divv) {
    player.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "Invalid arguement >> " + ChatColor.RED + "Hearts can't be higher than 999999999");
    return true;