Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.enjin.toastsplugins;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class healb extends JavaPlugin {
- /*
- 1. Figure out the player to be healed.
- 2. Heal the player.
- (1) If a player is specified, find them.
- If they are not online, send an error message.
- If the player is not online:
- If the sender is a player, heal the sender.
- If the sender is the console, send an error message.
- */
- @SuppressWarnings("deprecation")
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
- Player target;
- if (args.length == 0 && !(sender instanceof Player)) {
- sender.sendMessage(ChatColor.RED + "You must specify a player.");
- return true;
- }
- if (args.length == 0) {
- target = (Player) sender; // This is safe because we already made sure the sender is a Player.
- }
- else {
- target = Bukkit.getServer().getPlayer(args[0]);
- if (target == null) {
- sender.sendMessage(ChatColor.RED + "Cannot find player " + args[0] + ".");
- return true;
- }
- }
- target.setHealth(target.getMaxHealth());
- sender.sendMessage(ChatColor.GREEN + "You have healed " + target.getName() + "!");
- target.sendMessage(ChatColor.GREEN + "You have been healed by " + sender.getName() + "!");
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement