Runnable implementations for task manager classes.
This commit is contained in:
parent
e15d1719be
commit
0c4cbf4e18
@ -33,7 +33,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());
|
||||
|
||||
@ -42,57 +42,57 @@ 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() && creature.hasSummon())
|
||||
{
|
||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||
creature.getAI().setAutoAttacking(false);
|
||||
if (creature.isPlayer() && creature.hasSummon())
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.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.isOnlineInt() != 1) || (!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.isOnlineInt() != 1) || (!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().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored HP.");
|
||||
break HP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
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().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored CP.");
|
||||
break CP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
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().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored MP.");
|
||||
break MP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
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 _workingProducts = false;
|
||||
private static boolean _workingSaves = false;
|
||||
|
||||
public BuyListTaskManager()
|
||||
protected BuyListTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListProductTask(), 1000, 60000);
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListSaveTask(), 50, 50);
|
||||
}
|
||||
|
||||
protected class BuyListProductTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingProducts)
|
||||
{
|
||||
@ -64,9 +71,13 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingProducts = false;
|
||||
}, 1000, 60000);
|
||||
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
}
|
||||
}
|
||||
|
||||
protected class BuyListSaveTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingSaves)
|
||||
{
|
||||
@ -86,7 +97,7 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingSaves = false;
|
||||
}, 50, 50);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Product product, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class CreatureSeeTaskManager
|
||||
public class CreatureSeeTaskManager implements Runnable
|
||||
{
|
||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public CreatureSeeTaskManager()
|
||||
protected CreatureSeeTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(Creature creature)
|
||||
|
@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class DecayTaskManager
|
||||
public class DecayTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public DecayTaskManager()
|
||||
protected DecayTaskManager()
|
||||
{
|
||||
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<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemAppearanceTaskManager
|
||||
public class ItemAppearanceTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemAppearanceTaskManager()
|
||||
protected ItemAppearanceTaskManager()
|
||||
{
|
||||
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.onVisualLifeTimeEnd();
|
||||
}
|
||||
_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.onVisualLifeTimeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemLifeTimeTaskManager
|
||||
public class ItemLifeTimeTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemLifeTimeTaskManager()
|
||||
protected ItemLifeTimeTaskManager()
|
||||
{
|
||||
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.endOfLife();
|
||||
}
|
||||
_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.endOfLife();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -16,9 +16,8 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
@ -27,22 +26,17 @@ import org.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import org.l2jmobius.gameserver.instancemanager.ItemsOnGroundManager;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
|
||||
public class ItemsAutoDestroyTaskManager
|
||||
public class ItemsAutoDestroyTaskManager implements Runnable
|
||||
{
|
||||
private final List<ItemInstance> _items = new LinkedList<>();
|
||||
private final Set<ItemInstance> _items = ConcurrentHashMap.newKeySet();
|
||||
|
||||
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())
|
||||
{
|
||||
@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
|
||||
final long curtime = Chronos.currentTimeMillis();
|
||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
||||
while (itemIterator.hasNext())
|
||||
for (ItemInstance item : _items)
|
||||
{
|
||||
final ItemInstance item = itemIterator.next();
|
||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||
{
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||
{
|
||||
item.decayMe();
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
if (Config.SAVE_DROPPED_ITEM)
|
||||
{
|
||||
ItemsOnGroundManager.getInstance().removeObject(item);
|
||||
@ -87,6 +79,12 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(ItemInstance item)
|
||||
{
|
||||
item.setDropTime(Chronos.currentTimeMillis());
|
||||
_items.add(item);
|
||||
}
|
||||
|
||||
public static ItemsAutoDestroyTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
|
@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class MessageDeletionTaskManager
|
||||
public class MessageDeletionTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public MessageDeletionTaskManager()
|
||||
protected MessageDeletionTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 10000, 10000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 10000, 10000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(int msgId, long deletionTime)
|
||||
|
@ -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() - 20000))
|
||||
{
|
||||
player.updatePvPFlag(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.updatePvPFlag(1);
|
||||
}
|
||||
player.stopPvPFlag();
|
||||
}
|
||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||
{
|
||||
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.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RandomAnimationTaskManager
|
||||
public class RandomAnimationTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
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(Npc npc)
|
||||
|
@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
public class RespawnTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
PENDING_RESPAWNS.remove(npc);
|
||||
final Spawn spawn = npc.getSpawn();
|
||||
if (spawn != null)
|
||||
{
|
||||
final Npc 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(Npc npc, long time)
|
||||
|
@ -33,7 +33,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());
|
||||
|
||||
@ -42,57 +42,57 @@ 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() && creature.hasSummon())
|
||||
{
|
||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||
creature.getAI().setAutoAttacking(false);
|
||||
if (creature.isPlayer() && creature.hasSummon())
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.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.isOnlineInt() != 1) || (!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.isOnlineInt() != 1) || (!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().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored HP.");
|
||||
break HP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
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().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored CP.");
|
||||
break CP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
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().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored MP.");
|
||||
break MP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
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 _workingProducts = false;
|
||||
private static boolean _workingSaves = false;
|
||||
|
||||
public BuyListTaskManager()
|
||||
protected BuyListTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListProductTask(), 1000, 60000);
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListSaveTask(), 50, 50);
|
||||
}
|
||||
|
||||
protected class BuyListProductTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingProducts)
|
||||
{
|
||||
@ -64,9 +71,13 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingProducts = false;
|
||||
}, 1000, 60000);
|
||||
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
}
|
||||
}
|
||||
|
||||
protected class BuyListSaveTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingSaves)
|
||||
{
|
||||
@ -86,7 +97,7 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingSaves = false;
|
||||
}, 50, 50);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Product product, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class CreatureSeeTaskManager
|
||||
public class CreatureSeeTaskManager implements Runnable
|
||||
{
|
||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public CreatureSeeTaskManager()
|
||||
protected CreatureSeeTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(Creature creature)
|
||||
|
@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class DecayTaskManager
|
||||
public class DecayTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public DecayTaskManager()
|
||||
protected DecayTaskManager()
|
||||
{
|
||||
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<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemAppearanceTaskManager
|
||||
public class ItemAppearanceTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemAppearanceTaskManager()
|
||||
protected ItemAppearanceTaskManager()
|
||||
{
|
||||
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.onVisualLifeTimeEnd();
|
||||
}
|
||||
_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.onVisualLifeTimeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemLifeTimeTaskManager
|
||||
public class ItemLifeTimeTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemLifeTimeTaskManager()
|
||||
protected ItemLifeTimeTaskManager()
|
||||
{
|
||||
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.endOfLife();
|
||||
}
|
||||
_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.endOfLife();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -16,9 +16,8 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
@ -27,22 +26,17 @@ import org.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import org.l2jmobius.gameserver.instancemanager.ItemsOnGroundManager;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
|
||||
public class ItemsAutoDestroyTaskManager
|
||||
public class ItemsAutoDestroyTaskManager implements Runnable
|
||||
{
|
||||
private final List<ItemInstance> _items = new LinkedList<>();
|
||||
private final Set<ItemInstance> _items = ConcurrentHashMap.newKeySet();
|
||||
|
||||
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())
|
||||
{
|
||||
@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
|
||||
final long curtime = Chronos.currentTimeMillis();
|
||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
||||
while (itemIterator.hasNext())
|
||||
for (ItemInstance item : _items)
|
||||
{
|
||||
final ItemInstance item = itemIterator.next();
|
||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||
{
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||
{
|
||||
item.decayMe();
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
if (Config.SAVE_DROPPED_ITEM)
|
||||
{
|
||||
ItemsOnGroundManager.getInstance().removeObject(item);
|
||||
@ -87,6 +79,12 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(ItemInstance item)
|
||||
{
|
||||
item.setDropTime(Chronos.currentTimeMillis());
|
||||
_items.add(item);
|
||||
}
|
||||
|
||||
public static ItemsAutoDestroyTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
|
@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class MessageDeletionTaskManager
|
||||
public class MessageDeletionTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public MessageDeletionTaskManager()
|
||||
protected MessageDeletionTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 10000, 10000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 10000, 10000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(int msgId, long deletionTime)
|
||||
|
@ -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() - 20000))
|
||||
{
|
||||
player.updatePvPFlag(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.updatePvPFlag(1);
|
||||
}
|
||||
player.stopPvPFlag();
|
||||
}
|
||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||
{
|
||||
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.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RandomAnimationTaskManager
|
||||
public class RandomAnimationTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
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(Npc npc)
|
||||
|
@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
public class RespawnTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
PENDING_RESPAWNS.remove(npc);
|
||||
final Spawn spawn = npc.getSpawn();
|
||||
if (spawn != null)
|
||||
{
|
||||
final Npc 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(Npc npc, long time)
|
||||
|
@ -33,7 +33,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());
|
||||
|
||||
@ -42,57 +42,57 @@ 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() && creature.hasSummon())
|
||||
{
|
||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||
creature.getAI().setAutoAttacking(false);
|
||||
if (creature.isPlayer() && creature.hasSummon())
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.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.isOnlineInt() != 1) || (!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.isOnlineInt() != 1) || (!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().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored HP.");
|
||||
break HP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
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().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored CP.");
|
||||
break CP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
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().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored MP.");
|
||||
break MP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
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 _workingProducts = false;
|
||||
private static boolean _workingSaves = false;
|
||||
|
||||
public BuyListTaskManager()
|
||||
protected BuyListTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListProductTask(), 1000, 60000);
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListSaveTask(), 50, 50);
|
||||
}
|
||||
|
||||
protected class BuyListProductTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingProducts)
|
||||
{
|
||||
@ -64,9 +71,13 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingProducts = false;
|
||||
}, 1000, 60000);
|
||||
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
}
|
||||
}
|
||||
|
||||
protected class BuyListSaveTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingSaves)
|
||||
{
|
||||
@ -86,7 +97,7 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingSaves = false;
|
||||
}, 50, 50);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Product product, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class CreatureSeeTaskManager
|
||||
public class CreatureSeeTaskManager implements Runnable
|
||||
{
|
||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public CreatureSeeTaskManager()
|
||||
protected CreatureSeeTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(Creature creature)
|
||||
|
@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class DecayTaskManager
|
||||
public class DecayTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public DecayTaskManager()
|
||||
protected DecayTaskManager()
|
||||
{
|
||||
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<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemAppearanceTaskManager
|
||||
public class ItemAppearanceTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemAppearanceTaskManager()
|
||||
protected ItemAppearanceTaskManager()
|
||||
{
|
||||
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.onVisualLifeTimeEnd();
|
||||
}
|
||||
_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.onVisualLifeTimeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemLifeTimeTaskManager
|
||||
public class ItemLifeTimeTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemLifeTimeTaskManager()
|
||||
protected ItemLifeTimeTaskManager()
|
||||
{
|
||||
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.endOfLife();
|
||||
}
|
||||
_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.endOfLife();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -16,9 +16,8 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
@ -27,22 +26,17 @@ import org.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import org.l2jmobius.gameserver.instancemanager.ItemsOnGroundManager;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
|
||||
public class ItemsAutoDestroyTaskManager
|
||||
public class ItemsAutoDestroyTaskManager implements Runnable
|
||||
{
|
||||
private final List<ItemInstance> _items = new LinkedList<>();
|
||||
private final Set<ItemInstance> _items = ConcurrentHashMap.newKeySet();
|
||||
|
||||
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())
|
||||
{
|
||||
@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
|
||||
final long curtime = Chronos.currentTimeMillis();
|
||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
||||
while (itemIterator.hasNext())
|
||||
for (ItemInstance item : _items)
|
||||
{
|
||||
final ItemInstance item = itemIterator.next();
|
||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||
{
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||
{
|
||||
item.decayMe();
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
if (Config.SAVE_DROPPED_ITEM)
|
||||
{
|
||||
ItemsOnGroundManager.getInstance().removeObject(item);
|
||||
@ -87,6 +79,12 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(ItemInstance item)
|
||||
{
|
||||
item.setDropTime(Chronos.currentTimeMillis());
|
||||
_items.add(item);
|
||||
}
|
||||
|
||||
public static ItemsAutoDestroyTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
|
@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class MessageDeletionTaskManager
|
||||
public class MessageDeletionTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public MessageDeletionTaskManager()
|
||||
protected MessageDeletionTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 10000, 10000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 10000, 10000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(int msgId, long deletionTime)
|
||||
|
@ -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() - 20000))
|
||||
{
|
||||
player.updatePvPFlag(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.updatePvPFlag(1);
|
||||
}
|
||||
player.stopPvPFlag();
|
||||
}
|
||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||
{
|
||||
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.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RandomAnimationTaskManager
|
||||
public class RandomAnimationTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
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(Npc npc)
|
||||
|
@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
public class RespawnTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
PENDING_RESPAWNS.remove(npc);
|
||||
final Spawn spawn = npc.getSpawn();
|
||||
if (spawn != null)
|
||||
{
|
||||
final Npc 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(Npc npc, long time)
|
||||
|
@ -33,7 +33,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());
|
||||
|
||||
@ -42,57 +42,57 @@ 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() && creature.hasSummon())
|
||||
{
|
||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||
creature.getAI().setAutoAttacking(false);
|
||||
if (creature.isPlayer() && creature.hasSummon())
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.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.isOnlineInt() != 1) || (!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.isOnlineInt() != 1) || (!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().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored HP.");
|
||||
break HP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
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().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored CP.");
|
||||
break CP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
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().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored MP.");
|
||||
break MP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
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 _workingProducts = false;
|
||||
private static boolean _workingSaves = false;
|
||||
|
||||
public BuyListTaskManager()
|
||||
protected BuyListTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListProductTask(), 1000, 60000);
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListSaveTask(), 50, 50);
|
||||
}
|
||||
|
||||
protected class BuyListProductTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingProducts)
|
||||
{
|
||||
@ -64,9 +71,13 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingProducts = false;
|
||||
}, 1000, 60000);
|
||||
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
}
|
||||
}
|
||||
|
||||
protected class BuyListSaveTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingSaves)
|
||||
{
|
||||
@ -86,7 +97,7 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingSaves = false;
|
||||
}, 50, 50);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Product product, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class CreatureSeeTaskManager
|
||||
public class CreatureSeeTaskManager implements Runnable
|
||||
{
|
||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public CreatureSeeTaskManager()
|
||||
protected CreatureSeeTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(Creature creature)
|
||||
|
@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class DecayTaskManager
|
||||
public class DecayTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public DecayTaskManager()
|
||||
protected DecayTaskManager()
|
||||
{
|
||||
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<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemAppearanceTaskManager
|
||||
public class ItemAppearanceTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemAppearanceTaskManager()
|
||||
protected ItemAppearanceTaskManager()
|
||||
{
|
||||
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.onVisualLifeTimeEnd();
|
||||
}
|
||||
_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.onVisualLifeTimeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemLifeTimeTaskManager
|
||||
public class ItemLifeTimeTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemLifeTimeTaskManager()
|
||||
protected ItemLifeTimeTaskManager()
|
||||
{
|
||||
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.endOfLife();
|
||||
}
|
||||
_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.endOfLife();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -16,9 +16,8 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
@ -27,22 +26,17 @@ import org.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import org.l2jmobius.gameserver.instancemanager.ItemsOnGroundManager;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
|
||||
public class ItemsAutoDestroyTaskManager
|
||||
public class ItemsAutoDestroyTaskManager implements Runnable
|
||||
{
|
||||
private final List<ItemInstance> _items = new LinkedList<>();
|
||||
private final Set<ItemInstance> _items = ConcurrentHashMap.newKeySet();
|
||||
|
||||
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())
|
||||
{
|
||||
@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
|
||||
final long curtime = Chronos.currentTimeMillis();
|
||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
||||
while (itemIterator.hasNext())
|
||||
for (ItemInstance item : _items)
|
||||
{
|
||||
final ItemInstance item = itemIterator.next();
|
||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||
{
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||
{
|
||||
item.decayMe();
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
if (Config.SAVE_DROPPED_ITEM)
|
||||
{
|
||||
ItemsOnGroundManager.getInstance().removeObject(item);
|
||||
@ -87,6 +79,12 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(ItemInstance item)
|
||||
{
|
||||
item.setDropTime(Chronos.currentTimeMillis());
|
||||
_items.add(item);
|
||||
}
|
||||
|
||||
public static ItemsAutoDestroyTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
|
@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class MessageDeletionTaskManager
|
||||
public class MessageDeletionTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public MessageDeletionTaskManager()
|
||||
protected MessageDeletionTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 10000, 10000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 10000, 10000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(int msgId, long deletionTime)
|
||||
|
@ -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() - 20000))
|
||||
{
|
||||
player.updatePvPFlag(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.updatePvPFlag(1);
|
||||
}
|
||||
player.stopPvPFlag();
|
||||
}
|
||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||
{
|
||||
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.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RandomAnimationTaskManager
|
||||
public class RandomAnimationTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
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(Npc npc)
|
||||
|
@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
public class RespawnTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
PENDING_RESPAWNS.remove(npc);
|
||||
final Spawn spawn = npc.getSpawn();
|
||||
if (spawn != null)
|
||||
{
|
||||
final Npc 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(Npc npc, long time)
|
||||
|
@ -33,7 +33,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());
|
||||
|
||||
@ -42,57 +42,57 @@ 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() && creature.hasSummon())
|
||||
{
|
||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||
creature.getAI().setAutoAttacking(false);
|
||||
if (creature.isPlayer() && creature.hasSummon())
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.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.isOnlineInt() != 1) || (!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.isOnlineInt() != 1) || (!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().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored HP.");
|
||||
break HP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
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().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored CP.");
|
||||
break CP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
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().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored MP.");
|
||||
break MP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
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 _workingProducts = false;
|
||||
private static boolean _workingSaves = false;
|
||||
|
||||
public BuyListTaskManager()
|
||||
protected BuyListTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListProductTask(), 1000, 60000);
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListSaveTask(), 50, 50);
|
||||
}
|
||||
|
||||
protected class BuyListProductTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingProducts)
|
||||
{
|
||||
@ -64,9 +71,13 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingProducts = false;
|
||||
}, 1000, 60000);
|
||||
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
}
|
||||
}
|
||||
|
||||
protected class BuyListSaveTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingSaves)
|
||||
{
|
||||
@ -86,7 +97,7 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingSaves = false;
|
||||
}, 50, 50);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Product product, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class CreatureSeeTaskManager
|
||||
public class CreatureSeeTaskManager implements Runnable
|
||||
{
|
||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public CreatureSeeTaskManager()
|
||||
protected CreatureSeeTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(Creature creature)
|
||||
|
@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class DecayTaskManager
|
||||
public class DecayTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public DecayTaskManager()
|
||||
protected DecayTaskManager()
|
||||
{
|
||||
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<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemAppearanceTaskManager
|
||||
public class ItemAppearanceTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemAppearanceTaskManager()
|
||||
protected ItemAppearanceTaskManager()
|
||||
{
|
||||
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.onVisualLifeTimeEnd();
|
||||
}
|
||||
_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.onVisualLifeTimeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemLifeTimeTaskManager
|
||||
public class ItemLifeTimeTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemLifeTimeTaskManager()
|
||||
protected ItemLifeTimeTaskManager()
|
||||
{
|
||||
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.endOfLife();
|
||||
}
|
||||
_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.endOfLife();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -16,9 +16,8 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
@ -27,22 +26,17 @@ import org.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import org.l2jmobius.gameserver.instancemanager.ItemsOnGroundManager;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
|
||||
public class ItemsAutoDestroyTaskManager
|
||||
public class ItemsAutoDestroyTaskManager implements Runnable
|
||||
{
|
||||
private final List<ItemInstance> _items = new LinkedList<>();
|
||||
private final Set<ItemInstance> _items = ConcurrentHashMap.newKeySet();
|
||||
|
||||
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())
|
||||
{
|
||||
@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
|
||||
final long curtime = Chronos.currentTimeMillis();
|
||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
||||
while (itemIterator.hasNext())
|
||||
for (ItemInstance item : _items)
|
||||
{
|
||||
final ItemInstance item = itemIterator.next();
|
||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||
{
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||
{
|
||||
item.decayMe();
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
if (Config.SAVE_DROPPED_ITEM)
|
||||
{
|
||||
ItemsOnGroundManager.getInstance().removeObject(item);
|
||||
@ -87,6 +79,12 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(ItemInstance item)
|
||||
{
|
||||
item.setDropTime(Chronos.currentTimeMillis());
|
||||
_items.add(item);
|
||||
}
|
||||
|
||||
public static ItemsAutoDestroyTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
|
@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class MessageDeletionTaskManager
|
||||
public class MessageDeletionTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public MessageDeletionTaskManager()
|
||||
protected MessageDeletionTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 10000, 10000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 10000, 10000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(int msgId, long deletionTime)
|
||||
|
@ -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() - 20000))
|
||||
{
|
||||
player.updatePvPFlag(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.updatePvPFlag(1);
|
||||
}
|
||||
player.stopPvPFlag();
|
||||
}
|
||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||
{
|
||||
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.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RandomAnimationTaskManager
|
||||
public class RandomAnimationTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
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(Npc npc)
|
||||
|
@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
public class RespawnTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
PENDING_RESPAWNS.remove(npc);
|
||||
final Spawn spawn = npc.getSpawn();
|
||||
if (spawn != null)
|
||||
{
|
||||
final Npc 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(Npc npc, long time)
|
||||
|
@ -33,7 +33,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());
|
||||
|
||||
@ -42,57 +42,57 @@ 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() && creature.hasSummon())
|
||||
{
|
||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||
creature.getAI().setAutoAttacking(false);
|
||||
if (creature.isPlayer() && creature.hasSummon())
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.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.isOnlineInt() != 1) || (!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.isOnlineInt() != 1) || (!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().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored HP.");
|
||||
break HP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
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().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored CP.");
|
||||
break CP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
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().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored MP.");
|
||||
break MP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
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 _workingProducts = false;
|
||||
private static boolean _workingSaves = false;
|
||||
|
||||
public BuyListTaskManager()
|
||||
protected BuyListTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListProductTask(), 1000, 60000);
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListSaveTask(), 50, 50);
|
||||
}
|
||||
|
||||
protected class BuyListProductTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingProducts)
|
||||
{
|
||||
@ -64,9 +71,13 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingProducts = false;
|
||||
}, 1000, 60000);
|
||||
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
}
|
||||
}
|
||||
|
||||
protected class BuyListSaveTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingSaves)
|
||||
{
|
||||
@ -86,7 +97,7 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingSaves = false;
|
||||
}, 50, 50);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Product product, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class CreatureSeeTaskManager
|
||||
public class CreatureSeeTaskManager implements Runnable
|
||||
{
|
||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public CreatureSeeTaskManager()
|
||||
protected CreatureSeeTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
for (Creature creature : CREATURES)
|
||||
{
|
||||
creature.updateSeenCreatures();
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(Creature creature)
|
||||
|
@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class DecayTaskManager
|
||||
public class DecayTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public DecayTaskManager()
|
||||
protected DecayTaskManager()
|
||||
{
|
||||
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<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
final Creature creature = entry.getKey();
|
||||
DECAY_SCHEDULES.remove(creature);
|
||||
creature.onDecay();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemAppearanceTaskManager
|
||||
public class ItemAppearanceTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemAppearanceTaskManager()
|
||||
protected ItemAppearanceTaskManager()
|
||||
{
|
||||
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.onVisualLifeTimeEnd();
|
||||
}
|
||||
_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.onVisualLifeTimeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ItemLifeTimeTaskManager
|
||||
public class ItemLifeTimeTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public ItemLifeTimeTaskManager()
|
||||
protected ItemLifeTimeTaskManager()
|
||||
{
|
||||
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.endOfLife();
|
||||
}
|
||||
_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.endOfLife();
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(ItemInstance item, long endTime)
|
||||
|
@ -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)
|
||||
|
@ -16,9 +16,8 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
@ -27,22 +26,17 @@ import org.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import org.l2jmobius.gameserver.instancemanager.ItemsOnGroundManager;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
|
||||
public class ItemsAutoDestroyTaskManager
|
||||
public class ItemsAutoDestroyTaskManager implements Runnable
|
||||
{
|
||||
private final List<ItemInstance> _items = new LinkedList<>();
|
||||
private final Set<ItemInstance> _items = ConcurrentHashMap.newKeySet();
|
||||
|
||||
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())
|
||||
{
|
||||
@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
|
||||
final long curtime = Chronos.currentTimeMillis();
|
||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
||||
while (itemIterator.hasNext())
|
||||
for (ItemInstance item : _items)
|
||||
{
|
||||
final ItemInstance item = itemIterator.next();
|
||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||
{
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||
{
|
||||
item.decayMe();
|
||||
itemIterator.remove();
|
||||
_items.remove(item);
|
||||
if (Config.SAVE_DROPPED_ITEM)
|
||||
{
|
||||
ItemsOnGroundManager.getInstance().removeObject(item);
|
||||
@ -87,6 +79,12 @@ public class ItemsAutoDestroyTaskManager
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(ItemInstance item)
|
||||
{
|
||||
item.setDropTime(Chronos.currentTimeMillis());
|
||||
_items.add(item);
|
||||
}
|
||||
|
||||
public static ItemsAutoDestroyTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
|
@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class MessageDeletionTaskManager
|
||||
public class MessageDeletionTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||
private static boolean _working = false;
|
||||
|
||||
public MessageDeletionTaskManager()
|
||||
protected MessageDeletionTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(this, 10000, 10000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
if (_working)
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
Integer msgId;
|
||||
Message msg;
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
msgId = entry.getKey();
|
||||
msg = MailManager.getInstance().getMessage(msgId.intValue());
|
||||
if (msg == null)
|
||||
{
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.hasAttachments())
|
||||
{
|
||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||
if (sender != null)
|
||||
{
|
||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.getAttachments().returnToWh(null);
|
||||
}
|
||||
msg.getAttachments().deleteMe();
|
||||
msg.removeAttachments();
|
||||
|
||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
MailManager.getInstance().deleteMessageInDb(msgId.intValue());
|
||||
PENDING_MESSAGES.remove(msgId);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 10000, 10000);
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}
|
||||
|
||||
public void add(int msgId, long deletionTime)
|
||||
|
@ -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() - 20000))
|
||||
{
|
||||
player.updatePvPFlag(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.updatePvPFlag(1);
|
||||
}
|
||||
player.stopPvPFlag();
|
||||
}
|
||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||
{
|
||||
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.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RandomAnimationTaskManager
|
||||
public class RandomAnimationTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
final Npc npc = entry.getKey();
|
||||
if (npc.isInActiveRegion() && !npc.isDead() && !npc.isInCombat() && !npc.isMoving() && !npc.hasBlockActions())
|
||||
{
|
||||
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(Npc npc)
|
||||
|
@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class RespawnTaskManager
|
||||
public class RespawnTaskManager implements Runnable
|
||||
{
|
||||
private static final Map<Npc, 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<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
final long time = Chronos.currentTimeMillis();
|
||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||
{
|
||||
if (time > entry.getValue().longValue())
|
||||
final Npc npc = entry.getKey();
|
||||
PENDING_RESPAWNS.remove(npc);
|
||||
final Spawn spawn = npc.getSpawn();
|
||||
if (spawn != null)
|
||||
{
|
||||
final Npc 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(Npc npc, long time)
|
||||
|
@ -33,7 +33,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());
|
||||
|
||||
@ -42,57 +42,57 @@ 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() && creature.hasSummon())
|
||||
{
|
||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||
creature.getAI().setAutoAttacking(false);
|
||||
if (creature.isPlayer() && creature.hasSummon())
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
final Summon pet = creature.getPet();
|
||||
if (pet != null)
|
||||
{
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||
}
|
||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.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.isOnlineInt() != 1) || (!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.isOnlineInt() != 1) || (!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().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored HP.");
|
||||
break HP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||
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().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored CP.");
|
||||
break CP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||
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().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
player.sendMessage("Auto potion: Restored MP.");
|
||||
break MP;
|
||||
}
|
||||
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||
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 _workingProducts = false;
|
||||
private static boolean _workingSaves = false;
|
||||
|
||||
public BuyListTaskManager()
|
||||
protected BuyListTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListProductTask(), 1000, 60000);
|
||||
ThreadPool.scheduleAtFixedRate(new BuyListSaveTask(), 50, 50);
|
||||
}
|
||||
|
||||
protected class BuyListProductTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingProducts)
|
||||
{
|
||||
@ -64,9 +71,13 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingProducts = false;
|
||||
}, 1000, 60000);
|
||||
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
}
|
||||
}
|
||||
|
||||
protected class BuyListSaveTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_workingSaves)
|
||||
{
|
||||
@ -86,7 +97,7 @@ public class BuyListTaskManager
|
||||
}
|
||||
|
||||
_workingSaves = false;
|
||||
}, 50, 50);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Product product, long endTime)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user