Faction Mobs

Faction Mobs

72.2k Downloads

Error in console Task #55

Resoluciones opened this issue ยท 4 comments

commented

What were you doing when this happened? Everything is coded to run synchronously so this should never happen. Are you running some custom version of CB/Spigot?

commented

Hi Scyntrus, I'm not sure unfortunately what originated that eror, I just saw the error in console but I was not online.

I'm running last Paper build, but I didn't notice any change or problem with FM when I replaced the Spigot some months ago.

commented

ConcurrentModificationExceptions don't only happen in multi threaded environments but also when a collection is modified while iterating. In this case, because something inside this loop adds or removes values from FactionMobs.mobList while iterating over it.

            for (FactionMob fmob : FactionMobs.mobList) {...

Easiest fix would be to make mobList a CopyOnWriteArrayList or to produce a concurrent hash set from a ConcurrentHashMap.

    public static Set<FactionMob> mobList = Collections.newSetFromMap(new ConcurrentHashMap<FactionMob, Object>());
    public static Set<FactionMob> mobList = ConcurrentHashMap.newKeySet(); // I think this is how it's done in Java 8?

Instead, you could find out where the addition / removal of values happens, add them to a new collection outside of the loop and to do the actions after the loop.

commented

I'm aware of that and I already checked that my code doesn't directly modify the Set. However, since the addEntity function broadcasts and Event this error could happen if another plugin force kills the Entity right away.