Runnable implementations for task manager classes.
This commit is contained in:
@@ -33,7 +33,7 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
|||||||
* Attack stance task manager.
|
* Attack stance task manager.
|
||||||
* @author Luca Baldi
|
* @author Luca Baldi
|
||||||
*/
|
*/
|
||||||
public class AttackStanceTaskManager
|
public class AttackStanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
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 final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new attack stance task manager.
|
|
||||||
*/
|
|
||||||
protected AttackStanceTaskManager()
|
protected AttackStanceTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long current = Chronos.currentTimeMillis();
|
@Override
|
||||||
try
|
public void run()
|
||||||
|
{
|
||||||
|
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())
|
||||||
{
|
{
|
||||||
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
|
entry = iterator.next();
|
||||||
Entry<Creature, Long> entry;
|
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
||||||
Creature creature;
|
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
entry = iterator.next();
|
creature = entry.getKey();
|
||||||
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
if (creature != null)
|
||||||
{
|
{
|
||||||
creature = entry.getKey();
|
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||||
if (creature != null)
|
creature.getAI().setAutoAttacking(false);
|
||||||
|
if (creature.isPlayer() && creature.hasSummon())
|
||||||
{
|
{
|
||||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
final Summon pet = creature.getPet();
|
||||||
creature.getAI().setAutoAttacking(false);
|
if (pet != null)
|
||||||
if (creature.isPlayer() && creature.hasSummon())
|
|
||||||
{
|
{
|
||||||
final Summon pet = creature.getPet();
|
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||||
if (pet != null)
|
|
||||||
{
|
|
||||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
|
||||||
}
|
|
||||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
|
||||||
}
|
}
|
||||||
|
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||||
}
|
}
|
||||||
iterator.remove();
|
|
||||||
}
|
}
|
||||||
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
// Unless caught here, players remain in attack positions.
|
{
|
||||||
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
// Unless caught here, players remain in attack positions.
|
||||||
}
|
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,44 +26,47 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager
|
public class AttackableThinkTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
@Override
|
||||||
for (Attackable attackable : ATTACKABLES)
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : ATTACKABLES)
|
||||||
|
{
|
||||||
|
if (attackable.hasAI())
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
ai.onEvtThink();
|
||||||
if (ai != null)
|
|
||||||
{
|
|
||||||
ai.onEvtThink();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
remove(attackable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
remove(attackable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
public void add(Attackable attackable)
|
||||||
|
@@ -28,93 +28,96 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius, Gigi
|
* @author Mobius, Gigi
|
||||||
*/
|
*/
|
||||||
public class AutoPotionTaskManager
|
public class AutoPotionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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);
|
final ItemInstance hpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
continue PLAYER;
|
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
success = true;
|
||||||
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
if (restoreHP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||||
if (restoreHP)
|
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;
|
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
CP: for (int itemId : Config.AUTO_CP_ITEM_IDS)
|
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
if (restoreCP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||||
if (restoreCP)
|
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;
|
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
MP: for (int itemId : Config.AUTO_MP_ITEM_IDS)
|
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
if (restoreMP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||||
if (restoreMP)
|
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;
|
if (!success)
|
||||||
}, 0, 1000);
|
{
|
||||||
|
player.sendMessage("Auto potion: You are out of potions!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -36,9 +36,16 @@ public class BuyListTaskManager
|
|||||||
private static boolean _workingProducts = false;
|
private static boolean _workingProducts = false;
|
||||||
private static boolean _workingSaves = 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)
|
if (_workingProducts)
|
||||||
{
|
{
|
||||||
@@ -64,9 +71,13 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingProducts = false;
|
_workingProducts = false;
|
||||||
}, 1000, 60000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class BuyListSaveTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingSaves)
|
if (_workingSaves)
|
||||||
{
|
{
|
||||||
@@ -86,7 +97,7 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingSaves = false;
|
_workingSaves = false;
|
||||||
}, 50, 50);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Product product, long endTime)
|
public void add(Product product, long endTime)
|
||||||
|
@@ -40,9 +40,16 @@ public class CreatureFollowTaskManager
|
|||||||
private static boolean _workingNormal = false;
|
private static boolean _workingNormal = false;
|
||||||
private static boolean _workingAttack = 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)
|
if (_workingNormal)
|
||||||
{
|
{
|
||||||
@@ -56,9 +63,13 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingNormal = false;
|
_workingNormal = false;
|
||||||
}, 1000, 1000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class CreatureFollowAttackTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingAttack)
|
if (_workingAttack)
|
||||||
{
|
{
|
||||||
@@ -72,7 +83,7 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingAttack = false;
|
_workingAttack = false;
|
||||||
}, 500, 500);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void follow(Creature creature, int range)
|
private void follow(Creature creature, int range)
|
||||||
|
@@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class CreatureSeeTaskManager
|
public class CreatureSeeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
for (Creature creature : CREATURES)
|
for (Creature creature : CREATURES)
|
||||||
{
|
{
|
||||||
creature.updateSeenCreatures();
|
creature.updateSeenCreatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Creature creature)
|
public void add(Creature creature)
|
||||||
|
@@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class DecayTaskManager
|
public class DecayTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final Creature creature = entry.getKey();
|
||||||
{
|
DECAY_SCHEDULES.remove(creature);
|
||||||
final Creature creature = entry.getKey();
|
creature.onDecay();
|
||||||
DECAY_SCHEDULES.remove(creature);
|
|
||||||
creature.onDecay();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemAppearanceTaskManager
|
public class ItemAppearanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.onVisualLifeTimeEnd();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.onVisualLifeTimeEnd();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemLifeTimeTaskManager
|
public class ItemLifeTimeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.endOfLife();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.endOfLife();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,35 +27,38 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemManaTaskManager
|
public class ItemManaTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static final int MANA_CONSUMPTION_RATE = 60000;
|
private static final int MANA_CONSUMPTION_RATE = 60000;
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.decreaseMana(true);
|
||||||
ITEMS.remove(item);
|
|
||||||
item.decreaseMana(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item)
|
public void add(ItemInstance item)
|
||||||
|
@@ -16,9 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.l2jmobius.gameserver.taskmanager;
|
package org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Set;
|
||||||
import java.util.LinkedList;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
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.instancemanager.ItemsOnGroundManager;
|
||||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
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()
|
protected ItemsAutoDestroyTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this::removeItems, 5000, 5000);
|
ThreadPool.scheduleAtFixedRate(this, 5000, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addItem(ItemInstance item)
|
@Override
|
||||||
{
|
public void run()
|
||||||
item.setDropTime(Chronos.currentTimeMillis());
|
|
||||||
_items.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void removeItems()
|
|
||||||
{
|
{
|
||||||
if (_items.isEmpty())
|
if (_items.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
final long curtime = Chronos.currentTimeMillis();
|
final long curtime = Chronos.currentTimeMillis();
|
||||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
for (ItemInstance item : _items)
|
||||||
while (itemIterator.hasNext())
|
|
||||||
{
|
{
|
||||||
final ItemInstance item = itemIterator.next();
|
|
||||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||||
{
|
{
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||||
{
|
{
|
||||||
item.decayMe();
|
item.decayMe();
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
if (Config.SAVE_DROPPED_ITEM)
|
if (Config.SAVE_DROPPED_ITEM)
|
||||||
{
|
{
|
||||||
ItemsOnGroundManager.getInstance().removeObject(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()
|
public static ItemsAutoDestroyTaskManager getInstance()
|
||||||
{
|
{
|
||||||
return SingletonHolder.INSTANCE;
|
return SingletonHolder.INSTANCE;
|
||||||
|
@@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MessageDeletionTaskManager
|
public class MessageDeletionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
Integer msgId;
|
Integer msgId;
|
||||||
Message msg;
|
Message msg;
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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);
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_working = false;
|
if (msg.hasAttachments())
|
||||||
}, 10000, 10000);
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(int msgId, long deletionTime)
|
public void add(int msgId, long deletionTime)
|
||||||
|
@@ -28,38 +28,41 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PlayerAutoSaveTaskManager
|
public class PlayerAutoSaveTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PlayerAutoSaveTaskManager()
|
protected PlayerAutoSaveTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final PlayerInstance player = entry.getKey();
|
||||||
|
if ((player != null) && player.isOnline())
|
||||||
{
|
{
|
||||||
final PlayerInstance player = entry.getKey();
|
player.autoSave();
|
||||||
if ((player != null) && player.isOnline())
|
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;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -26,43 +26,46 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PvpFlagTaskManager
|
public class PvpFlagTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PvpFlagTaskManager()
|
protected PvpFlagTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
if (!PLAYERS.isEmpty())
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
if (!PLAYERS.isEmpty())
|
||||||
|
{
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (PlayerInstance player : PLAYERS)
|
||||||
{
|
{
|
||||||
final long time = Chronos.currentTimeMillis();
|
if (time > player.getPvpFlagLasts())
|
||||||
for (PlayerInstance player : PLAYERS)
|
|
||||||
{
|
{
|
||||||
if (time > player.getPvpFlagLasts())
|
player.stopPvPFlag();
|
||||||
{
|
}
|
||||||
player.stopPvPFlag();
|
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||||
}
|
{
|
||||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
player.updatePvPFlag(2);
|
||||||
{
|
}
|
||||||
player.updatePvPFlag(2);
|
else
|
||||||
}
|
{
|
||||||
else
|
player.updatePvPFlag(1);
|
||||||
{
|
|
||||||
player.updatePvPFlag(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -29,37 +29,40 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RandomAnimationTaskManager
|
public class RandomAnimationTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
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;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc)
|
public void add(Npc npc)
|
||||||
|
@@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RespawnTaskManager
|
public class RespawnTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public RespawnTaskManager()
|
protected RespawnTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
spawn.respawnNpc(npc);
|
||||||
PENDING_RESPAWNS.remove(npc);
|
spawn._scheduledCount--;
|
||||||
final Spawn spawn = npc.getSpawn();
|
|
||||||
if (spawn != null)
|
|
||||||
{
|
|
||||||
spawn.respawnNpc(npc);
|
|
||||||
spawn._scheduledCount--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc, long time)
|
public void add(Npc npc, long time)
|
||||||
|
@@ -33,7 +33,7 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
|||||||
* Attack stance task manager.
|
* Attack stance task manager.
|
||||||
* @author Luca Baldi
|
* @author Luca Baldi
|
||||||
*/
|
*/
|
||||||
public class AttackStanceTaskManager
|
public class AttackStanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
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 final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new attack stance task manager.
|
|
||||||
*/
|
|
||||||
protected AttackStanceTaskManager()
|
protected AttackStanceTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long current = Chronos.currentTimeMillis();
|
@Override
|
||||||
try
|
public void run()
|
||||||
|
{
|
||||||
|
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())
|
||||||
{
|
{
|
||||||
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
|
entry = iterator.next();
|
||||||
Entry<Creature, Long> entry;
|
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
||||||
Creature creature;
|
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
entry = iterator.next();
|
creature = entry.getKey();
|
||||||
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
if (creature != null)
|
||||||
{
|
{
|
||||||
creature = entry.getKey();
|
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||||
if (creature != null)
|
creature.getAI().setAutoAttacking(false);
|
||||||
|
if (creature.isPlayer() && creature.hasSummon())
|
||||||
{
|
{
|
||||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
final Summon pet = creature.getPet();
|
||||||
creature.getAI().setAutoAttacking(false);
|
if (pet != null)
|
||||||
if (creature.isPlayer() && creature.hasSummon())
|
|
||||||
{
|
{
|
||||||
final Summon pet = creature.getPet();
|
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||||
if (pet != null)
|
|
||||||
{
|
|
||||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
|
||||||
}
|
|
||||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
|
||||||
}
|
}
|
||||||
|
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||||
}
|
}
|
||||||
iterator.remove();
|
|
||||||
}
|
}
|
||||||
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
// Unless caught here, players remain in attack positions.
|
{
|
||||||
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
// Unless caught here, players remain in attack positions.
|
||||||
}
|
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,44 +26,47 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager
|
public class AttackableThinkTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
@Override
|
||||||
for (Attackable attackable : ATTACKABLES)
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : ATTACKABLES)
|
||||||
|
{
|
||||||
|
if (attackable.hasAI())
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
ai.onEvtThink();
|
||||||
if (ai != null)
|
|
||||||
{
|
|
||||||
ai.onEvtThink();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
remove(attackable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
remove(attackable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
public void add(Attackable attackable)
|
||||||
|
@@ -28,93 +28,96 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius, Gigi
|
* @author Mobius, Gigi
|
||||||
*/
|
*/
|
||||||
public class AutoPotionTaskManager
|
public class AutoPotionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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);
|
final ItemInstance hpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
continue PLAYER;
|
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
success = true;
|
||||||
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
if (restoreHP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||||
if (restoreHP)
|
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;
|
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
CP: for (int itemId : Config.AUTO_CP_ITEM_IDS)
|
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
if (restoreCP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||||
if (restoreCP)
|
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;
|
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
MP: for (int itemId : Config.AUTO_MP_ITEM_IDS)
|
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
if (restoreMP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||||
if (restoreMP)
|
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;
|
if (!success)
|
||||||
}, 0, 1000);
|
{
|
||||||
|
player.sendMessage("Auto potion: You are out of potions!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -36,9 +36,16 @@ public class BuyListTaskManager
|
|||||||
private static boolean _workingProducts = false;
|
private static boolean _workingProducts = false;
|
||||||
private static boolean _workingSaves = 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)
|
if (_workingProducts)
|
||||||
{
|
{
|
||||||
@@ -64,9 +71,13 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingProducts = false;
|
_workingProducts = false;
|
||||||
}, 1000, 60000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class BuyListSaveTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingSaves)
|
if (_workingSaves)
|
||||||
{
|
{
|
||||||
@@ -86,7 +97,7 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingSaves = false;
|
_workingSaves = false;
|
||||||
}, 50, 50);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Product product, long endTime)
|
public void add(Product product, long endTime)
|
||||||
|
@@ -40,9 +40,16 @@ public class CreatureFollowTaskManager
|
|||||||
private static boolean _workingNormal = false;
|
private static boolean _workingNormal = false;
|
||||||
private static boolean _workingAttack = 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)
|
if (_workingNormal)
|
||||||
{
|
{
|
||||||
@@ -56,9 +63,13 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingNormal = false;
|
_workingNormal = false;
|
||||||
}, 1000, 1000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class CreatureFollowAttackTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingAttack)
|
if (_workingAttack)
|
||||||
{
|
{
|
||||||
@@ -72,7 +83,7 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingAttack = false;
|
_workingAttack = false;
|
||||||
}, 500, 500);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void follow(Creature creature, int range)
|
private void follow(Creature creature, int range)
|
||||||
|
@@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class CreatureSeeTaskManager
|
public class CreatureSeeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
for (Creature creature : CREATURES)
|
for (Creature creature : CREATURES)
|
||||||
{
|
{
|
||||||
creature.updateSeenCreatures();
|
creature.updateSeenCreatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Creature creature)
|
public void add(Creature creature)
|
||||||
|
@@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class DecayTaskManager
|
public class DecayTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final Creature creature = entry.getKey();
|
||||||
{
|
DECAY_SCHEDULES.remove(creature);
|
||||||
final Creature creature = entry.getKey();
|
creature.onDecay();
|
||||||
DECAY_SCHEDULES.remove(creature);
|
|
||||||
creature.onDecay();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemAppearanceTaskManager
|
public class ItemAppearanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.onVisualLifeTimeEnd();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.onVisualLifeTimeEnd();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemLifeTimeTaskManager
|
public class ItemLifeTimeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.endOfLife();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.endOfLife();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,35 +27,38 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemManaTaskManager
|
public class ItemManaTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static final int MANA_CONSUMPTION_RATE = 60000;
|
private static final int MANA_CONSUMPTION_RATE = 60000;
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.decreaseMana(true);
|
||||||
ITEMS.remove(item);
|
|
||||||
item.decreaseMana(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item)
|
public void add(ItemInstance item)
|
||||||
|
@@ -16,9 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.l2jmobius.gameserver.taskmanager;
|
package org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Set;
|
||||||
import java.util.LinkedList;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
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.instancemanager.ItemsOnGroundManager;
|
||||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
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()
|
protected ItemsAutoDestroyTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this::removeItems, 5000, 5000);
|
ThreadPool.scheduleAtFixedRate(this, 5000, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addItem(ItemInstance item)
|
@Override
|
||||||
{
|
public void run()
|
||||||
item.setDropTime(Chronos.currentTimeMillis());
|
|
||||||
_items.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void removeItems()
|
|
||||||
{
|
{
|
||||||
if (_items.isEmpty())
|
if (_items.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
final long curtime = Chronos.currentTimeMillis();
|
final long curtime = Chronos.currentTimeMillis();
|
||||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
for (ItemInstance item : _items)
|
||||||
while (itemIterator.hasNext())
|
|
||||||
{
|
{
|
||||||
final ItemInstance item = itemIterator.next();
|
|
||||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||||
{
|
{
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||||
{
|
{
|
||||||
item.decayMe();
|
item.decayMe();
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
if (Config.SAVE_DROPPED_ITEM)
|
if (Config.SAVE_DROPPED_ITEM)
|
||||||
{
|
{
|
||||||
ItemsOnGroundManager.getInstance().removeObject(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()
|
public static ItemsAutoDestroyTaskManager getInstance()
|
||||||
{
|
{
|
||||||
return SingletonHolder.INSTANCE;
|
return SingletonHolder.INSTANCE;
|
||||||
|
@@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MessageDeletionTaskManager
|
public class MessageDeletionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
Integer msgId;
|
Integer msgId;
|
||||||
Message msg;
|
Message msg;
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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);
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_working = false;
|
if (msg.hasAttachments())
|
||||||
}, 10000, 10000);
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(int msgId, long deletionTime)
|
public void add(int msgId, long deletionTime)
|
||||||
|
@@ -28,38 +28,41 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PlayerAutoSaveTaskManager
|
public class PlayerAutoSaveTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PlayerAutoSaveTaskManager()
|
protected PlayerAutoSaveTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final PlayerInstance player = entry.getKey();
|
||||||
|
if ((player != null) && player.isOnline())
|
||||||
{
|
{
|
||||||
final PlayerInstance player = entry.getKey();
|
player.autoSave();
|
||||||
if ((player != null) && player.isOnline())
|
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;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -26,43 +26,46 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PvpFlagTaskManager
|
public class PvpFlagTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PvpFlagTaskManager()
|
protected PvpFlagTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
if (!PLAYERS.isEmpty())
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
if (!PLAYERS.isEmpty())
|
||||||
|
{
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (PlayerInstance player : PLAYERS)
|
||||||
{
|
{
|
||||||
final long time = Chronos.currentTimeMillis();
|
if (time > player.getPvpFlagLasts())
|
||||||
for (PlayerInstance player : PLAYERS)
|
|
||||||
{
|
{
|
||||||
if (time > player.getPvpFlagLasts())
|
player.stopPvPFlag();
|
||||||
{
|
}
|
||||||
player.stopPvPFlag();
|
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||||
}
|
{
|
||||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
player.updatePvPFlag(2);
|
||||||
{
|
}
|
||||||
player.updatePvPFlag(2);
|
else
|
||||||
}
|
{
|
||||||
else
|
player.updatePvPFlag(1);
|
||||||
{
|
|
||||||
player.updatePvPFlag(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -29,37 +29,40 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RandomAnimationTaskManager
|
public class RandomAnimationTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
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;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc)
|
public void add(Npc npc)
|
||||||
|
@@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RespawnTaskManager
|
public class RespawnTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public RespawnTaskManager()
|
protected RespawnTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
spawn.respawnNpc(npc);
|
||||||
PENDING_RESPAWNS.remove(npc);
|
spawn._scheduledCount--;
|
||||||
final Spawn spawn = npc.getSpawn();
|
|
||||||
if (spawn != null)
|
|
||||||
{
|
|
||||||
spawn.respawnNpc(npc);
|
|
||||||
spawn._scheduledCount--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc, long time)
|
public void add(Npc npc, long time)
|
||||||
|
@@ -33,7 +33,7 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
|||||||
* Attack stance task manager.
|
* Attack stance task manager.
|
||||||
* @author Luca Baldi
|
* @author Luca Baldi
|
||||||
*/
|
*/
|
||||||
public class AttackStanceTaskManager
|
public class AttackStanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
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 final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new attack stance task manager.
|
|
||||||
*/
|
|
||||||
protected AttackStanceTaskManager()
|
protected AttackStanceTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long current = Chronos.currentTimeMillis();
|
@Override
|
||||||
try
|
public void run()
|
||||||
|
{
|
||||||
|
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())
|
||||||
{
|
{
|
||||||
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
|
entry = iterator.next();
|
||||||
Entry<Creature, Long> entry;
|
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
||||||
Creature creature;
|
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
entry = iterator.next();
|
creature = entry.getKey();
|
||||||
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
if (creature != null)
|
||||||
{
|
{
|
||||||
creature = entry.getKey();
|
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||||
if (creature != null)
|
creature.getAI().setAutoAttacking(false);
|
||||||
|
if (creature.isPlayer() && creature.hasSummon())
|
||||||
{
|
{
|
||||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
final Summon pet = creature.getPet();
|
||||||
creature.getAI().setAutoAttacking(false);
|
if (pet != null)
|
||||||
if (creature.isPlayer() && creature.hasSummon())
|
|
||||||
{
|
{
|
||||||
final Summon pet = creature.getPet();
|
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||||
if (pet != null)
|
|
||||||
{
|
|
||||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
|
||||||
}
|
|
||||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
|
||||||
}
|
}
|
||||||
|
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||||
}
|
}
|
||||||
iterator.remove();
|
|
||||||
}
|
}
|
||||||
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
// Unless caught here, players remain in attack positions.
|
{
|
||||||
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
// Unless caught here, players remain in attack positions.
|
||||||
}
|
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,44 +26,47 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager
|
public class AttackableThinkTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
@Override
|
||||||
for (Attackable attackable : ATTACKABLES)
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : ATTACKABLES)
|
||||||
|
{
|
||||||
|
if (attackable.hasAI())
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
ai.onEvtThink();
|
||||||
if (ai != null)
|
|
||||||
{
|
|
||||||
ai.onEvtThink();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
remove(attackable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
remove(attackable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
public void add(Attackable attackable)
|
||||||
|
@@ -28,93 +28,96 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius, Gigi
|
* @author Mobius, Gigi
|
||||||
*/
|
*/
|
||||||
public class AutoPotionTaskManager
|
public class AutoPotionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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);
|
final ItemInstance hpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
continue PLAYER;
|
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
success = true;
|
||||||
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
if (restoreHP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||||
if (restoreHP)
|
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;
|
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
CP: for (int itemId : Config.AUTO_CP_ITEM_IDS)
|
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
if (restoreCP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||||
if (restoreCP)
|
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;
|
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
MP: for (int itemId : Config.AUTO_MP_ITEM_IDS)
|
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
if (restoreMP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||||
if (restoreMP)
|
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;
|
if (!success)
|
||||||
}, 0, 1000);
|
{
|
||||||
|
player.sendMessage("Auto potion: You are out of potions!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -36,9 +36,16 @@ public class BuyListTaskManager
|
|||||||
private static boolean _workingProducts = false;
|
private static boolean _workingProducts = false;
|
||||||
private static boolean _workingSaves = 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)
|
if (_workingProducts)
|
||||||
{
|
{
|
||||||
@@ -64,9 +71,13 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingProducts = false;
|
_workingProducts = false;
|
||||||
}, 1000, 60000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class BuyListSaveTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingSaves)
|
if (_workingSaves)
|
||||||
{
|
{
|
||||||
@@ -86,7 +97,7 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingSaves = false;
|
_workingSaves = false;
|
||||||
}, 50, 50);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Product product, long endTime)
|
public void add(Product product, long endTime)
|
||||||
|
@@ -40,9 +40,16 @@ public class CreatureFollowTaskManager
|
|||||||
private static boolean _workingNormal = false;
|
private static boolean _workingNormal = false;
|
||||||
private static boolean _workingAttack = 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)
|
if (_workingNormal)
|
||||||
{
|
{
|
||||||
@@ -56,9 +63,13 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingNormal = false;
|
_workingNormal = false;
|
||||||
}, 1000, 1000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class CreatureFollowAttackTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingAttack)
|
if (_workingAttack)
|
||||||
{
|
{
|
||||||
@@ -72,7 +83,7 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingAttack = false;
|
_workingAttack = false;
|
||||||
}, 500, 500);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void follow(Creature creature, int range)
|
private void follow(Creature creature, int range)
|
||||||
|
@@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class CreatureSeeTaskManager
|
public class CreatureSeeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
for (Creature creature : CREATURES)
|
for (Creature creature : CREATURES)
|
||||||
{
|
{
|
||||||
creature.updateSeenCreatures();
|
creature.updateSeenCreatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Creature creature)
|
public void add(Creature creature)
|
||||||
|
@@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class DecayTaskManager
|
public class DecayTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final Creature creature = entry.getKey();
|
||||||
{
|
DECAY_SCHEDULES.remove(creature);
|
||||||
final Creature creature = entry.getKey();
|
creature.onDecay();
|
||||||
DECAY_SCHEDULES.remove(creature);
|
|
||||||
creature.onDecay();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemAppearanceTaskManager
|
public class ItemAppearanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.onVisualLifeTimeEnd();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.onVisualLifeTimeEnd();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemLifeTimeTaskManager
|
public class ItemLifeTimeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.endOfLife();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.endOfLife();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,35 +27,38 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemManaTaskManager
|
public class ItemManaTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static final int MANA_CONSUMPTION_RATE = 60000;
|
private static final int MANA_CONSUMPTION_RATE = 60000;
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.decreaseMana(true);
|
||||||
ITEMS.remove(item);
|
|
||||||
item.decreaseMana(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item)
|
public void add(ItemInstance item)
|
||||||
|
@@ -16,9 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.l2jmobius.gameserver.taskmanager;
|
package org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Set;
|
||||||
import java.util.LinkedList;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
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.instancemanager.ItemsOnGroundManager;
|
||||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
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()
|
protected ItemsAutoDestroyTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this::removeItems, 5000, 5000);
|
ThreadPool.scheduleAtFixedRate(this, 5000, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addItem(ItemInstance item)
|
@Override
|
||||||
{
|
public void run()
|
||||||
item.setDropTime(Chronos.currentTimeMillis());
|
|
||||||
_items.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void removeItems()
|
|
||||||
{
|
{
|
||||||
if (_items.isEmpty())
|
if (_items.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
final long curtime = Chronos.currentTimeMillis();
|
final long curtime = Chronos.currentTimeMillis();
|
||||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
for (ItemInstance item : _items)
|
||||||
while (itemIterator.hasNext())
|
|
||||||
{
|
{
|
||||||
final ItemInstance item = itemIterator.next();
|
|
||||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||||
{
|
{
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||||
{
|
{
|
||||||
item.decayMe();
|
item.decayMe();
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
if (Config.SAVE_DROPPED_ITEM)
|
if (Config.SAVE_DROPPED_ITEM)
|
||||||
{
|
{
|
||||||
ItemsOnGroundManager.getInstance().removeObject(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()
|
public static ItemsAutoDestroyTaskManager getInstance()
|
||||||
{
|
{
|
||||||
return SingletonHolder.INSTANCE;
|
return SingletonHolder.INSTANCE;
|
||||||
|
@@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MessageDeletionTaskManager
|
public class MessageDeletionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
Integer msgId;
|
Integer msgId;
|
||||||
Message msg;
|
Message msg;
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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);
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_working = false;
|
if (msg.hasAttachments())
|
||||||
}, 10000, 10000);
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(int msgId, long deletionTime)
|
public void add(int msgId, long deletionTime)
|
||||||
|
@@ -28,38 +28,41 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PlayerAutoSaveTaskManager
|
public class PlayerAutoSaveTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PlayerAutoSaveTaskManager()
|
protected PlayerAutoSaveTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final PlayerInstance player = entry.getKey();
|
||||||
|
if ((player != null) && player.isOnline())
|
||||||
{
|
{
|
||||||
final PlayerInstance player = entry.getKey();
|
player.autoSave();
|
||||||
if ((player != null) && player.isOnline())
|
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;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -26,43 +26,46 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PvpFlagTaskManager
|
public class PvpFlagTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PvpFlagTaskManager()
|
protected PvpFlagTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
if (!PLAYERS.isEmpty())
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
if (!PLAYERS.isEmpty())
|
||||||
|
{
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (PlayerInstance player : PLAYERS)
|
||||||
{
|
{
|
||||||
final long time = Chronos.currentTimeMillis();
|
if (time > player.getPvpFlagLasts())
|
||||||
for (PlayerInstance player : PLAYERS)
|
|
||||||
{
|
{
|
||||||
if (time > player.getPvpFlagLasts())
|
player.stopPvPFlag();
|
||||||
{
|
}
|
||||||
player.stopPvPFlag();
|
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||||
}
|
{
|
||||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
player.updatePvPFlag(2);
|
||||||
{
|
}
|
||||||
player.updatePvPFlag(2);
|
else
|
||||||
}
|
{
|
||||||
else
|
player.updatePvPFlag(1);
|
||||||
{
|
|
||||||
player.updatePvPFlag(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -29,37 +29,40 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RandomAnimationTaskManager
|
public class RandomAnimationTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
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;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc)
|
public void add(Npc npc)
|
||||||
|
@@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RespawnTaskManager
|
public class RespawnTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public RespawnTaskManager()
|
protected RespawnTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
spawn.respawnNpc(npc);
|
||||||
PENDING_RESPAWNS.remove(npc);
|
spawn._scheduledCount--;
|
||||||
final Spawn spawn = npc.getSpawn();
|
|
||||||
if (spawn != null)
|
|
||||||
{
|
|
||||||
spawn.respawnNpc(npc);
|
|
||||||
spawn._scheduledCount--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc, long time)
|
public void add(Npc npc, long time)
|
||||||
|
@@ -33,7 +33,7 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
|||||||
* Attack stance task manager.
|
* Attack stance task manager.
|
||||||
* @author Luca Baldi
|
* @author Luca Baldi
|
||||||
*/
|
*/
|
||||||
public class AttackStanceTaskManager
|
public class AttackStanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
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 final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new attack stance task manager.
|
|
||||||
*/
|
|
||||||
protected AttackStanceTaskManager()
|
protected AttackStanceTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long current = Chronos.currentTimeMillis();
|
@Override
|
||||||
try
|
public void run()
|
||||||
|
{
|
||||||
|
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())
|
||||||
{
|
{
|
||||||
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
|
entry = iterator.next();
|
||||||
Entry<Creature, Long> entry;
|
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
||||||
Creature creature;
|
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
entry = iterator.next();
|
creature = entry.getKey();
|
||||||
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
if (creature != null)
|
||||||
{
|
{
|
||||||
creature = entry.getKey();
|
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||||
if (creature != null)
|
creature.getAI().setAutoAttacking(false);
|
||||||
|
if (creature.isPlayer() && creature.hasSummon())
|
||||||
{
|
{
|
||||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
final Summon pet = creature.getPet();
|
||||||
creature.getAI().setAutoAttacking(false);
|
if (pet != null)
|
||||||
if (creature.isPlayer() && creature.hasSummon())
|
|
||||||
{
|
{
|
||||||
final Summon pet = creature.getPet();
|
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||||
if (pet != null)
|
|
||||||
{
|
|
||||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
|
||||||
}
|
|
||||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
|
||||||
}
|
}
|
||||||
|
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||||
}
|
}
|
||||||
iterator.remove();
|
|
||||||
}
|
}
|
||||||
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
// Unless caught here, players remain in attack positions.
|
{
|
||||||
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
// Unless caught here, players remain in attack positions.
|
||||||
}
|
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,44 +26,47 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager
|
public class AttackableThinkTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
@Override
|
||||||
for (Attackable attackable : ATTACKABLES)
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : ATTACKABLES)
|
||||||
|
{
|
||||||
|
if (attackable.hasAI())
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
ai.onEvtThink();
|
||||||
if (ai != null)
|
|
||||||
{
|
|
||||||
ai.onEvtThink();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
remove(attackable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
remove(attackable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
public void add(Attackable attackable)
|
||||||
|
@@ -28,93 +28,96 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius, Gigi
|
* @author Mobius, Gigi
|
||||||
*/
|
*/
|
||||||
public class AutoPotionTaskManager
|
public class AutoPotionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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);
|
final ItemInstance hpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
continue PLAYER;
|
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
success = true;
|
||||||
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
if (restoreHP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||||
if (restoreHP)
|
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;
|
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
CP: for (int itemId : Config.AUTO_CP_ITEM_IDS)
|
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
if (restoreCP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||||
if (restoreCP)
|
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;
|
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
MP: for (int itemId : Config.AUTO_MP_ITEM_IDS)
|
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
if (restoreMP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||||
if (restoreMP)
|
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;
|
if (!success)
|
||||||
}, 0, 1000);
|
{
|
||||||
|
player.sendMessage("Auto potion: You are out of potions!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -36,9 +36,16 @@ public class BuyListTaskManager
|
|||||||
private static boolean _workingProducts = false;
|
private static boolean _workingProducts = false;
|
||||||
private static boolean _workingSaves = 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)
|
if (_workingProducts)
|
||||||
{
|
{
|
||||||
@@ -64,9 +71,13 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingProducts = false;
|
_workingProducts = false;
|
||||||
}, 1000, 60000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class BuyListSaveTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingSaves)
|
if (_workingSaves)
|
||||||
{
|
{
|
||||||
@@ -86,7 +97,7 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingSaves = false;
|
_workingSaves = false;
|
||||||
}, 50, 50);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Product product, long endTime)
|
public void add(Product product, long endTime)
|
||||||
|
@@ -40,9 +40,16 @@ public class CreatureFollowTaskManager
|
|||||||
private static boolean _workingNormal = false;
|
private static boolean _workingNormal = false;
|
||||||
private static boolean _workingAttack = 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)
|
if (_workingNormal)
|
||||||
{
|
{
|
||||||
@@ -56,9 +63,13 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingNormal = false;
|
_workingNormal = false;
|
||||||
}, 1000, 1000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class CreatureFollowAttackTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingAttack)
|
if (_workingAttack)
|
||||||
{
|
{
|
||||||
@@ -72,7 +83,7 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingAttack = false;
|
_workingAttack = false;
|
||||||
}, 500, 500);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void follow(Creature creature, int range)
|
private void follow(Creature creature, int range)
|
||||||
|
@@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class CreatureSeeTaskManager
|
public class CreatureSeeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
for (Creature creature : CREATURES)
|
for (Creature creature : CREATURES)
|
||||||
{
|
{
|
||||||
creature.updateSeenCreatures();
|
creature.updateSeenCreatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Creature creature)
|
public void add(Creature creature)
|
||||||
|
@@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class DecayTaskManager
|
public class DecayTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final Creature creature = entry.getKey();
|
||||||
{
|
DECAY_SCHEDULES.remove(creature);
|
||||||
final Creature creature = entry.getKey();
|
creature.onDecay();
|
||||||
DECAY_SCHEDULES.remove(creature);
|
|
||||||
creature.onDecay();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemAppearanceTaskManager
|
public class ItemAppearanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.onVisualLifeTimeEnd();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.onVisualLifeTimeEnd();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemLifeTimeTaskManager
|
public class ItemLifeTimeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.endOfLife();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.endOfLife();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,35 +27,38 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemManaTaskManager
|
public class ItemManaTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static final int MANA_CONSUMPTION_RATE = 60000;
|
private static final int MANA_CONSUMPTION_RATE = 60000;
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.decreaseMana(true);
|
||||||
ITEMS.remove(item);
|
|
||||||
item.decreaseMana(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item)
|
public void add(ItemInstance item)
|
||||||
|
@@ -16,9 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.l2jmobius.gameserver.taskmanager;
|
package org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Set;
|
||||||
import java.util.LinkedList;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
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.instancemanager.ItemsOnGroundManager;
|
||||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
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()
|
protected ItemsAutoDestroyTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this::removeItems, 5000, 5000);
|
ThreadPool.scheduleAtFixedRate(this, 5000, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addItem(ItemInstance item)
|
@Override
|
||||||
{
|
public void run()
|
||||||
item.setDropTime(Chronos.currentTimeMillis());
|
|
||||||
_items.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void removeItems()
|
|
||||||
{
|
{
|
||||||
if (_items.isEmpty())
|
if (_items.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
final long curtime = Chronos.currentTimeMillis();
|
final long curtime = Chronos.currentTimeMillis();
|
||||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
for (ItemInstance item : _items)
|
||||||
while (itemIterator.hasNext())
|
|
||||||
{
|
{
|
||||||
final ItemInstance item = itemIterator.next();
|
|
||||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||||
{
|
{
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||||
{
|
{
|
||||||
item.decayMe();
|
item.decayMe();
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
if (Config.SAVE_DROPPED_ITEM)
|
if (Config.SAVE_DROPPED_ITEM)
|
||||||
{
|
{
|
||||||
ItemsOnGroundManager.getInstance().removeObject(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()
|
public static ItemsAutoDestroyTaskManager getInstance()
|
||||||
{
|
{
|
||||||
return SingletonHolder.INSTANCE;
|
return SingletonHolder.INSTANCE;
|
||||||
|
@@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MessageDeletionTaskManager
|
public class MessageDeletionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
Integer msgId;
|
Integer msgId;
|
||||||
Message msg;
|
Message msg;
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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);
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_working = false;
|
if (msg.hasAttachments())
|
||||||
}, 10000, 10000);
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(int msgId, long deletionTime)
|
public void add(int msgId, long deletionTime)
|
||||||
|
@@ -28,38 +28,41 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PlayerAutoSaveTaskManager
|
public class PlayerAutoSaveTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PlayerAutoSaveTaskManager()
|
protected PlayerAutoSaveTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final PlayerInstance player = entry.getKey();
|
||||||
|
if ((player != null) && player.isOnline())
|
||||||
{
|
{
|
||||||
final PlayerInstance player = entry.getKey();
|
player.autoSave();
|
||||||
if ((player != null) && player.isOnline())
|
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;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -26,43 +26,46 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PvpFlagTaskManager
|
public class PvpFlagTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PvpFlagTaskManager()
|
protected PvpFlagTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
if (!PLAYERS.isEmpty())
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
if (!PLAYERS.isEmpty())
|
||||||
|
{
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (PlayerInstance player : PLAYERS)
|
||||||
{
|
{
|
||||||
final long time = Chronos.currentTimeMillis();
|
if (time > player.getPvpFlagLasts())
|
||||||
for (PlayerInstance player : PLAYERS)
|
|
||||||
{
|
{
|
||||||
if (time > player.getPvpFlagLasts())
|
player.stopPvPFlag();
|
||||||
{
|
}
|
||||||
player.stopPvPFlag();
|
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||||
}
|
{
|
||||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
player.updatePvPFlag(2);
|
||||||
{
|
}
|
||||||
player.updatePvPFlag(2);
|
else
|
||||||
}
|
{
|
||||||
else
|
player.updatePvPFlag(1);
|
||||||
{
|
|
||||||
player.updatePvPFlag(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -29,37 +29,40 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RandomAnimationTaskManager
|
public class RandomAnimationTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
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;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc)
|
public void add(Npc npc)
|
||||||
|
@@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RespawnTaskManager
|
public class RespawnTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public RespawnTaskManager()
|
protected RespawnTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
spawn.respawnNpc(npc);
|
||||||
PENDING_RESPAWNS.remove(npc);
|
spawn._scheduledCount--;
|
||||||
final Spawn spawn = npc.getSpawn();
|
|
||||||
if (spawn != null)
|
|
||||||
{
|
|
||||||
spawn.respawnNpc(npc);
|
|
||||||
spawn._scheduledCount--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc, long time)
|
public void add(Npc npc, long time)
|
||||||
|
@@ -33,7 +33,7 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
|||||||
* Attack stance task manager.
|
* Attack stance task manager.
|
||||||
* @author Luca Baldi
|
* @author Luca Baldi
|
||||||
*/
|
*/
|
||||||
public class AttackStanceTaskManager
|
public class AttackStanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
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 final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new attack stance task manager.
|
|
||||||
*/
|
|
||||||
protected AttackStanceTaskManager()
|
protected AttackStanceTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long current = Chronos.currentTimeMillis();
|
@Override
|
||||||
try
|
public void run()
|
||||||
|
{
|
||||||
|
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())
|
||||||
{
|
{
|
||||||
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
|
entry = iterator.next();
|
||||||
Entry<Creature, Long> entry;
|
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
||||||
Creature creature;
|
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
entry = iterator.next();
|
creature = entry.getKey();
|
||||||
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
if (creature != null)
|
||||||
{
|
{
|
||||||
creature = entry.getKey();
|
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||||
if (creature != null)
|
creature.getAI().setAutoAttacking(false);
|
||||||
|
if (creature.isPlayer() && creature.hasSummon())
|
||||||
{
|
{
|
||||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
final Summon pet = creature.getPet();
|
||||||
creature.getAI().setAutoAttacking(false);
|
if (pet != null)
|
||||||
if (creature.isPlayer() && creature.hasSummon())
|
|
||||||
{
|
{
|
||||||
final Summon pet = creature.getPet();
|
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||||
if (pet != null)
|
|
||||||
{
|
|
||||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
|
||||||
}
|
|
||||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
|
||||||
}
|
}
|
||||||
|
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||||
}
|
}
|
||||||
iterator.remove();
|
|
||||||
}
|
}
|
||||||
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
// Unless caught here, players remain in attack positions.
|
{
|
||||||
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
// Unless caught here, players remain in attack positions.
|
||||||
}
|
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,44 +26,47 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager
|
public class AttackableThinkTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
@Override
|
||||||
for (Attackable attackable : ATTACKABLES)
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : ATTACKABLES)
|
||||||
|
{
|
||||||
|
if (attackable.hasAI())
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
ai.onEvtThink();
|
||||||
if (ai != null)
|
|
||||||
{
|
|
||||||
ai.onEvtThink();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
remove(attackable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
remove(attackable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
public void add(Attackable attackable)
|
||||||
|
@@ -28,93 +28,96 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius, Gigi
|
* @author Mobius, Gigi
|
||||||
*/
|
*/
|
||||||
public class AutoPotionTaskManager
|
public class AutoPotionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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);
|
final ItemInstance hpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
continue PLAYER;
|
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
success = true;
|
||||||
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
if (restoreHP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||||
if (restoreHP)
|
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;
|
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
CP: for (int itemId : Config.AUTO_CP_ITEM_IDS)
|
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
if (restoreCP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||||
if (restoreCP)
|
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;
|
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
MP: for (int itemId : Config.AUTO_MP_ITEM_IDS)
|
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
if (restoreMP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||||
if (restoreMP)
|
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;
|
if (!success)
|
||||||
}, 0, 1000);
|
{
|
||||||
|
player.sendMessage("Auto potion: You are out of potions!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -36,9 +36,16 @@ public class BuyListTaskManager
|
|||||||
private static boolean _workingProducts = false;
|
private static boolean _workingProducts = false;
|
||||||
private static boolean _workingSaves = 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)
|
if (_workingProducts)
|
||||||
{
|
{
|
||||||
@@ -64,9 +71,13 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingProducts = false;
|
_workingProducts = false;
|
||||||
}, 1000, 60000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class BuyListSaveTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingSaves)
|
if (_workingSaves)
|
||||||
{
|
{
|
||||||
@@ -86,7 +97,7 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingSaves = false;
|
_workingSaves = false;
|
||||||
}, 50, 50);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Product product, long endTime)
|
public void add(Product product, long endTime)
|
||||||
|
@@ -40,9 +40,16 @@ public class CreatureFollowTaskManager
|
|||||||
private static boolean _workingNormal = false;
|
private static boolean _workingNormal = false;
|
||||||
private static boolean _workingAttack = 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)
|
if (_workingNormal)
|
||||||
{
|
{
|
||||||
@@ -56,9 +63,13 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingNormal = false;
|
_workingNormal = false;
|
||||||
}, 1000, 1000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class CreatureFollowAttackTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingAttack)
|
if (_workingAttack)
|
||||||
{
|
{
|
||||||
@@ -72,7 +83,7 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingAttack = false;
|
_workingAttack = false;
|
||||||
}, 500, 500);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void follow(Creature creature, int range)
|
private void follow(Creature creature, int range)
|
||||||
|
@@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class CreatureSeeTaskManager
|
public class CreatureSeeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
for (Creature creature : CREATURES)
|
for (Creature creature : CREATURES)
|
||||||
{
|
{
|
||||||
creature.updateSeenCreatures();
|
creature.updateSeenCreatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Creature creature)
|
public void add(Creature creature)
|
||||||
|
@@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class DecayTaskManager
|
public class DecayTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final Creature creature = entry.getKey();
|
||||||
{
|
DECAY_SCHEDULES.remove(creature);
|
||||||
final Creature creature = entry.getKey();
|
creature.onDecay();
|
||||||
DECAY_SCHEDULES.remove(creature);
|
|
||||||
creature.onDecay();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemAppearanceTaskManager
|
public class ItemAppearanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.onVisualLifeTimeEnd();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.onVisualLifeTimeEnd();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemLifeTimeTaskManager
|
public class ItemLifeTimeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.endOfLife();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.endOfLife();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,35 +27,38 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemManaTaskManager
|
public class ItemManaTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static final int MANA_CONSUMPTION_RATE = 60000;
|
private static final int MANA_CONSUMPTION_RATE = 60000;
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.decreaseMana(true);
|
||||||
ITEMS.remove(item);
|
|
||||||
item.decreaseMana(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item)
|
public void add(ItemInstance item)
|
||||||
|
@@ -16,9 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.l2jmobius.gameserver.taskmanager;
|
package org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Set;
|
||||||
import java.util.LinkedList;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
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.instancemanager.ItemsOnGroundManager;
|
||||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
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()
|
protected ItemsAutoDestroyTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this::removeItems, 5000, 5000);
|
ThreadPool.scheduleAtFixedRate(this, 5000, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addItem(ItemInstance item)
|
@Override
|
||||||
{
|
public void run()
|
||||||
item.setDropTime(Chronos.currentTimeMillis());
|
|
||||||
_items.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void removeItems()
|
|
||||||
{
|
{
|
||||||
if (_items.isEmpty())
|
if (_items.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
final long curtime = Chronos.currentTimeMillis();
|
final long curtime = Chronos.currentTimeMillis();
|
||||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
for (ItemInstance item : _items)
|
||||||
while (itemIterator.hasNext())
|
|
||||||
{
|
{
|
||||||
final ItemInstance item = itemIterator.next();
|
|
||||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||||
{
|
{
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||||
{
|
{
|
||||||
item.decayMe();
|
item.decayMe();
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
if (Config.SAVE_DROPPED_ITEM)
|
if (Config.SAVE_DROPPED_ITEM)
|
||||||
{
|
{
|
||||||
ItemsOnGroundManager.getInstance().removeObject(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()
|
public static ItemsAutoDestroyTaskManager getInstance()
|
||||||
{
|
{
|
||||||
return SingletonHolder.INSTANCE;
|
return SingletonHolder.INSTANCE;
|
||||||
|
@@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MessageDeletionTaskManager
|
public class MessageDeletionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
Integer msgId;
|
Integer msgId;
|
||||||
Message msg;
|
Message msg;
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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);
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_working = false;
|
if (msg.hasAttachments())
|
||||||
}, 10000, 10000);
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(int msgId, long deletionTime)
|
public void add(int msgId, long deletionTime)
|
||||||
|
@@ -28,38 +28,41 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PlayerAutoSaveTaskManager
|
public class PlayerAutoSaveTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PlayerAutoSaveTaskManager()
|
protected PlayerAutoSaveTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final PlayerInstance player = entry.getKey();
|
||||||
|
if ((player != null) && player.isOnline())
|
||||||
{
|
{
|
||||||
final PlayerInstance player = entry.getKey();
|
player.autoSave();
|
||||||
if ((player != null) && player.isOnline())
|
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;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -26,43 +26,46 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PvpFlagTaskManager
|
public class PvpFlagTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PvpFlagTaskManager()
|
protected PvpFlagTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
if (!PLAYERS.isEmpty())
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
if (!PLAYERS.isEmpty())
|
||||||
|
{
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (PlayerInstance player : PLAYERS)
|
||||||
{
|
{
|
||||||
final long time = Chronos.currentTimeMillis();
|
if (time > player.getPvpFlagLasts())
|
||||||
for (PlayerInstance player : PLAYERS)
|
|
||||||
{
|
{
|
||||||
if (time > player.getPvpFlagLasts())
|
player.stopPvPFlag();
|
||||||
{
|
}
|
||||||
player.stopPvPFlag();
|
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||||
}
|
{
|
||||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
player.updatePvPFlag(2);
|
||||||
{
|
}
|
||||||
player.updatePvPFlag(2);
|
else
|
||||||
}
|
{
|
||||||
else
|
player.updatePvPFlag(1);
|
||||||
{
|
|
||||||
player.updatePvPFlag(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -29,37 +29,40 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RandomAnimationTaskManager
|
public class RandomAnimationTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
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;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc)
|
public void add(Npc npc)
|
||||||
|
@@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RespawnTaskManager
|
public class RespawnTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public RespawnTaskManager()
|
protected RespawnTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
spawn.respawnNpc(npc);
|
||||||
PENDING_RESPAWNS.remove(npc);
|
spawn._scheduledCount--;
|
||||||
final Spawn spawn = npc.getSpawn();
|
|
||||||
if (spawn != null)
|
|
||||||
{
|
|
||||||
spawn.respawnNpc(npc);
|
|
||||||
spawn._scheduledCount--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc, long time)
|
public void add(Npc npc, long time)
|
||||||
|
@@ -33,7 +33,7 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
|||||||
* Attack stance task manager.
|
* Attack stance task manager.
|
||||||
* @author Luca Baldi
|
* @author Luca Baldi
|
||||||
*/
|
*/
|
||||||
public class AttackStanceTaskManager
|
public class AttackStanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
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 final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new attack stance task manager.
|
|
||||||
*/
|
|
||||||
protected AttackStanceTaskManager()
|
protected AttackStanceTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long current = Chronos.currentTimeMillis();
|
@Override
|
||||||
try
|
public void run()
|
||||||
|
{
|
||||||
|
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())
|
||||||
{
|
{
|
||||||
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
|
entry = iterator.next();
|
||||||
Entry<Creature, Long> entry;
|
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
||||||
Creature creature;
|
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
entry = iterator.next();
|
creature = entry.getKey();
|
||||||
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
if (creature != null)
|
||||||
{
|
{
|
||||||
creature = entry.getKey();
|
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||||
if (creature != null)
|
creature.getAI().setAutoAttacking(false);
|
||||||
|
if (creature.isPlayer() && creature.hasSummon())
|
||||||
{
|
{
|
||||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
final Summon pet = creature.getPet();
|
||||||
creature.getAI().setAutoAttacking(false);
|
if (pet != null)
|
||||||
if (creature.isPlayer() && creature.hasSummon())
|
|
||||||
{
|
{
|
||||||
final Summon pet = creature.getPet();
|
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||||
if (pet != null)
|
|
||||||
{
|
|
||||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
|
||||||
}
|
|
||||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
|
||||||
}
|
}
|
||||||
|
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||||
}
|
}
|
||||||
iterator.remove();
|
|
||||||
}
|
}
|
||||||
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
// Unless caught here, players remain in attack positions.
|
{
|
||||||
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
// Unless caught here, players remain in attack positions.
|
||||||
}
|
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,44 +26,47 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager
|
public class AttackableThinkTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
@Override
|
||||||
for (Attackable attackable : ATTACKABLES)
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : ATTACKABLES)
|
||||||
|
{
|
||||||
|
if (attackable.hasAI())
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
ai.onEvtThink();
|
||||||
if (ai != null)
|
|
||||||
{
|
|
||||||
ai.onEvtThink();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
remove(attackable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
remove(attackable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
public void add(Attackable attackable)
|
||||||
|
@@ -28,93 +28,96 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius, Gigi
|
* @author Mobius, Gigi
|
||||||
*/
|
*/
|
||||||
public class AutoPotionTaskManager
|
public class AutoPotionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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);
|
final ItemInstance hpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
continue PLAYER;
|
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
success = true;
|
||||||
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
if (restoreHP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||||
if (restoreHP)
|
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;
|
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
CP: for (int itemId : Config.AUTO_CP_ITEM_IDS)
|
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
if (restoreCP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||||
if (restoreCP)
|
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;
|
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
MP: for (int itemId : Config.AUTO_MP_ITEM_IDS)
|
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
if (restoreMP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||||
if (restoreMP)
|
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;
|
if (!success)
|
||||||
}, 0, 1000);
|
{
|
||||||
|
player.sendMessage("Auto potion: You are out of potions!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -36,9 +36,16 @@ public class BuyListTaskManager
|
|||||||
private static boolean _workingProducts = false;
|
private static boolean _workingProducts = false;
|
||||||
private static boolean _workingSaves = 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)
|
if (_workingProducts)
|
||||||
{
|
{
|
||||||
@@ -64,9 +71,13 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingProducts = false;
|
_workingProducts = false;
|
||||||
}, 1000, 60000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class BuyListSaveTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingSaves)
|
if (_workingSaves)
|
||||||
{
|
{
|
||||||
@@ -86,7 +97,7 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingSaves = false;
|
_workingSaves = false;
|
||||||
}, 50, 50);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Product product, long endTime)
|
public void add(Product product, long endTime)
|
||||||
|
@@ -40,9 +40,16 @@ public class CreatureFollowTaskManager
|
|||||||
private static boolean _workingNormal = false;
|
private static boolean _workingNormal = false;
|
||||||
private static boolean _workingAttack = 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)
|
if (_workingNormal)
|
||||||
{
|
{
|
||||||
@@ -56,9 +63,13 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingNormal = false;
|
_workingNormal = false;
|
||||||
}, 1000, 1000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class CreatureFollowAttackTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingAttack)
|
if (_workingAttack)
|
||||||
{
|
{
|
||||||
@@ -72,7 +83,7 @@ public class CreatureFollowTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingAttack = false;
|
_workingAttack = false;
|
||||||
}, 500, 500);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void follow(Creature creature, int range)
|
private void follow(Creature creature, int range)
|
||||||
|
@@ -25,28 +25,31 @@ import org.l2jmobius.gameserver.model.actor.Creature;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class CreatureSeeTaskManager
|
public class CreatureSeeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
for (Creature creature : CREATURES)
|
for (Creature creature : CREATURES)
|
||||||
{
|
{
|
||||||
creature.updateSeenCreatures();
|
creature.updateSeenCreatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Creature creature)
|
public void add(Creature creature)
|
||||||
|
@@ -30,34 +30,37 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class DecayTaskManager
|
public class DecayTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
private static final Map<Creature, Long> DECAY_SCHEDULES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
for (Entry<Creature, Long> entry : DECAY_SCHEDULES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final Creature creature = entry.getKey();
|
||||||
{
|
DECAY_SCHEDULES.remove(creature);
|
||||||
final Creature creature = entry.getKey();
|
creature.onDecay();
|
||||||
DECAY_SCHEDULES.remove(creature);
|
|
||||||
creature.onDecay();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemAppearanceTaskManager
|
public class ItemAppearanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.onVisualLifeTimeEnd();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.onVisualLifeTimeEnd();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,34 +27,37 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemLifeTimeTaskManager
|
public class ItemLifeTimeTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.endOfLife();
|
||||||
ITEMS.remove(item);
|
|
||||||
item.endOfLife();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item, long endTime)
|
public void add(ItemInstance item, long endTime)
|
||||||
|
@@ -27,35 +27,38 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class ItemManaTaskManager
|
public class ItemManaTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
private static final Map<ItemInstance, Long> ITEMS = new ConcurrentHashMap<>();
|
||||||
private static final int MANA_CONSUMPTION_RATE = 60000;
|
private static final int MANA_CONSUMPTION_RATE = 60000;
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long currentTime = Chronos.currentTimeMillis();
|
final long currentTime = Chronos.currentTimeMillis();
|
||||||
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
for (Entry<ItemInstance, Long> entry : ITEMS.entrySet())
|
||||||
|
{
|
||||||
|
if (currentTime > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (currentTime > entry.getValue().longValue())
|
final ItemInstance item = entry.getKey();
|
||||||
{
|
ITEMS.remove(item);
|
||||||
final ItemInstance item = entry.getKey();
|
item.decreaseMana(true);
|
||||||
ITEMS.remove(item);
|
|
||||||
item.decreaseMana(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ItemInstance item)
|
public void add(ItemInstance item)
|
||||||
|
@@ -16,9 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.l2jmobius.gameserver.taskmanager;
|
package org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Set;
|
||||||
import java.util.LinkedList;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
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.instancemanager.ItemsOnGroundManager;
|
||||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
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()
|
protected ItemsAutoDestroyTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(this::removeItems, 5000, 5000);
|
ThreadPool.scheduleAtFixedRate(this, 5000, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addItem(ItemInstance item)
|
@Override
|
||||||
{
|
public void run()
|
||||||
item.setDropTime(Chronos.currentTimeMillis());
|
|
||||||
_items.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void removeItems()
|
|
||||||
{
|
{
|
||||||
if (_items.isEmpty())
|
if (_items.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -50,13 +44,11 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
final long curtime = Chronos.currentTimeMillis();
|
final long curtime = Chronos.currentTimeMillis();
|
||||||
final Iterator<ItemInstance> itemIterator = _items.iterator();
|
for (ItemInstance item : _items)
|
||||||
while (itemIterator.hasNext())
|
|
||||||
{
|
{
|
||||||
final ItemInstance item = itemIterator.next();
|
|
||||||
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
if ((item.getDropTime() == 0) || (item.getItemLocation() != ItemLocation.VOID))
|
||||||
{
|
{
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -77,7 +69,7 @@ public class ItemsAutoDestroyTaskManager
|
|||||||
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
if ((curtime - item.getDropTime()) > autoDestroyTime)
|
||||||
{
|
{
|
||||||
item.decayMe();
|
item.decayMe();
|
||||||
itemIterator.remove();
|
_items.remove(item);
|
||||||
if (Config.SAVE_DROPPED_ITEM)
|
if (Config.SAVE_DROPPED_ITEM)
|
||||||
{
|
{
|
||||||
ItemsOnGroundManager.getInstance().removeObject(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()
|
public static ItemsAutoDestroyTaskManager getInstance()
|
||||||
{
|
{
|
||||||
return SingletonHolder.INSTANCE;
|
return SingletonHolder.INSTANCE;
|
||||||
|
@@ -32,65 +32,68 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class MessageDeletionTaskManager
|
public class MessageDeletionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
Integer msgId;
|
Integer msgId;
|
||||||
Message msg;
|
Message msg;
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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);
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_working = false;
|
if (msg.hasAttachments())
|
||||||
}, 10000, 10000);
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(int msgId, long deletionTime)
|
public void add(int msgId, long deletionTime)
|
||||||
|
@@ -28,38 +28,41 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PlayerAutoSaveTaskManager
|
public class PlayerAutoSaveTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
private static final Map<PlayerInstance, Long> PLAYER_TIMES = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PlayerAutoSaveTaskManager()
|
protected PlayerAutoSaveTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
SEARCH: for (Entry<PlayerInstance, Long> entry : PLAYER_TIMES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
if (time > entry.getValue().longValue())
|
final PlayerInstance player = entry.getKey();
|
||||||
|
if ((player != null) && player.isOnline())
|
||||||
{
|
{
|
||||||
final PlayerInstance player = entry.getKey();
|
player.autoSave();
|
||||||
if ((player != null) && player.isOnline())
|
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;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -26,43 +26,46 @@ import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class PvpFlagTaskManager
|
public class PvpFlagTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public PvpFlagTaskManager()
|
protected PvpFlagTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
if (!PLAYERS.isEmpty())
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
if (!PLAYERS.isEmpty())
|
||||||
|
{
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (PlayerInstance player : PLAYERS)
|
||||||
{
|
{
|
||||||
final long time = Chronos.currentTimeMillis();
|
if (time > player.getPvpFlagLasts())
|
||||||
for (PlayerInstance player : PLAYERS)
|
|
||||||
{
|
{
|
||||||
if (time > player.getPvpFlagLasts())
|
player.stopPvPFlag();
|
||||||
{
|
}
|
||||||
player.stopPvPFlag();
|
else if (time > (player.getPvpFlagLasts() - 20000))
|
||||||
}
|
{
|
||||||
else if (time > (player.getPvpFlagLasts() - 20000))
|
player.updatePvPFlag(2);
|
||||||
{
|
}
|
||||||
player.updatePvPFlag(2);
|
else
|
||||||
}
|
{
|
||||||
else
|
player.updatePvPFlag(1);
|
||||||
{
|
|
||||||
player.updatePvPFlag(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -29,37 +29,40 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RandomAnimationTaskManager
|
public class RandomAnimationTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
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;
|
||||||
{
|
}
|
||||||
return;
|
_working = true;
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
final long time = Chronos.currentTimeMillis();
|
||||||
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
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;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc)
|
public void add(Npc npc)
|
||||||
|
@@ -28,39 +28,42 @@ import org.l2jmobius.gameserver.model.actor.Npc;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class RespawnTaskManager
|
public class RespawnTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public RespawnTaskManager()
|
protected RespawnTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long time = Chronos.currentTimeMillis();
|
@Override
|
||||||
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
final long time = Chronos.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue().longValue())
|
||||||
{
|
{
|
||||||
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();
|
spawn.respawnNpc(npc);
|
||||||
PENDING_RESPAWNS.remove(npc);
|
spawn._scheduledCount--;
|
||||||
final Spawn spawn = npc.getSpawn();
|
|
||||||
if (spawn != null)
|
|
||||||
{
|
|
||||||
spawn.respawnNpc(npc);
|
|
||||||
spawn._scheduledCount--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Npc npc, long time)
|
public void add(Npc npc, long time)
|
||||||
|
@@ -33,7 +33,7 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
|||||||
* Attack stance task manager.
|
* Attack stance task manager.
|
||||||
* @author Luca Baldi
|
* @author Luca Baldi
|
||||||
*/
|
*/
|
||||||
public class AttackStanceTaskManager
|
public class AttackStanceTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
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 final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new attack stance task manager.
|
|
||||||
*/
|
|
||||||
protected AttackStanceTaskManager()
|
protected AttackStanceTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 0, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
final long current = Chronos.currentTimeMillis();
|
@Override
|
||||||
try
|
public void run()
|
||||||
|
{
|
||||||
|
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())
|
||||||
{
|
{
|
||||||
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
|
entry = iterator.next();
|
||||||
Entry<Creature, Long> entry;
|
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
||||||
Creature creature;
|
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
entry = iterator.next();
|
creature = entry.getKey();
|
||||||
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
|
if (creature != null)
|
||||||
{
|
{
|
||||||
creature = entry.getKey();
|
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
||||||
if (creature != null)
|
creature.getAI().setAutoAttacking(false);
|
||||||
|
if (creature.isPlayer() && creature.hasSummon())
|
||||||
{
|
{
|
||||||
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
|
final Summon pet = creature.getPet();
|
||||||
creature.getAI().setAutoAttacking(false);
|
if (pet != null)
|
||||||
if (creature.isPlayer() && creature.hasSummon())
|
|
||||||
{
|
{
|
||||||
final Summon pet = creature.getPet();
|
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
||||||
if (pet != null)
|
|
||||||
{
|
|
||||||
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
|
|
||||||
}
|
|
||||||
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
|
||||||
}
|
}
|
||||||
|
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
|
||||||
}
|
}
|
||||||
iterator.remove();
|
|
||||||
}
|
}
|
||||||
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
catch (Exception e)
|
||||||
// Unless caught here, players remain in attack positions.
|
{
|
||||||
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
// Unless caught here, players remain in attack positions.
|
||||||
}
|
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 0, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,44 +26,47 @@ import org.l2jmobius.gameserver.model.actor.Attackable;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
public class AttackableThinkTaskManager
|
public class AttackableThinkTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
private static final Set<Attackable> ATTACKABLES = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
private static boolean _working = false;
|
||||||
|
|
||||||
public AttackableThinkTaskManager()
|
protected AttackableThinkTaskManager()
|
||||||
{
|
{
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
|
||||||
{
|
}
|
||||||
if (_working)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_working = true;
|
|
||||||
|
|
||||||
CreatureAI ai;
|
@Override
|
||||||
for (Attackable attackable : ATTACKABLES)
|
public void run()
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
CreatureAI ai;
|
||||||
|
for (Attackable attackable : ATTACKABLES)
|
||||||
|
{
|
||||||
|
if (attackable.hasAI())
|
||||||
{
|
{
|
||||||
if (attackable.hasAI())
|
ai = attackable.getAI();
|
||||||
|
if (ai != null)
|
||||||
{
|
{
|
||||||
ai = attackable.getAI();
|
ai.onEvtThink();
|
||||||
if (ai != null)
|
|
||||||
{
|
|
||||||
ai.onEvtThink();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
remove(attackable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove(attackable);
|
remove(attackable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
remove(attackable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_working = false;
|
_working = false;
|
||||||
}, 1000, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Attackable attackable)
|
public void add(Attackable attackable)
|
||||||
|
@@ -28,93 +28,96 @@ import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
|||||||
/**
|
/**
|
||||||
* @author Mobius, Gigi
|
* @author Mobius, Gigi
|
||||||
*/
|
*/
|
||||||
public class AutoPotionTaskManager
|
public class AutoPotionTaskManager implements Runnable
|
||||||
{
|
{
|
||||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||||
private static boolean _working = false;
|
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);
|
final ItemInstance hpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
continue PLAYER;
|
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
success = true;
|
||||||
if ((hpPotion != null) && (hpPotion.getCount() > 0))
|
if (restoreHP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(hpPotion.getEtcItem()).useItem(player, hpPotion, false);
|
||||||
if (restoreHP)
|
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;
|
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
CP: for (int itemId : Config.AUTO_CP_ITEM_IDS)
|
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance cpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((cpPotion != null) && (cpPotion.getCount() > 0))
|
if (restoreCP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(cpPotion.getEtcItem()).useItem(player, cpPotion, false);
|
||||||
if (restoreCP)
|
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;
|
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
||||||
MP: for (int itemId : Config.AUTO_MP_ITEM_IDS)
|
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
||||||
{
|
{
|
||||||
final ItemInstance mpPotion = player.getInventory().getItemByItemId(itemId);
|
success = true;
|
||||||
if ((mpPotion != null) && (mpPotion.getCount() > 0))
|
if (restoreMP)
|
||||||
{
|
{
|
||||||
success = true;
|
ItemHandler.getInstance().getHandler(mpPotion.getEtcItem()).useItem(player, mpPotion, false);
|
||||||
if (restoreMP)
|
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;
|
if (!success)
|
||||||
}, 0, 1000);
|
{
|
||||||
|
player.sendMessage("Auto potion: You are out of potions!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PlayerInstance player)
|
public void add(PlayerInstance player)
|
||||||
|
@@ -36,9 +36,16 @@ public class BuyListTaskManager
|
|||||||
private static boolean _workingProducts = false;
|
private static boolean _workingProducts = false;
|
||||||
private static boolean _workingSaves = 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)
|
if (_workingProducts)
|
||||||
{
|
{
|
||||||
@@ -64,9 +71,13 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingProducts = false;
|
_workingProducts = false;
|
||||||
}, 1000, 60000);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ThreadPool.scheduleAtFixedRate(() ->
|
protected class BuyListSaveTask implements Runnable
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
{
|
{
|
||||||
if (_workingSaves)
|
if (_workingSaves)
|
||||||
{
|
{
|
||||||
@@ -86,7 +97,7 @@ public class BuyListTaskManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_workingSaves = false;
|
_workingSaves = false;
|
||||||
}, 50, 50);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Product product, long endTime)
|
public void add(Product product, long endTime)
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user