From 6de4ae247c03012df29183821e33bcd1fbcac785 Mon Sep 17 00:00:00 2001
From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com>
Date: Sat, 8 Jun 2019 00:24:13 +0000
Subject: [PATCH] Addition of RespawnTaskManager.
---
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../model/actor/instance/NpcInstance.java | 2 +-
.../gameserver/model/spawn/Spawn.java | 39 ++--------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
.../org/l2jmobius/gameserver/model/Spawn.java | 31 +-------
.../taskmanager/RespawnTaskManager.java | 78 +++++++++++++++++++
29 files changed, 1152 insertions(+), 384 deletions(-)
create mode 100644 L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
create mode 100644 L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/NpcInstance.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/NpcInstance.java
index 21e3bab978..69e5dc2053 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/NpcInstance.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/NpcInstance.java
@@ -3185,7 +3185,7 @@ public class NpcInstance extends Creature
// Decrease its spawn counter
if (_spawn != null)
{
- _spawn.decreaseCount(this);
+ _spawn.decreaseCount();
}
}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/spawn/Spawn.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/spawn/Spawn.java
index f80cdee1b8..2441ad892e 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/spawn/Spawn.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/spawn/Spawn.java
@@ -21,13 +21,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.datatables.sql.TerritoryTable;
import org.l2jmobius.gameserver.idfactory.IdFactory;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
import org.l2jmobius.gameserver.model.quest.Quest;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
import org.l2jmobius.gameserver.templates.creatures.NpcTemplate;
/**
@@ -47,7 +47,7 @@ public class Spawn
private int _location;
private int _maximumCount;
private int _currentCount;
- protected int _scheduledCount;
+ public int _scheduledCount;
private int _locX;
private int _locY;
private int _locZ;
@@ -61,36 +61,13 @@ public class Spawn
private NpcInstance _lastSpawn;
private static List _spawnListeners = new ArrayList<>();
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.warning(e.getMessage());
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
*
* Concept :
*
- * Each Spawn owns generic and static properties (ex : RewardExp, RewardSP, AggroRange...). All of those properties are stored in a different NpcTemplate for each type of Spawn. Each template is loaded once in the server cache memory (reduce memory use). When a new instance of Spawn is
- * created, server just create a link between the instance and the template. This link is stored in _template
+ * Each Spawn owns generic and static properties (ex : RewardExp, RewardSP, AggroRange...). All of those properties are stored in a different NpcTemplate for each type of Spawn. Each template is loaded once in the server cache memory (reduce memory use). When a new instance of Spawn is created,
+ * server just create a link between the instance and the template. This link is stored in _template
*
* Each NpcInstance is linked to a Spawn that manages its spawn and respawn (delay, location...). This link is stored in _spawn of the NpcInstance
*
@@ -369,10 +346,8 @@ public class Spawn
* Create a new SpawnTask to launch after the respawn Delay
*
* Caution : A respawn is possible ONLY if _doRespawn=True and _scheduledCount + _currentCount < _maximumCount
- *
- * @param oldNpc
*/
- public void decreaseCount(/* int npcId */final NpcInstance oldNpc)
+ public void decreaseCount()
{
// Decrease the current number of NpcInstance of this Spawn
_currentCount--;
@@ -383,8 +358,8 @@ public class Spawn
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), _respawnDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + _respawnDelay);
}
}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..40b1f36799
--- /dev/null
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.spawn.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/Spawn.java
index 159fe3c90d..3139cdf6c0 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -25,7 +25,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.datatables.NpcPersonalAIData;
@@ -38,6 +37,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.zone.ZoneId;
import org.l2jmobius.gameserver.model.zone.type.NpcSpawnTerritory;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -59,7 +59,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** Link to NPC spawn territory */
@@ -77,29 +77,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is random walk
private int _spawnTemplateId = 0;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -271,8 +248,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/Spawn.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/Spawn.java
index 33afd23e60..408ca7d357 100644
--- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/Spawn.java
+++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/Spawn.java
@@ -24,7 +24,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.Config;
-import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
@@ -35,6 +34,7 @@ import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
import org.l2jmobius.gameserver.model.interfaces.INamable;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.zone.ZoneId;
+import org.l2jmobius.gameserver.taskmanager.RespawnTaskManager;
/**
* This class manages the spawn and respawn of a group of NpcInstance that are in the same are and have the same type.
@@ -56,7 +56,7 @@ public class Spawn extends Location implements IIdentifiable, INamable
/** The current number of NpcInstance managed by this Spawn */
private int _currentCount;
/** The current number of SpawnTask in progress or stand by of this Spawn */
- protected int _scheduledCount;
+ public int _scheduledCount;
/** The identifier of the location area where NpcInstance can be spawned */
private int _locationId;
/** The spawn instance id */
@@ -73,29 +73,6 @@ public class Spawn extends Location implements IIdentifiable, INamable
private boolean _randomWalk = false; // Is no random walk
private NpcSpawnTemplate _spawnTemplate;
- /** The task launching the function doSpawn() */
- class SpawnTask implements Runnable
- {
- public SpawnTask()
- {
- }
-
- @Override
- public void run()
- {
- try
- {
- doSpawn();
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "", e);
- }
-
- _scheduledCount--;
- }
- }
-
/**
* Constructor of Spawn.
* Concept:
@@ -276,8 +253,8 @@ public class Spawn extends Location implements IIdentifiable, INamable
// Update the current number of SpawnTask in progress or stand by of this Spawn
_scheduledCount++;
- // Create a new SpawnTask to launch after the respawn Delay
- ThreadPool.schedule(new SpawnTask(), hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay);
+ // Schedule the next respawn.
+ RespawnTaskManager.getInstance().add(this, System.currentTimeMillis() + (hasRespawnRandom() ? Rnd.get(_respawnMinDelay, _respawnMaxDelay) : _respawnMinDelay));
}
}
diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
new file mode 100644
index 0000000000..f08215e11d
--- /dev/null
+++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/taskmanager/RespawnTaskManager.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.taskmanager;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.Spawn;
+
+/**
+ * @author Mobius
+ */
+public class RespawnTaskManager
+{
+ private static final Map> PENDING_RESPAWNS = new ConcurrentHashMap<>();
+
+ public RespawnTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ final long time = System.currentTimeMillis();
+ for (Entry> entry : PENDING_RESPAWNS.entrySet())
+ {
+ final Spawn spawn = entry.getKey();
+ for (Long respawnTime : entry.getValue())
+ {
+ if (time > respawnTime)
+ {
+ entry.getValue().remove(respawnTime);
+ spawn.doSpawn();
+ spawn._scheduledCount--;
+ }
+ }
+ if (entry.getValue().isEmpty())
+ {
+ PENDING_RESPAWNS.remove(spawn);
+ }
+ }
+ }, 0, 1000);
+ }
+
+ public void add(Spawn spawn, Long time)
+ {
+ if (!PENDING_RESPAWNS.containsKey(spawn))
+ {
+ PENDING_RESPAWNS.put(spawn, new CopyOnWriteArrayList<>());
+ }
+ PENDING_RESPAWNS.get(spawn).add(time);
+ }
+
+ public static RespawnTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final RespawnTaskManager INSTANCE = new RespawnTaskManager();
+ }
+}