Solved Hashmap Help

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

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


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


    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


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


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

    hashmap being the name of course.
  4. Offline


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


    Sorry uhm what?!?!?
  6. Offline


    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


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


    Some where in your main class:
    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


    Oh that makes sence, thank you.
  11. Offline

    ZeusAllMighty11 Retired Staff

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

    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