Commands Not Working

Discussion in 'Plugin Development' started by maniacbob456, May 11, 2014.

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

    maniacbob456

    package me.maniacbob.MoreCommands;

    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 Main extends JavaPlugin {

    public void onEnable() {
    getLogger().info("MoreCommands Has Been Enabled!");
    }
    public void onDisable() {
    getLogger().info("MoreCommands Has Been Disabled!");
    }
    public boolean OnCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if(sender instanceof Player) {
    Player p = (Player) sender;
    if (commandLabel.equalsIgnoreCase("HealMO")) {
    if (p.hasPermission("MoreCommands.HealMO"))
    if (args.length == 0)
    p.setHealth(20.0D);
    p.setFoodLevel(20);
    p.sendMessage(ChatColor.GOLD + "You Have Been Fully Healed");
    }
    else if(args.length == 1){
    Player player = (Player) sender;
    Player target = Bukkit.getServer().getPlayer(args[0]);
    target.setHealth(20.0D);
    target.setFoodLevel(20);
    player.sendMessage(ChatColor.GOLD + "You Have Healed" + target.getName());
    target.sendMessage(ChatColor.GOLD + "You Have Been Healed By" + player.getName());
    } else {
    p.sendMessage(ChatColor.RED + args[0] + "Is Not Online!");
    return true;
    }
    }
    return false;
    }
    }
     
  2. Offline

    tryy3

    So you are getting the messages, but the player isn't get healed and no errors?
     
  3. Offline

    maniacbob456

    No there are No Messages, Just nothing No Errors or Anything
     
  4. Offline

    tryy3

    add debug messages
     
  5. Offline

    maniacbob456

    Lol Im kinda new to coding :p
     
  6. Offline

    hubeb

    maniacbob456 well for one, your target player is never defined.
    Code:
    Player targetPlayer = player.getPlayer();
    if(targetPlayer != null){
    would work better if you did something like this:
    Code:
    Player target = Bukkit.getPlayer(args[0]); // Pseudo Code - Might actually work
    target.setHealth(20.0D); 
    secondly I prefer:
    Code:
    if (commandLabel.equalsIgnoreCase("HealMO")) {
    //over this:
    if (cmd.getName().equalsIgnoreCase("HealMO")) {
     
  7. Offline

    maniacbob456

    Ok thx But now Player target = Bukkit.getPlayer(args[10]); the Bukkit.getplayer Part is underlined yellow
     
  8. Offline

    Anonymous350

    maniacbob456

    Heal plugin would be more helpful to heal the hunger.
    Code:
    player.setFoodLevel(20);
     
  9. Offline

    maniacbob456

    Ok thx Added!

    Ok I did everything You asked and its still not working

    If someone could help me I have uptated my code and it is still not working I have pasted updated code In first post

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  10. maniacbob456 What actually doesn't work? And putting in some debug statements to see which parts of the code are executed would probably be helpful.

    Don't take this the wrong way but... so? Why does it matter what you prefer? You've simply stated that you prefer to do something a different way, but make no comment on why you believe that, or why it works any better. If it doesn't change anything, you shouldn't be suggesting it to new people - they can easily assume that it's the right way of doing things even though it isn't necessarily. Personally, I believe that checking the command label as opposed to the command is inferior and I will actually provide justification for that, albeit in one word:

    Aliases.

    I'd be interested to know why checking the label is better.
     
Thread Status:
Not open for further replies.

Share This Page