AttackStanceTaskManager adjustments to match other task managers.

This commit is contained in:
MobiusDevelopment 2020-07-02 23:32:21 +00:00
parent 75bfbb9173
commit 0b96b58d6e
19 changed files with 1123 additions and 1000 deletions

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -16,14 +16,15 @@
*/
package org.l2jmobius.gameserver.taskmanager;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.instance.CubicInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
@ -34,29 +35,75 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private AttackStanceTaskManager()
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && (((PlayerInstance) creature).getPet() != null))
{
((PlayerInstance) creature).getPet().broadcastPacket(new AutoAttackStop(((PlayerInstance) creature).getPet().getObjectId()));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param creature the actor
*/
public void addAttackStanceTask(Creature creature)
{
Creature actor = creature;
if (actor instanceof Summon)
if (creature == null)
{
final Summon summon = (Summon) actor;
actor = summon.getOwner();
return;
}
if (actor instanceof PlayerInstance)
if (creature.isPlayable())
{
final PlayerInstance player = (PlayerInstance) actor;
for (CubicInstance cubic : player.getCubics().values())
for (CubicInstance cubic : creature.getActingPlayer().getCubics().values())
{
if (cubic.getId() != CubicInstance.LIFE_CUBIC)
{
@ -64,70 +111,43 @@ public class AttackStanceTaskManager
}
}
}
_attackStanceTasks.put(actor, System.currentTimeMillis());
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
* Removes the attack stance task.
* @param creature the actor
*/
public void removeAttackStanceTask(Creature creature)
{
Creature actor = creature;
if (actor instanceof Summon)
if (actor != null)
{
final Summon summon = (Summon) actor;
actor = summon.getOwner();
if (actor.isSummon())
{
actor = actor.getActingPlayer();
}
_attackStanceTasks.remove(actor);
}
_attackStanceTasks.remove(actor);
}
/**
* Checks for attack stance task.
* @param creature the actor
* @return {@code true} if the character has an attack stance task, {@code false} otherwise
*/
public boolean hasAttackStanceTask(Creature creature)
{
Creature actor = creature;
if (actor instanceof Summon)
if (actor != null)
{
final Summon summon = (Summon) actor;
actor = summon.getOwner();
}
return _attackStanceTasks.containsKey(actor);
}
private class FightModeScheduler implements Runnable
{
protected FightModeScheduler()
{
}
@Override
public void run()
{
final Long current = System.currentTimeMillis();
try
if (actor.isSummon())
{
if (_attackStanceTasks != null)
{
synchronized (this)
{
for (Entry<Creature, Long> entry : _attackStanceTasks.entrySet())
{
final Creature actor = entry.getKey();
if ((current - entry.getValue()) > COMBAT_TIME)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
if ((actor instanceof PlayerInstance) && (((PlayerInstance) actor).getPet() != null))
{
((PlayerInstance) actor).getPet().broadcastPacket(new AutoAttackStop(((PlayerInstance) actor).getPet().getObjectId()));
}
actor.getAI().setAutoAttacking(false);
_attackStanceTasks.remove(actor);
}
}
}
}
}
catch (Exception e)
{
// TODO: Find out the reason for exception. Unless caught here, players remain in attack positions.
LOGGER.warning("Error in FightModeScheduler: " + e.getMessage());
actor = actor.getActingPlayer();
}
return _attackStanceTasks.containsKey(actor);
}
return false;
}
/**

View File

@ -16,14 +16,15 @@
*/
package org.l2jmobius.gameserver.taskmanager;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.instance.CubicInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
@ -34,29 +35,75 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private AttackStanceTaskManager()
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && (((PlayerInstance) creature).getPet() != null))
{
((PlayerInstance) creature).getPet().broadcastPacket(new AutoAttackStop(((PlayerInstance) creature).getPet().getObjectId()));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param creature the actor
*/
public void addAttackStanceTask(Creature creature)
{
Creature actor = creature;
if (actor instanceof Summon)
if (creature == null)
{
final Summon summon = (Summon) actor;
actor = summon.getOwner();
return;
}
if (actor instanceof PlayerInstance)
if (creature.isPlayable())
{
final PlayerInstance player = (PlayerInstance) actor;
for (CubicInstance cubic : player.getCubics().values())
for (CubicInstance cubic : creature.getActingPlayer().getCubics().values())
{
if (cubic.getId() != CubicInstance.LIFE_CUBIC)
{
@ -64,70 +111,43 @@ public class AttackStanceTaskManager
}
}
}
_attackStanceTasks.put(actor, System.currentTimeMillis());
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
* Removes the attack stance task.
* @param creature the actor
*/
public void removeAttackStanceTask(Creature creature)
{
Creature actor = creature;
if (actor instanceof Summon)
if (actor != null)
{
final Summon summon = (Summon) actor;
actor = summon.getOwner();
if (actor.isSummon())
{
actor = actor.getActingPlayer();
}
_attackStanceTasks.remove(actor);
}
_attackStanceTasks.remove(actor);
}
/**
* Checks for attack stance task.
* @param creature the actor
* @return {@code true} if the character has an attack stance task, {@code false} otherwise
*/
public boolean hasAttackStanceTask(Creature creature)
{
Creature actor = creature;
if (actor instanceof Summon)
if (actor != null)
{
final Summon summon = (Summon) actor;
actor = summon.getOwner();
}
return _attackStanceTasks.containsKey(actor);
}
private class FightModeScheduler implements Runnable
{
protected FightModeScheduler()
{
}
@Override
public void run()
{
final Long current = System.currentTimeMillis();
try
if (actor.isSummon())
{
if (_attackStanceTasks != null)
{
synchronized (this)
{
for (Entry<Creature, Long> entry : _attackStanceTasks.entrySet())
{
final Creature actor = entry.getKey();
if ((current - entry.getValue()) > COMBAT_TIME)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
if ((actor instanceof PlayerInstance) && (((PlayerInstance) actor).getPet() != null))
{
((PlayerInstance) actor).getPet().broadcastPacket(new AutoAttackStop(((PlayerInstance) actor).getPet().getObjectId()));
}
actor.getAI().setAutoAttacking(false);
_attackStanceTasks.remove(actor);
}
}
}
}
}
catch (Exception e)
{
// TODO: Find out the reason for exception. Unless caught here, players remain in attack positions.
LOGGER.warning("Error in FightModeScheduler: " + e.getMessage());
actor = actor.getActingPlayer();
}
return _attackStanceTasks.containsKey(actor);
}
return false;
}
/**

View File

@ -30,37 +30,79 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
creature.getSummon().broadcastPacket(new AutoAttackStop(creature.getSummon().getObjectId()));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor == null)
if (creature == null)
{
return;
}
if (actor.isPlayable())
if (creature.isPlayable())
{
for (CubicInstance cubic : actor.getActingPlayer().getCubics().values())
for (CubicInstance cubic : creature.getActingPlayer().getCubics().values())
{
if (cubic.getId() != CubicInstance.LIFE_CUBIC)
{
@ -68,7 +110,7 @@ public class AttackStanceTaskManager
}
}
}
_attackStanceTasks.put(actor, System.currentTimeMillis());
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -107,44 +149,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
actor.getSummon().broadcastPacket(new AutoAttackStop(actor.getSummon().getObjectId()));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,37 +30,79 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
creature.getSummon().broadcastPacket(new AutoAttackStop(creature.getSummon().getObjectId()));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor == null)
if (creature == null)
{
return;
}
if (actor.isPlayable())
if (creature.isPlayable())
{
for (CubicInstance cubic : actor.getActingPlayer().getCubics().values())
for (CubicInstance cubic : creature.getActingPlayer().getCubics().values())
{
if (cubic.getId() != CubicInstance.LIFE_CUBIC)
{
@ -68,7 +110,7 @@ public class AttackStanceTaskManager
}
}
}
_attackStanceTasks.put(actor, System.currentTimeMillis());
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -107,44 +149,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
actor.getSummon().broadcastPacket(new AutoAttackStop(actor.getSummon().getObjectId()));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager

View File

@ -30,34 +30,82 @@ import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AttackStanceTaskManager.class.getName());
public static final long COMBAT_TIME = 15000;
private static final Map<Creature, Long> _attackStanceTasks = new ConcurrentHashMap<>();
private static boolean _working = false;
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPool.scheduleAtFixedRate(new FightModeScheduler(), 0, 1000);
ThreadPool.scheduleAtFixedRate(() ->
{
if (_working)
{
return;
}
_working = true;
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iterator = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> entry;
Creature creature;
while (iterator.hasNext())
{
entry = iterator.next();
if ((current - entry.getValue().longValue()) > COMBAT_TIME)
{
creature = entry.getKey();
if (creature != null)
{
creature.broadcastPacket(new AutoAttackStop(creature.getObjectId()));
creature.getAI().setAutoAttacking(false);
if (creature.isPlayer() && creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
creature.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iterator.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in AttackStanceTaskManager: " + e.getMessage(), e);
}
_working = false;
}, 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
* @param creature the actor
*/
public void addAttackStanceTask(Creature actor)
public void addAttackStanceTask(Creature creature)
{
if (actor != null)
if (creature == null)
{
_attackStanceTasks.put(actor, System.currentTimeMillis());
return;
}
_attackStanceTasks.put(creature, System.currentTimeMillis());
}
/**
@ -96,49 +144,6 @@ public class AttackStanceTaskManager
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<Creature, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<Creature, Long> e;
Creature actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > COMBAT_TIME)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
LOGGER.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager