Advertisement
Guest User

Untitled

a guest
Jan 11th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. package ep_04.ep_04;
  2.  
  3. import org.bukkit.ChatColor;
  4. import org.bukkit.command.Command;
  5. import org.bukkit.command.CommandExecutor;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.entity.Player;
  8.  
  9. public class CommandsClass implements CommandExecutor {
  10.  
  11.     @Override
  12.     public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
  13.         if(command.getName().equalsIgnoreCase("healme")) {
  14.             if (commandSender instanceof Player) {
  15.                 Player player = (Player) commandSender;
  16.                 if (args.length < 1) {
  17.                     player.sendMessage(ChatColor.RED + "Please include how much you want to be healed by.");
  18.                     return true;
  19.                 }
  20.                 else if (args.length == 1) {
  21.                     try {
  22.                         double phealth = player.getHealth();
  23.                         double addhealth = Double.parseDouble(args[0]);
  24.                         if (phealth < 20) {
  25.                             player.setHealth(phealth + addhealth);
  26.                             player.sendMessage(ChatColor.GRAY + "You has been healed for " + ChatColor.GREEN + addhealth + " health");
  27.                             return true;
  28.                         }
  29.                         else {
  30.                             player.sendMessage(ChatColor.YELLOW + "if you rake some damage ..... I heal you.");
  31.                             return true;
  32.                         }
  33.                     }
  34.                     catch (NumberFormatException e) {
  35.                         player.sendMessage(ChatColor.RED + "Place input a real number!");
  36.                         return true;
  37.                     }
  38.                 }
  39.             }
  40.             else {
  41.                 commandSender.sendMessage(ChatColor.RED + "Only players can execute this command.");
  42.  
  43.             }
  44.         }
  45.  
  46.         return true;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement