Help! Commands not working

Discussion in 'Spigot Plugin Development' started by omgitsjayden, Nov 13, 2019.

Thread Status:
Not open for further replies.
  1. I have 2 commands, /die and /gmt.
    Since there is no killPlayer() event I had to try and work around that. It didn't work
    Code (Java):
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (command.getName().equalsIgnoreCase("die")) {                  
        if (sender instanceof Player) {
            Player p = Bukkit.getServer().getPlayer(sender.getName());
    Code (Java):
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase("gmt")) {
            if (sender instanceof Player) {
                Player player = (Player) sender;
                if (player.getGameMode() == (GameMode.SURVIVAL)) {
                } else if (player.getGameMode() == (GameMode.CREATIVE)) {
                } else if (player.getGameMode() == (GameMode.ADVENTURE)) {
                } else if (player.getGameMode() == (GameMode.SPECTATOR)) {
                } else if (player.getGameMode() == null) {
                    return false;
    Whenever I type the commands they do nothing :p
  2. Have you registered the commands in your onEnable, and added the command to your plugin.yml?
  3. Yes they are both in my plugin.yml but I don't know what you mean by "register in your onEnable". I've never done that before.
  4. Creeoer


    Show us your main class please. Particularly the onEnable function.
  5. Why are you using Bukkit.getPlayer when you already know that the sender is a player?
    just do Player player = (Player) sender;

    Show your plugin.yml and your error log as long as your classes.
  6. public void onEnable() {
    // Register our command "kit" (set an instance of your command class as executor)
    this.getCommand("gmt").setExecutor(new CommandsKit());
  7. gmt:
    usage: /gmt
    permission: jaydenutils.gmt
  8. I am assuming your command class is not called CommandKit. That class name was just the example command class used. You need to register it with a new instance of your command class, and command name.
    • Agree Agree x 2
  9. I don't care about the onEnable thing. I just want a /die and /gmt command and you guys are doing the exact opposite of that. Instead of helping me you're just spooning me meaningless information.
  10. Creeoer


    Meaningless information? You literally need to register the command correctly for it to work. He is helping with your exact problem which quite frankly is extremely basic.

    Protip: learn how to make spigot plugins before you write a guide on it.
    • Winner Winner x 2
  11. Strahan


    Well, if a command does nothing it's logical to check the process from the beginning. Throw a (plugin instance).getLogger().info("Command ran: " + label); as the first line in your command functions to ensure everything is good with the registration.

    Weird thing is, he does that in the gmt command just not in die for some reason.

    Also OP, Player#getGameMode() cannot return a null so no need to check for it, neither do you need to enclose the GameMode enum value in parenthesis. Were I doing it, I'd just make a map and use that. I.E:
    Code (Text):
    public class whatever implements CommandExecutor {
      Map<GameMode, GameMode> nextGMs = new HashMap<GameMode, GameMode>() {{
        put(GameMode.SURVIVAL, GameMode.CREATIVE);
        put(GameMode.CREATIVE, GameMode.ADVENTURE);
        put(GameMode.ADVENTURE, GameMode.SPECTATOR);
        put(GameMode.SPECTATOR, GameMode.SURVIVAL);

      public boolean onCommand(etc etc) {
        if (!(sender instanceof Player)) {
          sender.sendMessage("Players only, piss off");
          return true;

        Player p = (Player)sender;
    #13 Strahan, Nov 13, 2019
    Last edited: Nov 13, 2019
  12. You want help and you get help:
    .. the page contains an example and you think that the page is written exactly for your problem because you tried to copy the code. So you did not even read it.

    The only thing which can help you is probably a tutorial on how to use the internet.
    • Funny Funny x 1
  13. with this sort of attitude, no wonder why you ended up asking the question in your OP.

    look, those people are trying to "help" you,. If you present yourself as someone who're not willing to receive offered help but rather offend them who offered, you will get what you asked for.
    • Winner Winner x 1
  14. Locked because everyone is extremely useless and hostile.
    • Funny Funny x 4
Thread Status:
Not open for further replies.