Advertisement
xToast_

Plugin Problems

Feb 25th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. package com.enjin.toastsplugins;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.plugin.java.JavaPlugin;
  9.  
  10. public class healb extends JavaPlugin {
  11.  
  12. /*
  13. 1. Figure out the player to be healed.
  14. 2. Heal the player.
  15.  
  16. (1) If a player is specified, find them.
  17. If they are not online, send an error message.
  18. If the player is not online:
  19. If the sender is a player, heal the sender.
  20. If the sender is the console, send an error message.
  21. */
  22.  
  23. @SuppressWarnings("deprecation")
  24. @Override
  25. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  26. Player target;
  27.  
  28. if (args.length == 0 && !(sender instanceof Player)) {
  29. sender.sendMessage(ChatColor.RED + "You must specify a player.");
  30. return true;
  31. }
  32.  
  33. if (args.length == 0) {
  34. target = (Player) sender; // This is safe because we already made sure the sender is a Player.
  35. }
  36.  
  37. else {
  38. target = Bukkit.getServer().getPlayer(args[0]);
  39.  
  40. if (target == null) {
  41. sender.sendMessage(ChatColor.RED + "Cannot find player " + args[0] + ".");
  42. return true;
  43. }
  44. }
  45.  
  46. target.setHealth(target.getMaxHealth());
  47.  
  48. sender.sendMessage(ChatColor.GREEN + "You have healed " + target.getName() + "!");
  49. target.sendMessage(ChatColor.GREEN + "You have been healed by " + sender.getName() + "!");
  50.  
  51. return true;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement