Command Not Working

Discussion in 'Plugin Development' started by bumppy5, Oct 1, 2014.

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

    bumppy5

    Code:
    Code:
    package me.Zicion.gm;
     
    import java.util.logging.Logger;
     
    import org.bukkit.GameMode;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Easygm extends JavaPlugin
    {
        public final Logger logger = Logger.getLogger("Minecraft");
        public void onEnable()
        {
            getLogger().info("Easy GameMode enabled");
        }
       
        public void onDisable()
        {
            getLogger().info("Easy GameMode disabled");
        }
       
        public boolean onCommand(Command cmd, String commandLabel, CommandSender sender, String[] args)
        {
            Player player = (Player) sender;
            if(commandLabel.equals("gm1"))
            {
                player.setGameMode(GameMode.CREATIVE);
                return true;
            } else if(commandLabel.equals("gm0"))
            {
                player.setGameMode(GameMode.SURVIVAL);
                return true;
            } else if(commandLabel.equals("gm2"))
            {
                player.setGameMode(GameMode.ADVENTURE);
                return true;
            }
            return true;
           
           
           
        }
    }
    
    Plugin.yml
    Code:
    name: Easygm
    version: 1.4.1
    main: me.Zicion.gm.Easygm
    commands:
      gm1:
        description: Sets gamemode to creative.
      gm0:
        description: Sets gamemode to survival.
      gm2:
        description: Sets gamemode to adventure.

    The server recognizes that it is a command but no effect is taken. The gamemode will not change.
     
  2. Offline

    Jimfutsu

    remove the return statements within the ifcommandlabael check
     
  3. Offline

    bumppy5

    No change. Still does not work.
     
  4. Offline

    es359


    Don't use commandLabel.. Use cmd.getName(); also, you should use equalsIgnoreCase(" ");
    You also unsafely cast Player.
     
  5. Offline

    fireblast709

    bumppy5 in addition to the previous post:
    • Don't use Logger.getLogger("Minecraft"), use the getLogger() method that you get by extending JavaPlugin.
    • No need to print enable/disable messages, Bukkit does this for you.
     
  6. Offline

    bumppy5

    What do you mean unsafely cast? Can you give me an example of safe casting?
     
  7. Offline

    fireblast709

    bumppy5
    Code:java
    1. if(sender instanceof Player)
    2. {
    3. Player player = (Player) sender;
    4. }
     
Thread Status:
Not open for further replies.

Share This Page