简体   繁体   中英

Java trying to get all cached

I'm caching some certain players on my little game and now in my run method I want to check everyone who is cached and give them their reward, insted of getAllplayersOnline and check if they are in that certain map, I just cached the ones enter that map.

public static HashMap<Integer,MapleCharacter> fishlist = 
               new HashMap<Integer,MapleCharacter>();

Then I put

fishlist.put(chr.getId(), chr);

now in my run method i tried

                 if(UseChairHandler.fishlist.containsKey(chr.getId())) {
//do stuff

but it didn't work...any ideas?

the entryset allows you to loop over the entire map

for(Map.Entry<Integer,MapleCharacter> entry:fishlist.entrySet() ){
    //entry.value() is a MapleCharacter in the map
}

Add more debug output. A System.err.println(fishlist) can do wonders. Is chr.getId() always returning the correct ID? Also, if your game is multi-threaded, you will run into problems if you don't properly synchronize access to the map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM