How to heal others, because this code isn't working. Code: }else if(args.length == 1){ Player targetPlayer = Bukkit.getServer().getPlayer(args[0]); if(player.getServer().getPlayer(args[0] !=null)){ targetPlayer.setHealth(20.0);
player.getServer().getPlayer(args[0] !=null) Should be targetPlayer != null. Try this, you should show the rest of your code though incase there's something else (atleast a few lines up and down if you don't want to show all your code) P.S. This should be in plugin development not requests
@DanLT Some great functions you could also add to your heal command: Reset his food and exhaustion Clear his bad potion effects Extinguish him (if he's on fire) Reset his remaining air And if this thread is solved, mark it as filled
Writing some code just to help a little. If this is solved, mark the thread as solved. Btw, the potion effect thing may not work because I didn't test it xP Code: if (cmd.getName().equalsIgnoreCase("heal")) { Player player = (Player) sender; Player target = player.getServer().getPlayer(args[0]); if (args.length < 0) { } else { if (target.isOnline() || !target.equals(null)) { target.setHealth(20); target.setFoodLevel(20); Collection<PotionEffect> activePotionEffects = target.getActivePotionEffects(); if(!activePotionEffects.isEmpty()){ target.removePotionEffect((PotionEffectType) activePotionEffects); } } } }
I suppose this is a way to heal others? Code:java if(lbl.equalsIgnoreCase("heal")){ if(sender instanceof Player){ Player player = (Player) sender; if(args.length == 0){ player.setHealth(20.0D); player.setFoodLevel(20); player.sendMessage(ChatColor.GREEN + "You healed yourself!"); }else if(args.length == 1){ Player target = Bukkit.getPlayer(args[0]); if(!target.isOnline()){ player.sendMessage(ChatColor.RED + "That player is not online."); return true; } target.setHealth(20.0D); target.setFoodLevel(20); player.sendMessage(ChatColor.GREEN + "You've successfully healed: " + target.getName()); }else{ player.sendMessage(ChatColor.YELLOW + "Type it like this: /heal or /heal (player)"); } }else{ sender.sendMessage("Only players can heal others"); } }
@mrgreen33gamer Console and command blocks should be able to heal players (but not themselves). @The_BloodHound No, you're potion thing won't work, you can't cast a Collection<PotionEffect> to a PotionEffectType. You have to loop through the collection like this: Code: for (PotionEffect potion : target.getActivePotionEffects()) target.removePotionEffect(potion.getType()); And humm... !target.equals(null) That's the dumbest code ever... If target was null, "target.equals(null)" would throw a NPE. Use (target != null) instead.
@The_BloodHound No, you're potion thing won't work, you can't cast a Collection<PotionEffect> to a PotionEffectType. You have to loop through the collection like this: Code: for (PotionEffect potion : target.getActivePotionEffects()) target.removePotionEffect(potion.getType()); That's what I thought xD