开发者

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&l开发者_高级运维t;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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜