Runnable implementations for task manager classes.
This commit is contained in:
@ -34,7 +34,7 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
||||
* Attack stance task manager.
|
||||
* @author Luca Baldi
|
||||
*/
|
||||
public class AttackStanceTaskManager
|
||||
public class AttackStanceTaskManager implements Runnable
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
||||
|
||||
@ -43,52 +43,52 @@ public class AttackStanceTaskManager
|
||||
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
/**
|
||||
* Instantiates a new attack stance task manager.
|
||||
*/
|
||||
protected AttackStanceTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long current = Chronos.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
|
||||
Entry<Creature, Long> entry;
|
||||
Creature creature;
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long current = Chronos.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
|
||||
Entry<Creature, Long> entry;
|
||||
Creature creature;
|
||||
while (iterator.hasNext())
|
||||
entry = iterator.next();
|
||||
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
||||
{
|
||||
entry = iterator.next();
|
||||
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
||||
creature = entry.getKey();
|
||||
if (creature != null)
|
||||
{
|
||||
creature = entry.getKey();
|
||||
if (creature != null)
|
||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||
creature.getAI().setAutoAttacking(false);
|
||||
if (creature.isPlayer() && (((PlayerInstance) creature).getPet() != null))
|
||||
{
|
||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||
creature.getAI().setAutoAttacking(false);
|
||||
if (creature.isPlayer() && (((PlayerInstance) creature).getPet() != null))
|
||||
{
|
||||
((PlayerInstance) creature).getPet().broadcastPacket(new AutoAttackStop(((PlayerInstance) creature).getPet().getObjectId()));
|
||||
}
|
||||
((PlayerInstance) creature).getPet().broadcastPacket(new AutoAttackStop(((PlayerInstance) creature).getPet().getObjectId()));
|
||||
}
|
||||
iterator.remove();
|
||||
}
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Unless caught here, players remain in attack positions.
|
||||
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 0, 1000);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Unless caught here, players remain in attack positions.
|
||||
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,44 +26,47 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class AttackableThinkTaskManager
|
||||
public class AttackableThinkTaskManager implements Runnable
|
||||
{
|
||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public AttackableThinkTaskManager()
|
||||
protected AttackableThinkTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
CreatureAI ai;
|
||||
for (Attackable attackable : ATTACKABLES)
|
||||
{
|
||||
if (attackable.hasAI())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
CreatureAI ai;
|
||||
for (Attackable attackable : ATTACKABLES)
|
||||
{
|
||||
if (attackable.hasAI())
|
||||
ai = attackable.getAI();
|
||||
if (ai != null)
|
||||
{
|
||||
ai = attackable.getAI();
|
||||
if (ai != null)
|
||||
{
|
||||
ai.onEvtThink();
|
||||
}
|
||||
else
|
||||
{
|
||||
remove(attackable);
|
||||
}
|
||||
ai.onEvtThink();
|
||||
}
|
||||
else
|
||||
{
|
||||
remove(attackable);
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
else
|
||||
{
|
||||
remove(attackable);
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(Attackable attackable)
|
||||
|
@ -28,93 +28,96 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius, Gigi
|
||||
*/
|
||||
public class AutoPotionTaskManager
|
||||
public class AutoPotionTaskManager implements Runnable
|
||||
{
|
||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public AutoPotionTaskManager()
|
||||
protected AutoPotionTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
PLAYER: for (PlayerInstance player : PLAYERS)
|
||||
{
|
||||
if ((player == null) || player.isAlikeDead() || !player.isOnline() || player.isInOfflineMode() || (!Config.AUTO_POTIONS_IN_OLYMPIAD && player.isInOlympiadMode()))
|
||||
{
|
||||
return;
|
||||
remove(player);
|
||||
continue PLAYER;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
PLAYER: for (PlayerInstance player : PLAYERS)
|
||||
boolean success = false;
|
||||
if (Config.AUTO_HP_ENABLED)
|
||||
{
|
||||
if ((player == null) || player.isAlikeDead() || !player.isOnline() || player.isInOfflineMode() || (!Config.AUTO_POTIONS_IN_OLYMPIAD && player.isInOlympiadMode()))
|
||||
final boolean restoreHP = ((player.getStatus().getCurrentHp() / player.getMaxHp()) * 100) < Config.AUTO_HP_PERCENTAGE;
|
||||
HP: for (int itemId : Config.AUTO_HP_ITEM_IDS)
|
||||
{
|
||||
remove(player);
|
||||
continue PLAYER;
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
if (Config.AUTO_HP_ENABLED)
|
||||
{
|
||||
final boolean restoreHP = ((player.getStatus().getCurrentHp() / player.getMaxHp()) * 100) < Config.AUTO_HP_PERCENTAGE;
|
||||
HP: for (int itemId : Config.AUTO_HP_ITEM_IDS)
|
||||
final ItemInstance hpPotion = player.getInventory().getItemByItemId(itemId);
|
||||
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
||||
{
|
||||
final ItemInstance hpPotion = player.getInventory().getItemByItemId(itemId);
|
||||
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
||||
success = true;
|
||||
if (restoreHP)
|
||||
{
|
||||
success = true;
|
||||
if (restoreHP)
|
||||
{
|
||||
ItemHandler.getInstance().getItemHandler(hpPotion.getItemId()).useItem(player, hpPotion);
|
||||
player.sendMessage("Auto potion: Restored HP.");
|
||||
break HP;
|
||||
}
|
||||
ItemHandler.getInstance().getItemHandler(hpPotion.getItemId()).useItem(player, hpPotion);
|
||||
player.sendMessage("Auto potion: Restored HP.");
|
||||
break HP;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Config.AUTO_CP_ENABLED)
|
||||
}
|
||||
if (Config.AUTO_CP_ENABLED)
|
||||
{
|
||||
final boolean restoreCP = ((player.getStatus().getCurrentCp() / player.getMaxCp()) * 100) < Config.AUTO_CP_PERCENTAGE;
|
||||
CP: for (int itemId : Config.AUTO_CP_ITEM_IDS)
|
||||
{
|
||||
final boolean restoreCP = ((player.getStatus().getCurrentCp() / player.getMaxCp()) * 100) < Config.AUTO_CP_PERCENTAGE;
|
||||
CP: for (int itemId : Config.AUTO_CP_ITEM_IDS)
|
||||
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
||||
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
||||
{
|
||||
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
||||
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
||||
success = true;
|
||||
if (restoreCP)
|
||||
{
|
||||
success = true;
|
||||
if (restoreCP)
|
||||
{
|
||||
ItemHandler.getInstance().getItemHandler(cpPotion.getItemId()).useItem(player, cpPotion);
|
||||
player.sendMessage("Auto potion: Restored CP.");
|
||||
break CP;
|
||||
}
|
||||
ItemHandler.getInstance().getItemHandler(cpPotion.getItemId()).useItem(player, cpPotion);
|
||||
player.sendMessage("Auto potion: Restored CP.");
|
||||
break CP;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Config.AUTO_MP_ENABLED)
|
||||
}
|
||||
if (Config.AUTO_MP_ENABLED)
|
||||
{
|
||||
final boolean restoreMP = ((player.getStatus().getCurrentMp() / player.getMaxMp()) * 100) < Config.AUTO_MP_PERCENTAGE;
|
||||
MP: for (int itemId : Config.AUTO_MP_ITEM_IDS)
|
||||
{
|
||||
final boolean restoreMP = ((player.getStatus().getCurrentMp() / player.getMaxMp()) * 100) < Config.AUTO_MP_PERCENTAGE;
|
||||
MP: for (int itemId : Config.AUTO_MP_ITEM_IDS)
|
||||
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
||||
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
||||
{
|
||||
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
||||
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
||||
success = true;
|
||||
if (restoreMP)
|
||||
{
|
||||
success = true;
|
||||
if (restoreMP)
|
||||
{
|
||||
ItemHandler.getInstance().getItemHandler(mpPotion.getItemId()).useItem(player, mpPotion);
|
||||
player.sendMessage("Auto potion: Restored MP.");
|
||||
break MP;
|
||||
}
|
||||
ItemHandler.getInstance().getItemHandler(mpPotion.getItemId()).useItem(player, mpPotion);
|
||||
player.sendMessage("Auto potion: Restored MP.");
|
||||
break MP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
player.sendMessage("Auto potion: You are out of potions!");
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 0, 1000);
|
||||
if (!success)
|
||||
{
|
||||
player.sendMessage("Auto potion: You are out of potions!");
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(PlayerInstance player)
|
||||
|
@ -36,9 +36,16 @@ public class BuyListTaskManager
|
||||
private static boolean _workingTimes = false;
|
||||
private static boolean _workingSaves = false;
|
||||
|
||||
public BuyListTaskManager()
|
||||
protected BuyListTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListTimeTask(), 1000, 60000);
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListSaveTask(), 50, 50);
|
||||
}
|
||||
|
||||
protected class BuyListTimeTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingTimes)
|
||||
{
|
||||
@ -64,9 +71,13 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingTimes = false;
|
||||
}, 1000, 60000);
|
||||
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
}
|
||||
}
|
||||
|
||||
protected class BuyListSaveTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingSaves)
|
||||
{
|
||||
@ -87,7 +98,7 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingSaves = false;
|
||||
}, 50, 50);
|
||||
}
|
||||
}
|
||||
|
||||
public void addTime(int timeValue, long updateValue)
|
||||
|
@ -40,9 +40,16 @@ public class CreatureFollowTaskManager
|
||||
private static boolean _workingNormal = false;
|
||||
private static boolean _workingAttack = false;
|
||||
|
||||
public CreatureFollowTaskManager()
|
||||
protected CreatureFollowTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(new CreatureFollowNormalTask(), 1000, 1000);
|
||||
ThreadPool.scheduleAtFixedRate(new CreatureFollowAttackTask(), 500, 500);
|
||||
}
|
||||
|
||||
protected class CreatureFollowNormalTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingNormal)
|
||||
{
|
||||
@ -56,9 +63,13 @@ public class CreatureFollowTaskManager
|
||||
}
|
||||
|
||||
_workingNormal = false;
|
||||
}, 1000, 1000);
|
||||
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
}
|
||||
}
|
||||
|
||||
protected class CreatureFollowAttackTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingAttack)
|
||||
{
|
||||
@ -72,7 +83,7 @@ public class CreatureFollowTaskManager
|
||||
}
|
||||
|
||||
_workingAttack = false;
|
||||
}, 500, 500);
|
||||
}
|
||||
}
|
||||
|
||||
private void follow(Creature creature, int range)
|
||||
|
@ -30,7 +30,7 @@ import org.l2jmobius.gameserver.model.actor.instance.RaidBossInstance;
|
||||
/**
|
||||
* @author la2 Lets drink to code!
|
||||
*/
|
||||
public class DecayTaskManager
|
||||
public class DecayTaskManager implements Runnable
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(DecayTaskManager.class.getName());
|
||||
|
||||
@ -38,7 +38,42 @@ public class DecayTaskManager
|
||||
|
||||
protected DecayTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(new DecayScheduler(), 10000, 5000);
|
||||
ThreadPool.scheduleAtFixedRate(this, 10000, 5000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final long currentTime = Chronos.currentTimeMillis();
|
||||
int delay;
|
||||
try
|
||||
{
|
||||
if (_decayTasks != null)
|
||||
{
|
||||
for (Entry<Creature, Long> entry : _decayTasks.entrySet())
|
||||
{
|
||||
final Creature actor = entry.getKey();
|
||||
if (actor instanceof RaidBossInstance)
|
||||
{
|
||||
delay = 30000;
|
||||
}
|
||||
else
|
||||
{
|
||||
delay = 8500;
|
||||
}
|
||||
if ((currentTime - entry.getValue().longValue()) > delay)
|
||||
{
|
||||
actor.onDecay();
|
||||
_decayTasks.remove(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
// TODO: Find out the reason for exception. Unless caught here, mob decay would stop.
|
||||
LOGGER.warning(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void addDecayTask(Creature actor)
|
||||
@ -62,48 +97,6 @@ public class DecayTaskManager
|
||||
}
|
||||
}
|
||||
|
||||
private class DecayScheduler implements Runnable
|
||||
{
|
||||
protected DecayScheduler()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final Long current = Chronos.currentTimeMillis();
|
||||
int delay;
|
||||
try
|
||||
{
|
||||
if (_decayTasks != null)
|
||||
{
|
||||
for (Entry<Creature, Long> entry : _decayTasks.entrySet())
|
||||
{
|
||||
final Creature actor = entry.getKey();
|
||||
if (actor instanceof RaidBossInstance)
|
||||
{
|
||||
delay = 30000;
|
||||
}
|
||||
else
|
||||
{
|
||||
delay = 8500;
|
||||
}
|
||||
if ((current - entry.getValue().longValue()) > delay)
|
||||
{
|
||||
actor.onDecay();
|
||||
_decayTasks.remove(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
// TODO: Find out the reason for exception. Unless caught here, mob decay would stop.
|
||||
LOGGER.warning(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@ -27,35 +27,38 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemManaTaskManager
|
||||
public class ItemManaTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static final int MANA_CONSUMPTION_RATE = 60000;
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemManaTaskManager()
|
||||
protected ItemManaTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long currentTime = Chronos.currentTimeMillis();
|
||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||
{
|
||||
if (currentTime > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
final ItemInstance item = entry.getKey();
|
||||
ITEMS.remove(item);
|
||||
item.decreaseMana(true);
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long currentTime = Chronos.currentTimeMillis();
|
||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||
{
|
||||
if (currentTime > entry.getValue().longValue())
|
||||
{
|
||||
final ItemInstance item = entry.getKey();
|
||||
ITEMS.remove(item);
|
||||
item.decreaseMana(true);
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item)
|
||||
|
@ -28,7 +28,7 @@ import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
import org.l2jmobius.gameserver.model.items.type.EtcItemType;
|
||||
|
||||
public class ItemsAutoDestroyTaskManager
|
||||
public class ItemsAutoDestroyTaskManager implements Runnable
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(ItemsAutoDestroyTaskManager.class.getName());
|
||||
|
||||
@ -36,16 +36,11 @@ public class ItemsAutoDestroyTaskManager
|
||||
|
||||
protected ItemsAutoDestroyTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(this::removeItems, 5000, 5000);
|
||||
ThreadPool.scheduleAtFixedRate(this, 5000, 5000);
|
||||
}
|
||||
|
||||
public synchronized void addItem(ItemInstance item)
|
||||
{
|
||||
item.setDropTime(Chronos.currentTimeMillis());
|
||||
_items.add(item);
|
||||
}
|
||||
|
||||
private synchronized void removeItems()
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_items.isEmpty())
|
||||
{
|
||||
@ -87,6 +82,12 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(ItemInstance item)
|
||||
{
|
||||
item.setDropTime(Chronos.currentTimeMillis());
|
||||
_items.add(item);
|
||||
}
|
||||
|
||||
public static ItemsAutoDestroyTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
|
@ -29,15 +29,15 @@ public class KnownListUpdateTaskManager
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(KnownListUpdateTaskManager.class.getName());
|
||||
|
||||
public KnownListUpdateTaskManager()
|
||||
protected KnownListUpdateTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(new KnownListUpdate(), 1000, 750);
|
||||
}
|
||||
|
||||
private class KnownListUpdate implements Runnable
|
||||
protected class KnownListUpdate implements Runnable
|
||||
{
|
||||
boolean toggle = false;
|
||||
boolean fullUpdate = true;
|
||||
boolean _toggle = false;
|
||||
boolean _fullUpdate = true;
|
||||
|
||||
protected KnownListUpdate()
|
||||
{
|
||||
@ -54,21 +54,21 @@ public class KnownListUpdateTaskManager
|
||||
{
|
||||
if (r.isActive()) // and check only if the region is active
|
||||
{
|
||||
updateRegion(r, fullUpdate, toggle);
|
||||
updateRegion(r, _fullUpdate, _toggle);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toggle)
|
||||
if (_toggle)
|
||||
{
|
||||
toggle = false;
|
||||
_toggle = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
toggle = true;
|
||||
_toggle = true;
|
||||
}
|
||||
if (fullUpdate)
|
||||
if (_fullUpdate)
|
||||
{
|
||||
fullUpdate = false;
|
||||
_fullUpdate = false;
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
|
@ -28,38 +28,41 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class PlayerAutoSaveTaskManager
|
||||
public class PlayerAutoSaveTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public PlayerAutoSaveTaskManager()
|
||||
protected PlayerAutoSaveTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final PlayerInstance player = entry.getKey();
|
||||
if ((player != null) && player.isOnline())
|
||||
{
|
||||
final PlayerInstance player = entry.getKey();
|
||||
if ((player != null) && player.isOnline())
|
||||
{
|
||||
player.autoSave();
|
||||
PLAYER_TIMES.put(entry.getKey(), time + Config.CHAR_DATA_STORE_INTERVAL);
|
||||
break SEARCH; // Prevent SQL flood.
|
||||
}
|
||||
player.autoSave();
|
||||
PLAYER_TIMES.put(entry.getKey(), time + Config.CHAR_DATA_STORE_INTERVAL);
|
||||
break SEARCH; // Prevent SQL flood.
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(PlayerInstance player)
|
||||
|
@ -26,43 +26,46 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class PvpFlagTaskManager
|
||||
public class PvpFlagTaskManager implements Runnable
|
||||
{
|
||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public PvpFlagTaskManager()
|
||||
protected PvpFlagTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
if (!PLAYERS.isEmpty())
|
||||
{
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (PlayerInstance player : PLAYERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
if (!PLAYERS.isEmpty())
|
||||
{
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (PlayerInstance player : PLAYERS)
|
||||
if (time > player.getPvpFlagLasts())
|
||||
{
|
||||
if (time > player.getPvpFlagLasts())
|
||||
{
|
||||
player.stopPvPFlag();
|
||||
}
|
||||
else if (time > (player.getPvpFlagLasts() - 5000))
|
||||
{
|
||||
player.updatePvPFlag(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.updatePvPFlag(1);
|
||||
}
|
||||
player.stopPvPFlag();
|
||||
}
|
||||
else if (time > (player.getPvpFlagLasts() - 5000))
|
||||
{
|
||||
player.updatePvPFlag(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.updatePvPFlag(1);
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(PlayerInstance player)
|
||||
|
@ -29,37 +29,40 @@ import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RandomAnimationTaskManager
|
||||
public class RandomAnimationTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<NpcInstance, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public RandomAnimationTaskManager()
|
||||
protected RandomAnimationTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<NpcInstance, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<NpcInstance, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final NpcInstance npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.isStunned() && !npc.isSleeping() && !npc.isParalyzed())
|
||||
{
|
||||
final NpcInstance npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.isStunned() && !npc.isSleeping() && !npc.isParalyzed())
|
||||
{
|
||||
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||
}
|
||||
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));
|
||||
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(NpcInstance npc)
|
||||
|
@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.spawn.Spawn;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
public class RespawnTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<NpcInstance, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public RespawnTaskManager()
|
||||
protected RespawnTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<NpcInstance, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<NpcInstance, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final NpcInstance npc = entry.getKey();
|
||||
PENDING_RESPAWNS.remove(npc);
|
||||
final Spawn spawn = npc.getSpawn();
|
||||
if (spawn != null)
|
||||
{
|
||||
final NpcInstance npc = entry.getKey();
|
||||
PENDING_RESPAWNS.remove(npc);
|
||||
final Spawn spawn = npc.getSpawn();
|
||||
if (spawn != null)
|
||||
{
|
||||
spawn.respawnNpc(npc);
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
spawn.respawnNpc(npc);
|
||||
spawn._scheduledCount--;
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(NpcInstance npc, long time)
|
||||
|
Reference in New Issue
Block a user