Command Executor class Errors

Discussion in 'Plugin Development' started by TheLazeboy, May 3, 2013.

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

    TheLazeboy

    Upon the waiting of my other Command Executor class question to be answered, I was wondering how to fix these two errors:

    [​IMG]

    Here is the code text for hands on help:

    Code:
    package me.TheLazeboy.superpowers;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class MyCommandExecutor implements CommandExecutor {
     
        private Superpowers plugin;
        Player player = (Player) sender;
        public MyCommandExecutor(Superpowers plugin) {
            this.plugin = plugin;
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(label.equalsIgnoreCase("test1")) {
                    player.sendMessage(ChatColor.GOLD + "Sent!");
     
        }
            return false;
    }{
            if(label.equalsIgnoreCase("heal")) {
                player.sendMessage(ChatColor.GREEN + "Healing!");
                player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 1000, 1));
    }}}
    
     
  2. Offline

    Burnett1

    Player player = (Player) sender;

    This must be within the onCommand section.

    I would also advise using cmd.getName().equalsIgnorCase("Commad")

    Please try and neaten your code its a mess. Half of it looks to be outside the onCommand.
     
  3. Offline

    TheLazeboy

    [​IMG]

    P.S. You have a type on IgnoreCase.
     
  4. Offline

    Burnett1

    Code:
    public class MyCommandExecutor implements CommandExecutor {
     
        private Superpowers plugin;
        public MyCommandExecutor(Superpowers plugin) {
            this.plugin = plugin;
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
            Player player = (Player) sender;
         
            if(cmd.getName().equalsIgnoreCase("test1")) {
             
                player.sendMessage(ChatColor.GOLD + "Sent!");
                return true;
            }
         
            if(cmd.getName().equalsIgnoreCase("heal")) {
             
                player.sendMessage(ChatColor.GREEN + "Healing!");
                player.setHealth(20);
                return true;
            }
            return false;
        }
    }
    
    Indents are very import if you want other people to be able to read the code.
     
    TheGreenGamerHD likes this.
  5. Offline

    TheLazeboy

    I get this error code in server console:
    [​IMG]

    And here is my main class that seems to be the problem:
    [​IMG]
     
  6. Offline

    Burnett1

    Plugin.yml please?
     
  7. Offline

    TheLazeboy

    Here is the pastebin link: http://pastebin.com/LNHdu2ZX . And I don't know what you mean by indents. :3

    Ahhhhh. I see. I forgot the extra line on the end.

    Yay! It is working! Thanks for your help also! :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page