Adding a command that sends a message

Discussion in 'Plugin Development' started by Fearlessneon, Jan 30, 2014.

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

    Fearlessneon

    I am a little confused on how to add a command so if i type /anticurse it will send a message telling who made it and the version.
     
  2. Offline

    1Rogue

    Just override the onCommand method in your main class:

    Code:java
    1. public class YourClass extends JavaPlugin {
    2.  
    3. //...
    4.  
    5. @Override
    6. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    7. if (cmd.getName().equals("anticurse") {
    8. sender.sendMessage("Hello world!");
    9. }
    10. }
    11.  
    12. }


    Don't forget to put the commands in your plugin.yml as well.
     
    Fearlessneon likes this.
  3. Offline

    ShearsSheep

    Example for Commands in your plugin.yml
    Code:
    name: [Plugin Name]
    author: [Insert Name]
    version: [Version]
    description: [Your Description]
    main: [Your main]
    commands:
      [command. Remove [] ]:
        description: Starts the game!
     
  4. If you wanna add colours just add
    Code:java
    1. public class AntiCurse extends JavaPlugin{
    2.  
    3. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, Stringp[] args){
    4. if(cmd.getName().equalsIgnorecase("Anticurse"){
    5. sender.sendMessage(ChatColor.Whatever color you want + "Made by... Version...");
    6. }
    7.  
    8.  
    9. }
    10.  
    11.  
    12. }
     
Thread Status:
Not open for further replies.

Share This Page