Command just says the usage from plugin.yml

Discussion in 'Plugin Development' started by megasaad44, Apr 24, 2014.

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

    megasaad44

    Hi, I'm making my custom gm plugin for my server but when I run the command, it just says the usage part in the plugin.yml instead of actually changing my gamemode....

    Code:
    Code:java
    1. package me.LordSaad44.terramc;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.GameMode;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8.  
    9. public class Gamemode{
    10. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    11. if (cmd.getName().equalsIgnoreCase("gamemode")) {
    12. if (sender instanceof Player) {
    13. Player p = (Player) sender;
    14. if (args.length == 0) {
    15. if (p.getGameMode() == GameMode.SURVIVAL) {
    16. p.setGameMode(GameMode.CREATIVE);
    17. p.sendMessage(ChatColor.GRAY + "You are now in creative mode");
    18. } else {
    19. p.setGameMode(GameMode.SURVIVAL);
    20. p.sendMessage(ChatColor.GRAY + "You are now in survival mode");
    21. }
    22. } if (args.length >= 1) {
    23. if (args[0].equals("0") || args[0].equalsIgnoreCase("survival")) {
    24. p.setGameMode(GameMode.SURVIVAL);
    25. p.sendMessage(ChatColor.GRAY + "You are now in survival mode");
    26. } else if (args[0].equals("1") || args[0].equalsIgnoreCase("creative")) {
    27. p.setGameMode(GameMode.CREATIVE);
    28. p.sendMessage(ChatColor.GRAY + "You are now in creative mode");
    29. } else if (args[0].equals("2") || args[0].equalsIgnoreCase("adventure")) {
    30. p.setGameMode(GameMode.ADVENTURE);
    31. p.sendMessage(ChatColor.GRAY + "You are now in adventure mode");
    32. } else {
    33. p.sendMessage(ChatColor.GRAY + "wtf is that gamemode?");
    34. }
    35. }
    36. } else {
    37. sender.sendMessage(ChatColor.RED + "Only players can do this, you silly console!");
    38. }
    39. return true;
    40. }
    41. return false;
    42. }
    43. }


    plugin.yml
    Code:
    author: LordSaad44
    description: TerraMC commands and utilities.
    main: me.LordSaad44.terramc.Main
    name: TerraMC
    version: 1.0
    commands:
      gamemode:
        description: change gamemode
        aliases: gm
        usage: /gamemode [0|1|2|creative|survival|adventure]
      heal:
        description: heal yourself
        permission: terra.heal
        usage: /heal
      feed:
        description: feed yourself
        permission: terra.feed
        usage: /feed
     
  2. Offline

    BillyGalbreath

    Looks like you are missing a } near the end. Probably closed it at the wrong spot.
    Scratch that. You are not Overriding the method, and you havnt implement CommandExecutor. Which means you never registered you command in onEnable() either.
     
  3. Offline

    megasaad44

Thread Status:
Not open for further replies.

Share This Page