A class for every Command

Discussion in 'Plugin Development' started by Panic94, Mar 27, 2013.

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


    Hi people,
    i am a new plugin devolper and i have a question to do.
    Until now i created only simply plugins using only 1-2 classes (1 main and 1 for listners), but now i want to create plugins using more classes...
    I want to make a class for every command.
    I make 2 package, one for the main class and one for the commands.
    In the commands package i will put all classes like HelpCommand, KillCommand, HealthCommand etc.
    I readed some things in the net and i understand that for do that i can use "getCommand().setExecutor(new commandclassname(this)) " in the onEnable method, but all commands have got the same prefix (ex. /plugin heal, /plugin kill). I tried to do it in this method, but i had so many problems. Can you explain me how i can do that?

    I had seen in the bukkit commands the execute method
      38    public boolean execute(CommandSender sender, String currentAlias, String[] args) {
      39        if (!testPermission(sender)) return true;
      40        if ((args.length < 2)) {
      41            sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      42            return false;
      43        }
      45        Player player = Bukkit.getPlayerExact(args[0]);
      47        if (player != null) { [...] 
    I would like to know more... Thanks
  2. Offline


  3. Offline


    I looked the github, but my problem is another.
    I want to make a class for every command and relative args of it. For example:
    /plugin help -> HelpCommand Class
    /plugin join -> JoinCommand Class
    I tried to do something like this:

    onCommand(bla bla, bla bla ,bla bla, bla bla, bla bla) {
    if(args[0].equalsIgnoreCase("help") {
    HelpCommand helpcommand = new HelpCommand();

    But i have one problem... I don't know how to use bukkit Player/Location/World etc. classes (ex. Player testplayer = (Player) sender;) out of onCommand method.

    PS: I'm waiting explanations about the execute method...
  4. Offline


  5. Offline


    Panic94 How much about common java, including interfaces etc., do you know? I've got a good way but you need to understand it
  6. Offline


    jojohnson1 I know something about the interfaces and java commons...
Thread Status:
Not open for further replies.

Share This Page