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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final NpcInstance npc = entry.getKey(); final NpcInstance npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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,26 +29,19 @@ 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())
{
if (time > entry.getValue())
{ {
final Npc npc = entry.getKey(); final Npc npc = entry.getKey();
final List<Long> schedules = entry.getValue();
for (Long respawnTime : schedules)
{
if (time > respawnTime)
{
schedules.remove(respawnTime);
if (schedules.isEmpty())
{
PENDING_RESPAWNS.remove(npc); PENDING_RESPAWNS.remove(npc);
}
final Spawn spawn = npc.getSpawn(); final Spawn spawn = npc.getSpawn();
if (spawn != null) if (spawn != null)
{ {
@@ -59,17 +50,12 @@ public class RespawnTaskManager
} }
} }
} }
}
}, 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()