Solved Heal and Feed plugin error.

Discussion in 'Plugin Development' started by CrazyYoungBro, Jun 10, 2016.

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

    CrazyYoungBro

    Hello,
    I made a heal and feed plugin and whenever I go to compile it, it shows an error message.
    The error is as follows:
    "The method getPlayer(String) from type Server is deprecated."
    Here is the code for the plugin.

    Code:
    package me.arihant.medic;
    
    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 Medic extends JavaPlugin {
       
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(new MedicListeners(), this);
        }
       
       
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
           
            if(!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "The console cannot use Medic!");
                return true;
            }
           
            Player player = (Player) sender;
               
           
            if(cmd.getName().equalsIgnoreCase("heal")) {
                if(args.length == 0) {
                    player.setHealth(20);
                    player.sendMessage(ChatColor.GREEN + "You have been healed!");
                    return true;
                }
                Player target = Bukkit.getServer().getPlayer(args[0]);
                if( target == null ) {
                    player.sendMessage(ChatColor.RED + "Could not find player!");
                    return true;
                }
                target.setHealth(20);
                target.sendMessage(ChatColor.GREEN + "You have been healed!");
                player.sendMessage(ChatColor.GREEN + target.getName() +  " has been healed!");
            }
           
            if(cmd.getName().equalsIgnoreCase("feed")) {
                if(args.length == 0) {
                    player.setFoodLevel(20);
                    player.sendMessage(ChatColor.GREEN + "You have been fed!");
                    return true;
                }
                Player target = Bukkit.getServer().getPlayer(args[0]);
                if(target == null) {
                    player.sendMessage(ChatColor.RED + "Could not find player!");
                    return true;
                }
                target.setFoodLevel(20);
                target.sendMessage(ChatColor.GREEN + "You have been fed!");
                player.sendMessage(ChatColor.GREEN + target.getName() +  " has been fed!");
            }
            return true;
        }
    }
    
    Please help me with this and let me know what I did was wrong. This isnt the first time i came across this erros, it occured to me in a few other plugins as well. It would be great if anybody can solve this bug for me.
     
  2. Online

    timtower Administrator Administrator Moderator

    @CrazyYoungBro Hover your mouse over it.
    Select ignore warnings.
    It was a change to get attention to the uuid system.
     
  3. Offline

    CrazyYoungBro

  4. Offline

    mine-care

  5. Offline

    CrazyYoungBro

    @mine-care There is still a problem. The editor doesnt show me the ignore warnings option. It just states 2 quick fixes as which are as follows:
    • Add @SupressWarnings 'deprecation' to 'target'.
    • Add @SupressWarnings 'deprecation' to 'onCommand()'
    What to do now?
     
  6. Online

    timtower Administrator Administrator Moderator

  7. Offline

    CrazyYoungBro

Thread Status:
Not open for further replies.

Share This Page