Skip task manager tasks when working.

This commit is contained in:
MobiusDevelopment
2020-03-30 17:21:37 +00:00
parent c9601fac2a
commit 7cd9f35b43
71 changed files with 507 additions and 24 deletions

View File

@ -36,18 +36,15 @@ public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
public static final long COMBAT_TIME = 15000;
private AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
}
public static AttackStanceTaskManager getInstance()
{
return SingletonHolder.INSTANCE;
}
public void addAttackStanceTask(Creature actor)
{
if (actor instanceof Summon)
@ -108,7 +105,7 @@ public class AttackStanceTaskManager
for (Entry<Creature, Long> entry : _attackStanceTasks.entrySet())
{
final Creature actor = entry.getKey();
if ((current - entry.getValue()) > 15000)
if ((current - entry.getValue()) > COMBAT_TIME)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
if ((actor instanceof PlayerInstance) && (((PlayerInstance) actor).getPet() != null))
@ -130,6 +127,15 @@ public class AttackStanceTaskManager
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager
*/
public static AttackStanceTaskManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final AttackStanceTaskManager INSTANCE = new AttackStanceTaskManager();

View File

@ -31,11 +31,18 @@ import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
public class RandomAnimationTaskManager
{
private static final Map<NpcInstance, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
private static boolean _working = false;
public RandomAnimationTaskManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long time = System.currentTimeMillis();
for (Entry<NpcInstance, Long> entry : PENDING_ANIMATIONS.entrySet())
{
@ -49,6 +56,8 @@ public class RandomAnimationTaskManager
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
}
}
_working = false;
}, 0, 1000);
}

View File

@ -30,11 +30,18 @@ import org.l2jmobius.gameserver.model.spawn.Spawn;
public class RespawnTaskManager
{
private static final Map<NpcInstance, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
private static boolean _working = false;
public RespawnTaskManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long time = System.currentTimeMillis();
for (Entry<NpcInstance, Long> entry : PENDING_RESPAWNS.entrySet())
{
@ -50,6 +57,8 @@ public class RespawnTaskManager
}
}
}
_working = false;
}, 0, 1000);
}