Removed schedule lists from respawn task manager.

This commit is contained in:
MobiusDevelopment
2019-06-09 06:01:25 +00:00
parent 51d45f8261
commit b0f6f357fd
14 changed files with 154 additions and 350 deletions

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance; import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.spawn.Spawn;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<NpcInstance, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<NpcInstance, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<NpcInstance, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<NpcInstance, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final NpcInstance npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final NpcInstance npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(NpcInstance npc, Long time) public void add(NpcInstance npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()

View File

@@ -16,11 +16,9 @@
*/ */
package org.l2jmobius.gameserver.taskmanager; package org.l2jmobius.gameserver.taskmanager;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.model.Spawn; import org.l2jmobius.gameserver.model.Spawn;
@@ -31,45 +29,33 @@ import org.l2jmobius.gameserver.model.actor.Npc;
*/ */
public class RespawnTaskManager public class RespawnTaskManager
{ {
private static final Map<Npc, List<Long>> PENDING_RESPAWNS = new ConcurrentHashMap<>(); private static final Map<Npc, Long> PENDING_RESPAWNS = new ConcurrentHashMap<>();
public RespawnTaskManager() public RespawnTaskManager()
{ {
ThreadPool.scheduleAtFixedRate(() -> ThreadPool.scheduleAtFixedRate(() ->
{ {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
for (Entry<Npc, List<Long>> entry : PENDING_RESPAWNS.entrySet()) for (Entry<Npc, Long> entry : PENDING_RESPAWNS.entrySet())
{ {
final Npc npc = entry.getKey(); if (time > entry.getValue())
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{ {
if (time > respawnTime) final Npc npc = entry.getKey();
PENDING_RESPAWNS.remove(npc);
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{ {
schedules.remove(respawnTime); spawn.respawnNpc(npc);
if (schedules.isEmpty()) spawn._scheduledCount--;
{
PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn();
if (spawn != null)
{
spawn.respawnNpc(npc);
spawn._scheduledCount--;
}
} }
} }
} }
}, 0, 1000); }, 0, 1000);
} }
public void add(Npc npc, Long time) public void add(Npc npc, long time)
{ {
if (!PENDING_RESPAWNS.containsKey(npc)) PENDING_RESPAWNS.put(npc, time);
{
PENDING_RESPAWNS.put(npc, new CopyOnWriteArrayList<>());
}
PENDING_RESPAWNS.get(npc).add(time);
} }
public static RespawnTaskManager getInstance() public static RespawnTaskManager getInstance()