Solved Heal Range

Discussion in 'Plugin Development' started by noraver, Apr 6, 2013.

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

    noraver

    hey guys one of my plugins im working on adjust health of players in different groups and the heal command i made for ops come into little snag

    now everything works fine just when you type /pheal or /pheal playername

    if
    playerA has 30 max health
    playerB has 50 max health

    the heal wont work unless
    this.player.setHealth(30);
    or
    this.player.setHealth(50);

    anyway to work around that to just make it fully heal no matter the amount of health they have?


    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    3. {
    4. if ((sender instanceof Player)) {
    5. this.player = ((Player)sender);
    6. }
    7.  
    8. if (cmd.getName().equalsIgnoreCase("pheal")) {
    9. if (this.player.hasPermission("permissionshealth.pheal")) {
    10. if (this.player == null) {
    11. sender.sendMessage("This command can only be run by a player. ");
    12. } else if (args.length == 0) {
    13. this.player.setHealth(50);
    14. this.player.setFoodLevel(20);
    15. this.player.setFireTicks(0);
    16. this.player.sendMessage(ChatColor.RED + "You health is full.");
    17. return true;
    18. }if (args.length == 1) {
    19. this.target = this.player.getServer().getPlayer(args[0]);
    20.  
    21. if (this.target == null) {
    22. sender.sendMessage(ChatColor.RED + args[0] + " is not online!");
    23. return false;
    24. }
    25. this.target.setHealth(50);
    26. this.target.sendMessage(ChatColor.RED + "Your health is full.");
    27. }
    28. if (args.length > 1)
    29. sender.sendMessage("Please write /heal <name>");
    30. }
    31. else {
    32. sender.sendMessage(ChatColor.RED + "You dont have the required permission.");
    33. }
    34.  
    35. return true;
    36. }
    37.  
    38. return false;
    39. }
    40. }
    41. [syntax][/syntax]
     
  2. Offline

    StaticE

    I don't think there's a way to do that, not positive though.

    Actually, try this:
    Code:
    this.player.setHealth(player.getMaxHealth());
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  3. Offline

    noraver

    well the health is adjustable in the config so i cant make a command for each one hehe
     
  4. Offline

    StaticE

    So couldn't you just heal the player using the value set in the config file? Like this:

    Code:
    player.setHealth(getConfig().getInt("pathtototalhealth"));
     
  5. Offline

    noraver

    this.player.setHealth(player.getMaxHealth());
    and
    this.target.setHealth(target.getMaxHealth());

    worked like a charm ty =D

    and no because there is like 20 health settings like i said before its for each group each group can have a set amount of health

    [​IMG]
     
  6. Offline

    ohtwo

    noraver I'm curious by looking at your map...but what kind of plugin are you making? Looks like you got a lot of things you need to test it with.
     
  7. Offline

    noraver

    ohtwo
    the display of Health Next to the names is a plugin not mine i just used it to check health was working in the settings the plugin used to do that is http://dev.bukkit.org/server-mods/health-heads/
    <25>health level1
    <30>Health level2
    <20> Health Guest
    are just 3 of the premission node for setting health i just happen to use it as there name aswell hehe
     
  8. Offline

    StaticE

    Cool, glad I could help!
     
Thread Status:
Not open for further replies.

Share This Page