Changed getAi method to synchronized.

This commit is contained in:
MobiusDevelopment
2019-11-03 20:52:05 +00:00
parent fb5302e0ab
commit 3ed4660df9
18 changed files with 39 additions and 148 deletions

View File

@ -2240,21 +2240,15 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
}
/**
* Return the CreatureAI of the Creature and if its null create a new one.
* @return the aI
* Gets this creature's AI.
* @return the AI
*/
public CreatureAI getAI()
public synchronized CreatureAI getAI()
{
CreatureAI ai = _ai;
if (ai == null)
{
synchronized (this)
{
if (_ai == null)
{
_ai = new CreatureAI(new AIAccessor());
}
}
_ai = ai = new CreatureAI(new AIAccessor());
}
return ai;
}
@ -2265,8 +2259,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
*/
public void setAI(CreatureAI newAI)
{
CreatureAI oldAI = getAI();
CreatureAI oldAI = _ai;
if ((oldAI != null) && (oldAI != newAI) && (oldAI instanceof AttackableAI))
{
((AttackableAI) oldAI).stopAITask();