Solved Hashmap Help

Discussion in 'Plugin Development' started by Giorgio, Nov 27, 2012.

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

    Giorgio

    Hello everyone I recently created a plugin called Simplepvpkits. The plugin allows you to give yourself pre-made kits/classes.

    Question:

    Ive defined a hashmap in my main class. But now I when a player dies i want to remove them from the hashmap using the PlayerDeathEvent. Which is located in a Different class. Now when i defined the Hashmap in the other class I basicly made a hashmap that is not listening to the one in my main class. How can I make it so both Hashmaps are the same?
     
  2. Offline

    zack6849

    Use the istance of your main class if they're in the same class
    ie:
    Main.hashmapname
     
  3. Offline

    Giorgio

    erm, what do you mean. Main.hashmap doesn't work.

    hashmap being the name of course.
     
  4. Offline

    Tirelessly

    It would if the hashmap was static, or you could learn what object oriented programming is and use your main class' instance.
     
  5. Offline

    Giorgio

    Sorry uhm what?!?!?
     
  6. Offline

    Jogy34

    Use a get method in your main class that returns the HashMap.

    As a side note don't store Player objects, it causes memory leeks.
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    You should be passing in the main class into the listener, so that it has a reference to the main class and in turn the hash map.
     
  8. Offline

    Giorgio

    Sorry guys, im more of a visual learner. So im getting really confused.
     
  9. Offline

    Jogy34

    Some where in your main class:
    Code:
    public HashMap<Object1, Object2> getHashMap()
    {
        return hashMap;
    }
    
    Then in your listener class you can call plugin.getHashMap() to get the HashMap. You just have to replace it with the right variables
     
  10. Offline

    Giorgio

    Oh that makes sence, thank you.
     
  11. Offline

    ZeusAllMighty11 Retired Staff

    Or you could do it with statics; but I don't reccomend it

    Code:
    public static HashMap<Value, Key>someName = new HashMap<Value, Key>();
    
    Then call it using ClassName.someName
     
Thread Status:
Not open for further replies.

Share This Page