Specified command

Discussion in 'Plugin Development' started by Dyrocraft, Jan 7, 2013.

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

    Dyrocraft

    What would be the correct code for, if i was to type /gender <male/female>, and if not equaling these options will result in the command "Gender does not exist." How would i do something like this.
     
  2. Offline

    CubixCoders

    Do you know how to make the command?
     
  3. Offline

    chasechocolate

    Code:java
    1. if(!(args[0].equalsIgnoreCase("male") || args[0].equalsIgnoreCase("female"))){
    2. //Code
    3. }
     
  4. Offline

    gomeow

    A better way to do it:
    Code:java
    1. if(args[0].equalsIgnoreCase("male") {
    2. //Is male
    3. }
    4. else if(args[0].equalsIgnoreCase("female") {
    5. //Is female
    6. }
    7. else sender.sendMessage("Insert message here"); return true;
     
  5. Offline

    Dyrocraft

    gomeow
    chasechocolate

    I know how to make a command, I meant not for the first arg but for the 2 arg. So when a player types in /gender female/or male. Instead of allowing them to type anything in. I'm using this for putting it in to the config.yml.
     
  6. Offline

    CubixCoders

    Code:java
    1.  
    2. if(args.length == 2){
    3. if(args[1].equalsIgnoreCase("male")){
    4. //Male code
    5. }else if(args[1].equalsIgnoreCase("female")){
    6. //Female code
    7. }else{
    8. player.sendMessage(ChatColor.DARK_RED + "That is not a gender!");
    9. }
    10. }
    11.  

    That works for if the 2nd arg is male or female
     
  7. Offline

    gomeow

    No, that's wrong.

    Dyrocraft

    If you had a command:
    /gender female

    gender would be the commandLabel(or whatever you called it, I call it label)
    female is args[0]

    Args does not include the command
     
  8. Offline

    chasechocolate

    And also, args start at zero, not one. For genders to be saved in the config, I would make a string list in the config; one for male, one for female.
     
  9. Offline

    gomeow

    Or a key for each player, which would be a lot easier to modify/use
     
  10. Offline

    CubixCoders

    I know, he asked for the second arg, im confused on what he is asking Lol. I know that args[1] is the 2nd arg and that the commandLabel doesn't count as an arg T_T He said he is asking for the second arg not the first, so i thought he meant /gender something male/female
     
  11. Offline

    gomeow

    You need to think like you didn't know, because many people think that the command label is included in the args. :p
     
  12. Offline

    CubixCoders

    True true, he confused me Lol.
     
  13. Offline

    chasechocolate

    Code:java
    1. if(args[0].equalsIgnoreCase("male"){
    2. //Is male
    3. getConfig().set("genders." + player.getName(), "male");
    4. return true;
    5. }
    6. else if(args[0].equalsIgnoreCase("female"){
    7. //Is female
    8. getConfig().set("genders." + player.getName(), "female");
    9. return true;
    10. } else {
    11. sender.sendMessage("No.");
    12. return true;
    13. }
     
  14. Offline

    CubixCoders

    Lol "No."
     
  15. Offline

    Dyrocraft

    Ok im understanding this a bit more, these examples are not very far from what my looking for.
    Thank you all for your help, and time :)
     
Thread Status:
Not open for further replies.

Share This Page