How to impliment chat commands

Discussion in 'Plugin Development' started by AnthraX, Jan 21, 2011.

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

    AnthraX

    i have a varible.

    we will just call it size for now

    so the code is

    size = 5

    How would i change that 5 with a chat command

    ex. /Size 3

    i cannot figure it out
     
  2. Offline

    Jinux

    You first need to hook the command (see This thread)
    Then you need to parse the argument to the command (the number after it) and change the variable if it exists + is a number etc.
     
  3. Offline

    MadMichi

    You mean this thread? [​IMG]
     
  4. Offline

    Funylilman

    This is kinda the basic idea that I'm aware of.

    Code:
    public boolean onCommand(Player player, Command command, String commandLabel, String[] args) {
    
    String commandName = command.getName().toLowerCase();
                if(commandName.equalsIgnoreCase("size")){
    size = args[0];
    return true;
    }
    return false;
    }
    A bit sleepy though, so syntax may be wrong and that's more along the lines of theory code. I dont know where/how you have you size variable. Also I'm just starting to read on plug ins, so everything could be completely wrong.

    Hope that helps.
     
  5. Offline

    AnthraX

    Thank you xD Didnt stumble acrost that
    --- merged: Jan 21, 2011 11:00 AM ---
    Do you know of an easyer way to do this? becuase this is my first plugin and im not firmilliar with the code
     
  6. Offline

    Jinux

    What? That's completely exactly the same link that I posted [​IMG]
     
  7. Offline

    MadMichi

    Oh, sorry... when i looked it seemed the link was missing. [​IMG]
     
  8. Offline

    Jinux

    No worries. At first I thought I'd got the thread wrong but then I checked and the head-scratching started :p
     
Thread Status:
Not open for further replies.

Share This Page