HashMaps or ArrayList?

Discussion in 'Plugin Development' started by Brett Basinger, Mar 30, 2014.

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

    Brett Basinger

    Hey I have a Question, for my plugin (kits), I was wondering if I should use a hashmap instead of an arraylist because I am trying to make it so that one a player who performs a command can get certain things... -Example- I want it so that only the kit vipers(Poison sword) diamond sword, is the only diamond that does that. Well I am running into a problem where every kit can do that now. I am using the arraylist (thought it would seperate it) but would a hashmap do that??

    Sorry I am learning java, my only source of help is from youtube. And I learning java from bukkit.

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

    JBoss925

    If u want, use a hash map and store the player's name and then the string of the class. For example:

    The player's name is JBoss925 he chose viper kit

    So store the key as: "JBoss925"

    and store the value as: "vipers"

    now when JBoss925 goes to do /kit tank

    get the key "JBoss925" and get the value "vipers".

    check if the output "vipers" is equal to "tank"

    since it is not don't allow him the kit.

    now he does /kit viper

    get the key "JBoss925" and get the value "vipers".

    check if the output "vipers" is equal to "vipers"

    since it is allow him the kit.

    That simple really.
     
    rbrick likes this.
  3. Offline

    jthort

    Hashmap:
    ArrayList:
    Take a look at http://javarevisited.blogspot.com/2011/05/example-of-arraylist-in-java-tutorial.html and http://stackoverflow.com/questions/6493605/how-does-a-hashmap-work-in-java for more information or a more detailed explanation.
     
Thread Status:
Not open for further replies.

Share This Page