Solved Command Arguments

Discussion in 'Plugin Development' started by DaanSander, Jan 13, 2015.

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

    DaanSander

    Hello i am creating a plugin where you can give player a amount of "keys" with a command
    but how can i do that please help

    main class:
    http://pastebin.com/pTz9juqN




    sorry for bad english
     
  2. Online

    timtower Administrator Administrator Moderator

    @DaanSander And what is the part that you need help with then?
     
  3. Offline

    DaanSander

    the arguments how many "keys " and the arguments to send it to that player
     
  4. Online

    timtower Administrator Administrator Moderator

    @DaanSander What have you tried already with arguments? Because the current code doesn't show any of it
     
  5. Offline

    unrealdesign

    After skimming your code, "MyAPI" is never imported or declared and you're statically referencing it.

    Edit: After you posted later I see that "MyAPI" is in the same package. My mistake.
     
    Last edited: Jan 13, 2015
  6. Offline

    Coopah

    @DaanSander
    Alright, so that code is almost completely wrong.

    You're adding a statement which is checking if it's a certain command then you're saying else if it's not that command do this.

    Start off with something like this,
    Code:
    if (cmd.getName().equalsIgnoreCase("test") {
                   if (args.length == 1) {
                            p.sendMessage("First argument");
    } else if (args.length ==2) {
                      p.sendMessage("Second argument");
    }
    }
     
  7. Offline

    DaanSander



    Thx i have 1 question left how can i use the second argument to add "keys" what i put in the second argument

    Code:
    Player target = Bukkit.getPlayerExact(args[0]);
                    MyAPI.giveKeys(target, args[1]);
                    target.sendMessage(args[1] + "ยง2Keys has been added to your account!");


    yes i tried this but it wont work

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

    Coopah

    @DaanSander
    I really don't know what you mean by "keys". You're code is really unclear and messy. Sorry I can't help unless you give me a better definition or some code that keys is.
     
  9. Offline

    DaanSander



    Keys is a interger stored in another class
    I got 2 interger keys and silver


    API class:
    http://pastebin.com/UNqcXm67
     
    Last edited: Jan 13, 2015
  10. Offline

    Coopah

    @DaanSander
    I don't really understand the question, but as far as I can tell, you would want to do:
    Code:
    if (args.length == 2) {
    MyAPI.giveKeys(p, amount);
    }
     
  11. Online

    timtower Administrator Administrator Moderator

    @DaanSander Doesn't work as in? I won't accept "Doesn't work" without any prove
     
  12. Offline

    DaanSander

    what i mean is on that command give keys to the target argument 0 and ammount arg 1 so if do the command like
    test DaanSander 12 it would send the player 12 keys


    the method givekeys(Player, int) int the type MyAPI is not applicable for the arguments (Player, String)

    thats the error that i get

    EDIT by Timtower: merged posts
     
  13. Online

    timtower Administrator Administrator Moderator

    @DaanSander So you are using a string array and are surprised that it won't auto-convert to integer? Has nothing to do with arguments, just types
     
  14. Offline

    DaanSander

    so what do i have to do then?
     
  15. Online

    timtower Administrator Administrator Moderator

    You need to convert it to an integer
     
  16. Offline

    DaanSander


    how can i do that??
     
  17. Online

    timtower Administrator Administrator Moderator

    Tried google already?
     
  18. @DaanSander If you still can't figure it out, here's a hint: Think about Integers... how would one parse an int from a String? ;)
     
  19. Offline

    DaanSander


    yes

    The only thing what i want is just when i type the command
    /test DaanSander 10
    it would give the player 10 keys

    EDIT by Timtower: merged posts
     
  20. Online

    timtower Administrator Administrator Moderator

    @DaanSander Converting string to int is something that you will use more often though.
    What did you google search got you?
     
  21. Offline

    DaanSander


    converting string to int when specifying itemid
    videos about arguments
    javadoc
    php videos
     
  22. Online

    timtower Administrator Administrator Moderator

  23. Offline

    DaanSander

    I finaly found a website how to do that its says

    In Java, i use this:
    String PixelBreite = JOptionPane.showInputDialog(null,"PixelBreite eingeben: " , "PixelBreite");
    x = Integer.parseInt(PixelBreite);

    That works perfectly in java, but when i would do the same thing in Bukkit, like:
    String amount = args[0];
    x = Integer.parseInt(amount)

    But i dont really get how to use this:

    String amount = args[0]
    x = Integer.parseInt(amount)
     
  24. I'm not sure how these were really meant to find what you were looking for - the javadoc search was probably the closest of these to finding a meaningful result, but the problem with them is that you need to know roughly what it is you're looking for before you're able to find it.

    I see what your logic was here, but it actually betrays a big problem with your approach to the problem: your focus is far too narrow. Right now, when you're making these plugins, you're probably thinking to yourself "I'm programming a Bukkit plugin!". That's an understandable view to take, but it's a stumbling point that you need to overcome. You're not programming in Bukkit, you're programming in Java. Bukkit is merely an API, Java is the main thing you need to know about. Once you know the actual language, then you can know the API. And converting a String to an int is not something you do in Bukkit - there's no possible way you can use Bukkit to convert a String to an int. That's something you accomplish with Java.
     
  25. Offline

    DaanSander

    Can you just tell me how to make a command like
    /givekeys <User> <amount>
     
  26. Online

    timtower Administrator Administrator Moderator

  27. Offline

    Crazyyy

    Search around you will find it eventually
     
  28. Offline

    Coopah

    Come on now, this guy is clearly a out right beginner. Go easy on him. By giving him hints that he will never understand due to have lack of knowledge wont help him.

    @DaanSander
    You need to check each argument. Start off by checking the lengths (args.length). Then to check a player name use:
    Code:
    Player p = Bukkit.getServer().getPlayer(args[number]);
    I suggest making a check to see if that player isn't equal to nothing as well.

    Next to the int, to get a int from a string you'll have to create a int:
    Code:
    int i = 0;
    Then to the string part do:
    Code:
    i= Integer.parseInt(args[number]);
    Made up off the top of my head!

    That's how you get all the stuff you'll need to create the command. I'm not going to spoonfeed you anymore code on how to make the command.
     
  29. @Coopah And spoon-feeding him code that doesn't work isn't helpful either :p
     
    Coopah likes this.
  30. Offline

    Coopah

    @AdamQpzm
    What doesn't work?

    Ohh I see now. I ment to type "i" not amount.

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Jan 13, 2015
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page