Command In Game Isn't Working

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

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

    xMwpgamer7ooox

    It says the command is unknown, when I type in mwpgamer7ooo. it loads of fine otherwise....

    package me.Mwpgamer7ooo.java;

    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("Plugin Has Been Enabled! :D");
    }


    public void onDisable() {
    getLogger().info("Plugin Has Been Disabled! D:");

    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if(commandLabel.equalsIgnoreCase("mwpgamer7ooo")) {
    Player player = (Player) sender;
    player.sendMessage(ChatColor.AQUA + "This Plugin Has Been Created By Michael Pereira");

    }

    return false;

    }
    }

    main: me.Mwpgamer7ooo.java.main
    name: Java
    version: 1.0
    author: Mwpgamer7ooo
    description: Java, Simple and Perfect! :)
     
  2. Offline

    thecrystalflame

    you havent added the command to your plugin.yml

    add this to it

    commands:
    mwpgamer7ooo:
    description: whatever
    usage: /mwpgamer7ooo whatever
     
  3. Offline

    DotDash

    You need to add the command to the plugin.yml

    Use this for help.

    Lol Ninja'd xD
     
  4. Offline

    xMwpgamer7ooox

    I did this and its still an unknown command.

    main: me.Mwpgamer7ooo.java.main
    name: Java
    version: 1.0
    author: Mwpgamer7ooo
    description: Java, Simple and Perfect! :)
    commands:
    mwpgamer7ooo:
    description: To Help You!
    usage: /mwpgamer7ooo
     
  5. Offline

    NetherResident

    You need to make your class "main.java" implement CommandExecutor, you also need to add the line of code:
    Code:
    this.getCommand("mwpgamer7000").setExecutor(this);
    to the onEnable() method.
     
  6. Offline

    xMwpgamer7ooox

    could you copy my code and insert that in so I could see how it should look like please and thank you.

    still doesn't work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  7. Offline

    thecrystalflame

    this is completely incorrect, the only time you need to do this is when your using a class that isnt your main as the executor.
    extends JavaPlugin has all the implementation needed for the onCommand Override

    Code:yml
    1.  
    2. commands:
    3. mwpgamer7ooo:
    4. usage: /mwpgamer7ooo
    5. description: To Help You!
    6.  


    try it with proper indentation

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  8. Offline

    xMwpgamer7ooox

    still isn't working
     
  9. Offline

    thecrystalflame

    return true in onCommand()
     
  10. Offline

    xMwpgamer7ooox

    Where do I insert that?
     
  11. Offline

    thecrystalflame

    replace return false in your onCommand() with it.
     
  12. Offline

    JoeyDevs

    First add the command in your plugin.yml

    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    3. if(commandLabel.equalsIgnoreCase("mwpgamer7ooo")) {
    4. Player player = (Player) sender;
    5. player.sendMessage(ChatColor.AQUA + "This Plugin Has Been Created By Michael Pereira");
    6. return true;
    7. }
    8.  
    9. return false;
    10.  
    11. }
     
  13. Offline

    Drkmaster83

    And in addition that that, here's your plugin.yml. Make sure the spacing looks exactly like this.
    Code:
    main: me.Mwpgamer7ooo.java.main
    name: Java
    version: 1.0
    author: Mwpgamer7ooo
    description: Java, Simple and Perfect! :)
    commands:
      mwpgamer7ooo:
        description: To Help You!
    
     
  14. Offline

    gal0511Dev

    I can try but im at school im not on eclipse but it try this
    Code:java
    1. ur package stuff
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, Sting commandLable, String[] args){
    4. Player player = (Player)sender;
    5. if(cmd.getName().equalsIgnoreCase("test")){
    6. player.sendMessage("your message here");
    7. return true;
    8. }
    9. // other code


    plugin.yml
    Code:
    name: plugin name
    main: your.main.class
    vesion: 1.0
    description: Plugin description
    commands:
     
     
      test:
        description: what the command does
     
  15. Offline

    xMwpgamer7ooox

    Thanks for your helped, it worked!
     
  16. Offline

    gal0511Dev

    If you need help with anything else harder or easier just pm me
     
Thread Status:
Not open for further replies.

Share This Page