Solved I'm Failing to see the problem with this command setup

Discussion in 'Plugin Development' started by Kwright02, Dec 30, 2017.

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

    Kwright02

    Why does this setup for my command ALWAYS return the usage?
    Code:
    	public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    		Player p = (Player) sender;
    		if(cmd.getLabel().equalsIgnoreCase("warn")){
    			for(Player c: Bukkit.getOnlinePlayers()){
    				if(c.hasPermission("viridian.error.view")){
    					c.sendMessage(Viridian.PREFIX + " §c" +args[0] + " §f(" + args[1] + ")§5[§6Level:§c" + Integer.parseInt(args[2]) + "§5]");
    				}
    			}
    			return true;
    		}
    		return false;
    	}
     
  2. Offline

    RunsWithShovels

    @Kwright02 Does it also display the intended message?
    Also is you're command registered in onEnable and plugin.yml?
     
  3. Offline

    Kwright02

    it doesn't display the intended message, and it's registered in the plugin.yml. I've never ever had to register it in the onEnable to get it to work
     
  4. Offline

    RunsWithShovels

    @Kwright02

    Unless you're using reflection to create on the fly commands, which looking at your code you're not, then you should be registering your commands some how when your plugin is enabled. Whether that be with a method you have constructed or directly referencing the class that the command is in, in the onEnable.

    Is all your code in your main class?
    Also you are implementing CommandExecutor is the command class correct, if its in a different class other than the main?
     
    KingOfTheEast01 and CeramicTitan like this.
  5. Offline

    CeramicTitan

    OR

    You could try adding @Override in your main class above the onCommand method.
     
    KingOfTheEast01 likes this.
  6. Offline

    KingOfTheEast01

    Defining the commands in the plugin.yml is not registering them. You may have a method to do what you want on that command, but if it's not registered, the methods in that class will never be used by the server. When you register plugins, it tells the server that they can look in the specified class for instructions on how to handle it.
     
  7. Offline

    RunsWithShovels

    This has nothing to do with registering a plugin. That is something totally different. It's as simple as making sure that the command is correctly referenced.
     
  8. Offline

    Kwright02

    I tried this and it made no difference. I am very confused right now lol

    I have figured out what is wrong. In my onCommand I was using .getLable() instead of .getName()

    Using .getName() fixed my problem and I did not register anything in the onEnable()

    Solved
     
    Last edited: Dec 31, 2017
  9. Offline

    RunsWithShovels

    How about posting the whole class....................... solved or not, I still want to see it..
     
  10. Offline

    KingOfTheEast01

    Well you had actually told him to make sure it was registered. I was just trying to explain something I thought he was confused about. You told him to register the command, which he needs to do, but he believed he had already done that in the plugin.yml, but you need to in your onEnable() as well, do you not?
     
  11. Online

    timtower Administrator Administrator Moderator

    @KingOfTheEast01 Only need to register it in the onEnable if you want to change the executor.
     
    KingOfTheEast01 likes this.
  12. Offline

    KingOfTheEast01

    Ah, ok. When would it be best to do that? Whenever I create a new class for execution I have to register it, but the only time I can think of when you wouldn't need to specify it is if you create the execution method inside of the main class.
     
  13. Offline

    RunsWithShovels

    That's right. Whenever you make a separate class for a command, you need to register the command to set the executor class. That would be when.
     
    KingOfTheEast01 likes this.
  14. Offline

    KingOfTheEast01

    Alright, that makes sense. I appreciate the clear up.
     
Thread Status:
Not open for further replies.

Share This Page