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?
It would if the hashmap was static, or you could learn what object oriented programming is and use your main class' instance.
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.
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.
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
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