I cant get the command to work, Help!

Discussion in 'Plugin Development' started by ajcool1050, Jan 29, 2013.

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

    ajcool1050

    I am making a plugin that will let you join a rank ladder with permissionsEx the command is /RaceJoinElf, I am just starting so the more help the better! Thanks.

    Code:
     package com.github.Ajcool1050.RaceSystem;
     
    import org.bukkit.Bukkit;
    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 RaceSystem extends JavaPlugin{
       
        @Override
        public void onEnable(){
            getLogger().info("Le Old Race System Has Been Enabled!");   
        }
       
        @Override
        public void onDisable(){
            getLogger().info("Le Old Race System As Been Disabled!");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String[] args) {
            if (cmd.getName().equalsIgnoreCase("RaceJoinElf")) {
                if(sender instanceof Player) {
                    Player player = (Player) sender;
                    String name = player.getName();
                    String command = "pex user " + name + " group set Elf-Slave";
                    getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
                    sender.sendMessage(ChatColor.GOLD + "Welcome To The Elf's Young GrassHoper");
                    return true;                       
                }
            }
            return false;
        }
    }
    
     
  2. Offline

    chasechocolate

    Did you put it in your plugin.yml?
     
  3. Offline

    ajcool1050

    Yah, here it is.
    Code:
    name: RolePlay Race System
    version: 1.0
    description: Allows players to choose what race they want to be apart of!
    author: Ajcool1050
    main: com.github.Ajcool1050.RaceSystem.RaceSystem
    commands:
      RaceJoinElf:
        description: Lets You Join The elf race!
        
     
  4. Offline

    DSH105

    ajcool1050
    What is the issue? Is it that the plugin doesn't load? Or that the command doesn't execute when you enter it?
     
  5. Offline

    ajcool1050

    The plugin startup works and the command allows me to run it but it doesn't do anything, it doesn't reply with "Welcome To The Elf Race" nor run the command through console.
     
  6. Offline

    DSH105

    Shouldn't your plugin.yml look like this?
    Code:
    commands:
        RaceJoinElf:
            description: Lets you join the elf race
    
    There are two extra spaces on the last two lines
     
  7. Offline

    ajcool1050

    Ill try that and see what happens!

    Nope still doesn't work, it lets me run the command but it doesn't do anything. Sigh

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

    stickeric

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    2. if(cmd.getName().equalsIgnoreCase("racejoinelf")){
    3. if(sender instanceof Player) {
    4. Player player = (Player) sender;
    5. String name = player.getName();
    6. String command = "pex user " + name + " group set Elf-Slave";
    7. getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
    8. player.sendMessage(ChatColor.GOLD + "Welcome To The Elf's Young GrassHoper");
    9. }else{
    10.  
    11. }
    12.  
    13. }else{
    14. }
    15. return false;
    16. }
    17. }


    Compare:

    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String[] args) {

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){


    @ajcool1050
     
  9. Offline

    caseif

    I'd recommend adding support for other permission systems, as many server owners dislike PEX considering it's tendency to break things. :p
     
  10. Offline

    stickeric

    AngryNerd
    I'm using it for arround a year now, It only fails on me when i use /reload with it :p.
    But /reload is never safe.
     
  11. Offline

    McCastleWars

    Your not loading your command in your onEnable.

    This is how I register my commands.(Put this in your main class)
    Code:
          public static void getCommands() {
                getCommand("castlewars", new CommandCastleWars());//Change "castlewars" to command name. and new CommandCastleWars() to your command class
                logger.info(name + " Initializing Commands."); //Optional
          }
          public static void getCommand(String command, CommandExecutor commandexecutor) {
                Bukkit.getServer().getPluginCommand(command).setExecutor(commandexecutor);
              }
    And then add this to your onEnable()
    Code:
    getCommands();
     
Thread Status:
Not open for further replies.

Share This Page