L2JMobius

C6 Respawn problem

ihearcolors · 6 · 7675

Offline ihearcolors

  • Knight
  • ***
    • Posts: 53
    • L2Interlude
After this error occurs:
Code: [Select]
Exception in thread "pool-2-thread-81" java.util.ConcurrentModificationException
        at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1012)
        at java.base/java.util.ArrayList$Itr.next(ArrayList.java:966)
        at org.l2jmobius.gameserver.model.actor.instance.MonsterInstance.onSpawn(MonsterInstance.java:119)
        at org.l2jmobius.gameserver.model.WorldObject.spawnMe(WorldObject.java:284)
        at org.l2jmobius.gameserver.model.spawn.Spawn.initializeNpcInstance(Spawn.java:480)
        at org.l2jmobius.gameserver.model.spawn.Spawn.respawnNpc(Spawn.java:550)
        at org.l2jmobius.gameserver.taskmanager.RespawnTaskManager.lambda$new$0(RespawnTaskManager.java:55)
        at org.l2jmobius.commons.concurrent.RunnableWrapper.run(RunnableWrapper.java:38)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
        at java.base/java.lang.Thread.run(Thread.java:832)

Mobs do not respawn anymore


Online Mobius

  • Distinguished King
  • *****
    • Posts: 16006
Try this.
Code: [Select]
Index: java/org/l2jmobius/gameserver/model/actor/Creature.java
===================================================================
--- java/org/l2jmobius/gameserver/model/actor/Creature.java (revision 7187)
+++ java/org/l2jmobius/gameserver/model/actor/Creature.java (working copy)
@@ -19,8 +19,8 @@
 import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -3332,13 +3332,11 @@
  */
  private List<Effect> effectQueueInsert(Effect newStackedEffect, List<Effect> stackQueue)
  {
- // Create an Iterator to go through the list of stacked effects in progress on the Creature
- final Iterator<Effect> queueIterator = stackQueue.iterator();
+ // Go through the list of stacked effects in progress on the Creature.
  int i = 0;
- while (queueIterator.hasNext())
+ for (Effect effect : stackQueue)
  {
- final Effect cur = queueIterator.next();
- if (newStackedEffect.getStackOrder() < cur.getStackOrder())
+ if (newStackedEffect.getStackOrder() < effect.getStackOrder())
  {
  i++;
  }
@@ -6280,17 +6278,13 @@
 
  if (target instanceof MinionInstance)
  {
- ((MinionInstance) target).getLeader().stopHating(this);
-
- final List<MinionInstance> spawnedMinions = ((MinionInstance) target).getLeader().getSpawnedMinions();
- if ((spawnedMinions != null) && !spawnedMinions.isEmpty())
+ final MonsterInstance leader = ((MinionInstance) target).getLeader();
+ leader.stopHating(this);
+ if (leader.hasMinions())
  {
- final Iterator<MinionInstance> itr = spawnedMinions.iterator();
- MinionInstance minion;
- while (itr.hasNext())
+ for (MinionInstance minion : leader.getSpawnedMinions())
  {
- minion = itr.next();
- if (((MinionInstance) target).getLeader().getMostHated() == null)
+ if (leader.getMostHated() == null)
  {
  ((AttackableAI) minion.getAI()).setGlobalAggro(-25);
  minion.clearAggroList();
@@ -6302,7 +6296,7 @@
  ((AttackableAI) minion.getAI()).setGlobalAggro(-25);
  minion.clearAggroList();
  minion.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
- minion.addDamage(((MinionInstance) target).getLeader().getMostHated(), 100);
+ minion.addDamage(leader.getMostHated(), 100);
  }
  }
  }
@@ -6310,14 +6304,11 @@
  else
  {
  ((Attackable) target).stopHating(this);
- final List<MinionInstance> spawnedMinions = ((MonsterInstance) target).getSpawnedMinions();
+ final Collection<MinionInstance> spawnedMinions = ((MonsterInstance) target).getSpawnedMinions();
  if ((spawnedMinions != null) && !spawnedMinions.isEmpty())
  {
- final Iterator<MinionInstance> itr = spawnedMinions.iterator();
- MinionInstance minion;
- while (itr.hasNext())
+ for (MinionInstance minion : spawnedMinions)
  {
- minion = itr.next();
  if (((Attackable) target).getMostHated() == null)
  {
  ((AttackableAI) minion.getAI()).setGlobalAggro(-25);
@@ -8051,16 +8042,13 @@
 
  if (creature instanceof MinionInstance)
  {
- ((MinionInstance) creature).getLeader().stopHating(this);
- final List<MinionInstance> spawnedMinions = ((MonsterInstance) creature).getSpawnedMinions();
- if ((spawnedMinions != null) && !spawnedMinions.isEmpty())
+ final MonsterInstance leader = ((MinionInstance) creature).getLeader();
+ leader.stopHating(this);
+ if (leader.hasMinions())
  {
- final Iterator<MinionInstance> itr = spawnedMinions.iterator();
- MinionInstance minion;
- while (itr.hasNext())
+ for (MinionInstance minion : leader.getSpawnedMinions())
  {
- minion = itr.next();
- if (((Attackable) creature).getMostHated() == null)
+ if (leader.getMostHated() == null)
  {
  ((AttackableAI) minion.getAI()).setGlobalAggro(-25);
  minion.clearAggroList();
@@ -8080,14 +8068,11 @@
  else
  {
  ((Attackable) creature).stopHating(this);
- final List<MinionInstance> spawnedMinions = ((MonsterInstance) creature).getSpawnedMinions();
+ final Collection<MinionInstance> spawnedMinions = ((MonsterInstance) creature).getSpawnedMinions();
  if ((spawnedMinions != null) && !spawnedMinions.isEmpty())
  {
- final Iterator<MinionInstance> itr = spawnedMinions.iterator();
- MinionInstance minion;
- while (itr.hasNext())
+ for (MinionInstance minion : spawnedMinions)
  {
- minion = itr.next();
  if (((Attackable) creature).getMostHated() == null)
  {
  ((AttackableAI) minion.getAI()).setGlobalAggro(-25);
Index: java/org/l2jmobius/gameserver/model/actor/instance/MonsterInstance.java
===================================================================
--- java/org/l2jmobius/gameserver/model/actor/instance/MonsterInstance.java (revision 7034)
+++ java/org/l2jmobius/gameserver/model/actor/instance/MonsterInstance.java (working copy)
@@ -16,8 +16,7 @@
  */
 package org.l2jmobius.gameserver.model.actor.instance;
 
-import java.util.Iterator;
-import java.util.List;
+import java.util.Collection;
 import java.util.concurrent.ScheduledFuture;
 
 import org.l2jmobius.Config;
@@ -28,7 +27,6 @@
 import org.l2jmobius.gameserver.model.actor.knownlist.MonsterKnownList;
 import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
 import org.l2jmobius.gameserver.model.spawn.Spawn;
-import org.l2jmobius.gameserver.network.serverpackets.SocialAction;
 import org.l2jmobius.gameserver.util.MinionList;
 
 /**
@@ -114,32 +112,8 @@
 
  if (getTemplate().getMinionData() != null)
  {
- try
- {
- for (MinionInstance minion : _minionList.getSpawnedMinions())
- {
- if (minion == null)
- {
- continue;
- }
- _minionList.getSpawnedMinions().remove(minion);
- minion.deleteMe();
- }
- _minionList.clearRespawnList();
-
- manageMinions();
- }
- catch (NullPointerException e)
- {
- }
-
- switch (getTemplate().getNpcId())
- {
- case 12372: // baium
- {
- broadcastPacket(new SocialAction(getObjectId(), 2));
- }
- }
+ _minionList.clearRespawnList();
+ manageMinions();
  }
  }
 
@@ -193,26 +167,19 @@
  {
  if (_minionList.hasMinions())
  {
- final List<MinionInstance> spawnedMinions = _minionList.getSpawnedMinions();
- if ((spawnedMinions != null) && !spawnedMinions.isEmpty())
+ for (MinionInstance minion : _minionList.getSpawnedMinions())
  {
- final Iterator<MinionInstance> itr = spawnedMinions.iterator();
- MinionInstance minion;
- while (itr.hasNext())
+ // Trigger the aggro condition of the minion
+ if ((minion != null) && !minion.isDead())
  {
- minion = itr.next();
- // Trigger the aggro condition of the minion
- if ((minion != null) && !minion.isDead())
+ if (this instanceof RaidBossInstance)
  {
- if (this instanceof RaidBossInstance)
- {
- minion.addDamage(attacker, 100);
- }
- else
- {
- minion.addDamage(attacker, 1);
- }
+ minion.addDamage(attacker, 100);
  }
+ else
+ {
+ minion.addDamage(attacker, 1);
+ }
  }
  }
  }
@@ -242,7 +209,7 @@
  * Gets the spawned minions.
  * @return the spawned minions
  */
- public List<MinionInstance> getSpawnedMinions()
+ public Collection<MinionInstance> getSpawnedMinions()
  {
  return _minionList.getSpawnedMinions();
  }
@@ -321,17 +288,6 @@
  */
  public void deleteSpawnedMinions()
  {
- for (MinionInstance minion : _minionList.getSpawnedMinions())
- {
- if (minion == null)
- {
- continue;
- }
- minion.abortAttack();
- minion.abortCast();
- minion.deleteMe();
- _minionList.getSpawnedMinions().remove(minion);
- }
  _minionList.clearRespawnList();
  }
 
Index: java/org/l2jmobius/gameserver/util/MinionList.java
===================================================================
--- java/org/l2jmobius/gameserver/util/MinionList.java (revision 7034)
+++ java/org/l2jmobius/gameserver/util/MinionList.java (working copy)
@@ -16,9 +16,8 @@
  */
 package org.l2jmobius.gameserver.util;
 
-import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -34,41 +33,30 @@
 import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
 import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
 
-/**
- * @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $
- */
 public class MinionList
 {
- /** List containing the current spawned minions for this MonsterInstance */
- private final List<MinionInstance> minionReferences;
+ private final Set<MinionInstance> _minionReferences = ConcurrentHashMap.newKeySet();
  protected Map<Long, Integer> _respawnTasks = new ConcurrentHashMap<>();
- private final MonsterInstance master;
+ private final MonsterInstance _master;
 
- public MinionList(MonsterInstance pMaster)
+ public MinionList(MonsterInstance master)
  {
- minionReferences = new ArrayList<>();
- master = pMaster;
+ _master = master;
  }
 
  public int countSpawnedMinions()
  {
- synchronized (minionReferences)
- {
- return minionReferences.size();
- }
+ return _minionReferences.size();
  }
 
  public int countSpawnedMinionsById(int minionId)
  {
  int count = 0;
- synchronized (minionReferences)
+ for (MinionInstance minion : _minionReferences)
  {
- for (MinionInstance minion : minionReferences)
+ if (minion.getNpcId() == minionId)
  {
- if (minion.getNpcId() == minionId)
- {
- count++;
- }
+ count++;
  }
  }
  return count;
@@ -76,26 +64,23 @@
 
  public boolean hasMinions()
  {
- return !minionReferences.isEmpty();
+ return !_minionReferences.isEmpty();
  }
 
- public List<MinionInstance> getSpawnedMinions()
+ public Collection<MinionInstance> getSpawnedMinions()
  {
- return minionReferences;
+ return _minionReferences;
  }
 
  public void addSpawnedMinion(MinionInstance minion)
  {
- synchronized (minionReferences)
- {
- minionReferences.add(minion);
- }
+ _minionReferences.add(minion);
  }
 
  public int lazyCountSpawnedMinionsGroups()
  {
  final Set<Integer> seenGroups = new HashSet<>();
- for (MinionInstance minion : minionReferences)
+ for (MinionInstance minion : _minionReferences)
  {
  seenGroups.add(minion.getNpcId());
  }
@@ -104,32 +89,25 @@
 
  public void removeSpawnedMinion(MinionInstance minion)
  {
- synchronized (minionReferences)
- {
- minionReferences.remove(minion);
- }
+ _minionReferences.remove(minion);
  }
 
  public void moveMinionToRespawnList(MinionInstance minion)
  {
  final Long current = System.currentTimeMillis();
- synchronized (minionReferences)
+ _minionReferences.remove(minion);
+ if (_respawnTasks.get(current) == null)
  {
- minionReferences.remove(minion);
- if (_respawnTasks.get(current) == null)
+ _respawnTasks.put(current, minion.getNpcId());
+ }
+ else
+ {
+ for (int i = 1; i < 30; i++)
  {
- _respawnTasks.put(current, minion.getNpcId());
- }
- else
- {
- // nice AoE
- for (int i = 1; i < 30; i++)
+ if (_respawnTasks.get(current + i) == null)
  {
- if (_respawnTasks.get(current + i) == null)
- {
- _respawnTasks.put(current + i, minion.getNpcId());
- break;
- }
+ _respawnTasks.put(current + i, minion.getNpcId());
+ break;
  }
  }
  }
@@ -137,6 +115,18 @@
 
  public void clearRespawnList()
  {
+ for (MinionInstance minion : _minionReferences)
+ {
+ if (minion == null)
+ {
+ continue;
+ }
+
+ minion.abortAttack();
+ minion.abortCast();
+ minion.deleteMe();
+ }
+ _minionReferences.clear();
  _respawnTasks.clear();
  }
 
@@ -145,7 +135,7 @@
  */
  public void maintainMinions()
  {
- if ((master == null) || master.isAlikeDead())
+ if ((_master == null) || _master.isAlikeDead())
  {
  return;
  }
@@ -175,27 +165,22 @@
  */
  public void spawnMinions()
  {
- if ((master == null) || master.isAlikeDead())
+ if ((_master == null) || _master.isAlikeDead())
  {
  return;
  }
 
- final List<MinionData> minions = master.getTemplate().getMinionData();
-
- synchronized (minionReferences)
+ int minionCount;
+ int minionId;
+ int minionsToSpawn;
+ for (MinionData minion : _master.getTemplate().getMinionData())
  {
- int minionCount;
- int minionId;
- int minionsToSpawn;
- for (MinionData minion : minions)
+ minionCount = minion.getAmount();
+ minionId = minion.getMinionId();
+ minionsToSpawn = minionCount - countSpawnedMinionsById(minionId);
+ for (int i = 0; i < minionsToSpawn; i++)
  {
- minionCount = minion.getAmount();
- minionId = minion.getMinionId();
- minionsToSpawn = minionCount - countSpawnedMinionsById(minionId);
- for (int i = 0; i < minionsToSpawn; i++)
- {
- spawnSingleMinion(minionId);
- }
+ spawnSingleMinion(minionId);
  }
  }
  }
@@ -221,10 +206,10 @@
 
  // Set the Minion HP, MP and Heading
  monster.setCurrentHpMp(monster.getMaxHp(), monster.getMaxMp());
- monster.setHeading(master.getHeading());
+ monster.setHeading(_master.getHeading());
 
  // Set the Minion leader to this RaidBoss
- monster.setLeader(master);
+ monster.setLeader(_master);
 
  // Init the position of the Minion and add it in the world as a visible object
  int spawnConstant;
@@ -237,7 +222,7 @@
  spawnConstant *= -1;
  }
 
- final int newX = master.getX() + spawnConstant;
+ final int newX = _master.getX() + spawnConstant;
  spawnConstant = Rnd.get(randSpawnLim);
  randPlusMin = Rnd.get(2);
  if (randPlusMin == 1)
@@ -245,13 +230,13 @@
  spawnConstant *= -1;
  }
 
- final int newY = master.getY() + spawnConstant;
- monster.spawnMe(newX, newY, master.getZ());
+ final int newY = _master.getY() + spawnConstant;
+ monster.spawnMe(newX, newY, _master.getZ());
 
  // Assist master
- if (!master.getAggroList().isEmpty())
+ if (!_master.getAggroList().isEmpty())
  {
- monster.getAggroList().putAll(master.getAggroList());
+ monster.getAggroList().putAll(_master.getAggroList());
  monster.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, monster.getAggroList().keySet().stream().findFirst().get());
  }
  }