Inventory Items?

Discussion in 'Plugin Development' started by mehboss, Oct 6, 2016.

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

    mehboss

    Alright, time to keep this short. If I wanted a GUI to only add certain items that are in the GUI, how would I do it.

    Example:
    Code:
    EXAMPLE CONFIG:
    
    [1]:
      Item[1]-displayname: 'test'
      Item[1]-lore: 'item 1 lore test'
      Item[1]-slot: '0'
      Item[1]-command: '/test1command'
    # I want item 1 to not be togglable, I can do that on my #own
    
    [2]:
      Item[2]-displayname: 'test'
      Item[2]-enabled: 'true'
      Item[2]-lore: 'item 2 lore test'
      Item[2]-slot: '1'
      Item[2]-command: '/test2command'
    # I want item 2 to only "exist" if the player puts it in #there. If it isn't in there, I want it to be like it never #"exists".
    
    # AND SO ON
    I put explanations inside it. Also if it consists of that i++ thing, can you please link some links explaining everything in it or tell me what they do. I do not like adding things if I don't know what they do because it gets really complicated when I want to add things to them.

    ~ Thank you in advance. :)
    Also please provide examples if it contains a lot of steps or if most people do not know what it is (your choice).
     
    Last edited: Oct 6, 2016
  2. Offline

    Whoneedspacee

    You don't seem to understand coding at all, since you seem confused with a simple for loop, I recommend looking up a few java tutorials, or plugin tutorials.
     
  3. Offline

    kameronn

    How an i++ for loop works

    Example:
    Code:
    for(int i=0; i < 10; i++) {
    i++; means add 1 to the current number of that integer, the start states the the i is equal to 0 and that if i is less than 10 then it will add one more.

    This means that while i is less then 10 it will run the code that is inside the bracket 11 times and you can use this many ways. It does not loop 10 times because it is i less than, not less than or equal to so the integer has to be 11 before the loop is complete.

    Code:
    for(int i=0; i < 10;i++) {
    System.out.println("Count: " + i); // this one will print out 0,1,2,3,4,5,6,7,8,9,10 looping 11 times
    }
    System.out.println("Loop is done, this is outside the for loop so it will only be run once, however the first one will be run 10 times.");
    What can this be used for in your case?
    Make int i equals a number and check if its less than the size of your loop. then use config.getlist("list").get(i) to get a certain part of your list
     
  4. Offline

    mehboss

    @kameronn
    like this?

    Code:
    for(int i=0; i < 10;i++) {
    if (int i=1 | int i < 10);
    config.getList("list").get(i)
    //menu stuff
    
    if (int i=2 | int i < 10);
    config.getList("list").get(i)
    //menu stuff
    
    if (int i=3 | int i < 10);
    config.getList("list").get(i)
    //menu stuff
    
    ect
    
    thanks bud, did I ask for your criticism?
     
    Last edited: Oct 6, 2016
  5. Offline

    Lordloss

    The post of @Whoneedspacee wasn 't rude, it was simply the truth. If you dont know the basics of java, you have to learn them. If you want to use the Bukkit API you have to know java. In your case is a enhanced for-loop much simpler to use than the one @kameronn showed you. Get the GUI contents as List, iterate over it and add them to the player inventory.
     
  6. Offline

    Evonoucono

    I laughed so hard at this :D
    Is that supposed to be a demented for loop, or a demented if statement? Just a word of advice if an integer is equal to 2, it will always be less than 10, just so you know. Please look at these tutorials from oracle:
    https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
    https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html
    And understand that in the for loop the integer i will only assume one value per loop, so there is no need to check if it's equal to 1 or 2 or 3 etc...
    Not sure I understand the question. You basically just said you want a Graphical user interface with items that come from that same graphical user interface...
     
  7. Offline

    mehboss

    @Evonoucono

    LOL I meant, I wanted the GUI to only add certain items that are in the Config*

    Also evon, I was trying to make int I equal the number.. :(

    Also I understand that it gets the numbers 1-10, but how would I check to see if the int i is 1 and get the string 1 from config, then set the item in slot 0 to number item 1 if it is in the config, and if it isn't I want it to cancel it as if it never existed. I also want people to be able to have unlimited items by simply adding it to the config.
     
    Last edited: Oct 7, 2016
  8. @mehboss Why do you not just make like a String with inventoryType or something like that. Would be easier to identify for users and easier in the code. Would suggest making it an enum rather than String though. Pretty much same thing just makes it much easier to know if there are mistakes and gives a little more structure. To check a number if you do it that way just do I == Integer the same way you would with any condition. Not sure why 1, 2 and 3 are all inventory stuff though. The enum would make this easier but you can just use an OR. Which in Java is ||
    I == 1 || I == 2 etc

    Sorry for any spelling mistakes or whatever, on iPad.
     
  9. Offline

    mehboss

    @bwfcwalshy
    Is this what I would do if I wanted the menu to be able to have unlimited items on it as long as the numbers were in the config.

    For example:

    If there was only 1 and 2 in the config, it will only show those.

    If there were 1, 2, 3, 4, 5, it would only show those 5.

    and unlimited items ect
     
Thread Status:
Not open for further replies.

Share This Page