Heal command // message

Discussion in 'Spigot Plugin Development' started by leoyt185owner, Aug 4, 2018.

  1. Some other stupid question, i'm sorry. I have an issue with this and i don't know whats wrong ):
    Code (Text):
    public class heal implements CommandExecutor {
        public heal (Main instance) {
            Main plugin;
            plugin = instance;
        }
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("heal")) {
                Player p = (Player) sender;
                FileConfiguration config = plugin.getConfig();
                if(args.length == 0){
                    if(p.hasPermission("core.*") && p.hasPermission("core.use") && p.isOp()) {
                        List<String> Lines = plugin.getConfig().getStringList("Heal");
                        for (String s : Lines) {
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', s).replace("%player%", p.getName()).replace("%online_players%",Bukkit.getOnlinePlayers().size()+""));
                        p.setHealth(20);
                        p.setFoodLevel(20);
                       
                        return true;
                    }else{
                       
                        p.sendMessage("§cYou don't have permission tu use this command." );
                         
                    }
                   return true;
                }
     
  2. I want that sends the message that it's on the String Heal i the config and then heal the player
     
  3. Code (Java):
        public class heal implements CommandExecutor {
            public heal (Main instance) {
                Main plugin;
                plugin = instance;
            }
            @Override
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
             
                if (cmd.getName().equalsIgnoreCase("heal")) {
                    Player p = (Player) sender;
                    FileConfiguration config = plugin.getConfig();
                    if(args.length == 0){
                        if(p.hasPermission("core.*") && p.hasPermission("core.use") && p.isOp()) {
                            List<String> Lines = plugin.getConfig().getStringList("Heal");
                            for (String s : Lines) {
                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', s).replace("%player%", p.getName()).replace("%online_players%", Bukkit.getOnlinePlayers().size()));
                            }
                            p.setHealth(20);
                            p.setFoodLevel(20);
                         
                            return true;
                        } else {
                         
                            p.sendMessage("§cYou don't have permission tu use this command." );
                           
                        }
                       return true;
                    }
                }
            }
        }
    Maybe try this..
     
  4. Error: plugin can not be resolved
    Error: The method replace(char, char) in the type String is not applicable for the arguments (String, int)
    The second error is in replace
     
  5. Try this.
    Code (Java):
    p.sendMessage(ChatColor.translateAlternateColorCodes('&', s).replace("%player%", p.getName()).replace("%online_players%", Bukkit.getOnlinePlayers().size().toString()));
     
  6. If not works than this:
    Code (Java):
    p.sendMessage(ChatColor.translateAlternateColorCodes('&', s).replace("%player%", p.getName()).replace("%online_players%", Integer.toString(Bukkit.getOnlinePlayers().size())));
     
  7. the healing wont work cause you have to do 20D or 20F or something
     
  8. 20.0 would work. (it's a double)
     
  9. Regardless, his current code of "20" won't.
     
  10. My guess would be to change the following:
    Code (Java):
    public heal (Main instance) {
        Main plugin;
        plugin = instance;
    }
    to:
    Code (Java):
    Main plugin;
    public heal (Main instance) {
        this.plugin = instance;
    }
     
    • Agree Agree x 1
  11. It will work.
    You need to move your plugin variable outside of the constructor.
     
    • Agree Agree x 1
  12. That won't be the reason for your Error, but in this line, u're saying, that the player has to have everyone of these Permissions AND has to be OP to perform this command, instead of '&&' you could use ' || ' (it means 'or')

    + u can actually remove p.isOp, cuz an op will always be able to perform any command, as long as you do not forbid it for him.