List if they have perms.

Discussion in 'Plugin Development' started by SirLittlemonster7, Apr 3, 2013.

Thread Status:
Not open for further replies.
  1. I am making a plugin that lists kits. But I do not know how to make it like a format (like this)

    My Kits: kit, kit, kit, kit.

    Other Kits: kit, kit, kit, kit.

    And lets say they buy a kit it will remove one of the kits from the (other kits) and place it in (my kits) I cant seem to figure this out. I have tried else if statements, if statements. (I want it preferably using perms to list the kits you have)

    Does anyone have ideas?

    Please I need this quick.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Offline

    chasechocolate

    Use StringBuilders.
     
    SirLittlemonster7 and Codisimus like this.
  3. How do I use this.
     
  4. Offline

    LazyLemons

  5. Lazy, go away I don't really care what you think. I am not some kind of 'java god' like you. I am still learning -_- I just started java like a couple months ago.
     
  6. If you've started a couple of months ago then you should understand this.

    Assuming you have a List or array... first make sure it has at least one element.
    First create a new StringBuilder object and store it, then use append() method with the first element of the list/array as value.
    Then start a for() loop with integers starting from 1 to less than list/array's size and on each iteration append ", " and then the list/array's value at that index.
     
  7. Offline

    chasechocolate

    Digi that can cause an extra ", " at the end, so it's best to check if the sb.length() > 2 and then sb.setLength(sb.length() - 2) (where your "sb" variable is the StringBuilder) to remove the extra ", " at the end.

    EDIT: Never mind, what you have is fine, usually people just loop through and append the art and append a ", ".
     
  8. I dont really get how this works. Could you give me an example.. Also its not a list, or hashmap its a permission that im using.
     
  9. Offline

    HackintoshMan

    I never actually learned java…I looked at a plugin and just started editing stuff and I learned as I went…Im not the best at java, but Im able to make a TF2 plugin like MCTF2.com for a server that I play on
     
  10. Offline

    ZeusAllMighty11

    Code:
    StringBuilder sb = new StringBuilder();
    sb.append(someValue + ",");
     
  11. TheGreenGamerHD
    You're creating 2 StringBuilder objects there, if you're going to use a StringBuilder don't use concatenation (+), use append().

    SirLittlemonster7
    Code:
    StringBuilder s = new StringBuilder();
    
    for(String name : kitsList) // iterate through all possible kits list
    {
        if(player.hasPermissionForThisKit()) // check whatever you want here
        {
            if(s.length() > 0)
            {
                s.append(", ");
            }
    
            s.append(name);
        }
    }
    
    if(s.length() == 0)
    {
        s.append("Nothing"); // if player has no kits then do this
    }
    
    // Now use s.toString() to print the list.
    
     
Thread Status:
Not open for further replies.

Share This Page