From 9bbb4d0a8571a0aa9bf44d8b03dd41520728605f Mon Sep 17 00:00:00 2001
From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com>
Date: Tue, 2 Feb 2021 22:07:06 +0000
Subject: [PATCH] Addition of PvpFlagTaskManager.
---
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../gameserver/model/actor/Creature.java | 97 +------------------
.../model/actor/instance/PlayerInstance.java | 47 ++++++++-
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../gameserver/model/actor/Creature.java | 97 +------------------
.../model/actor/instance/PlayerInstance.java | 47 ++++++++-
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 22 +----
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 22 +----
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
.../model/actor/instance/PlayerInstance.java | 21 +---
.../model/actor/tasks/player/PvPFlagTask.java | 55 -----------
.../taskmanager/PvpFlagTaskManager.java | 86 ++++++++++++++++
63 files changed, 1957 insertions(+), 1583 deletions(-)
delete mode 100644 L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
create mode 100644 L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
create mode 100644 L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
delete mode 100644 L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
create mode 100644 L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index daf96bf57e..e43bb1cde7 100644
--- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -167,7 +167,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -343,6 +342,7 @@ import org.l2jmobius.gameserver.network.serverpackets.commission.ExResponseCommi
import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -791,8 +791,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -819,26 +817,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -14010,11 +14000,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index ed36641c86..57ab3a0dc1 100644
--- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -168,7 +168,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -345,6 +344,7 @@ import org.l2jmobius.gameserver.network.serverpackets.commission.ExResponseCommi
import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -793,8 +793,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -821,26 +819,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -14017,11 +14007,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index af3f20f60c..f3fcfe2fdb 100644
--- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -169,7 +169,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -347,6 +346,7 @@ import org.l2jmobius.gameserver.network.serverpackets.commission.ExResponseCommi
import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -795,8 +795,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -823,26 +821,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -14020,11 +14010,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 827e3eb651..5d3889fd48 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -167,7 +167,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -351,6 +350,7 @@ import org.l2jmobius.gameserver.network.serverpackets.monsterbook.ExMonsterBookC
import org.l2jmobius.gameserver.network.serverpackets.monsterbook.ExMonsterBookRewardIcon;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -800,8 +800,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -828,26 +826,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Monster Book variables
@@ -13992,11 +13982,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 93e4ed8326..7718d1b94a 100644
--- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -167,7 +167,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -349,6 +348,7 @@ import org.l2jmobius.gameserver.network.serverpackets.monsterbook.ExMonsterBookC
import org.l2jmobius.gameserver.network.serverpackets.monsterbook.ExMonsterBookRewardIcon;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -796,8 +796,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -824,26 +822,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Monster Book variables
@@ -13954,11 +13944,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 03aa295cd7..b8b196ef02 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -167,7 +167,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -349,6 +348,7 @@ import org.l2jmobius.gameserver.network.serverpackets.monsterbook.ExMonsterBookC
import org.l2jmobius.gameserver.network.serverpackets.monsterbook.ExMonsterBookRewardIcon;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -796,8 +796,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -824,26 +822,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Monster Book variables
@@ -13957,11 +13947,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index a45151ffc9..faa11e3243 100644
--- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -167,7 +167,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -349,6 +348,7 @@ import org.l2jmobius.gameserver.network.serverpackets.monsterbook.ExMonsterBookC
import org.l2jmobius.gameserver.network.serverpackets.monsterbook.ExMonsterBookRewardIcon;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -796,8 +796,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -824,26 +822,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Monster Book variables
@@ -13963,11 +13953,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index c02e10f3a0..6f9f9a3e1a 100644
--- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -170,7 +170,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -356,6 +355,7 @@ import org.l2jmobius.gameserver.network.serverpackets.monsterbook.ExMonsterBookR
import org.l2jmobius.gameserver.network.serverpackets.sessionzones.TimedHuntingZoneExit;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -803,8 +803,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -831,26 +829,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Monster Book variables
@@ -13971,11 +13961,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_timedHuntingZoneFinishTask != null) && !_timedHuntingZoneFinishTask.isDone() && !_timedHuntingZoneFinishTask.isCancelled())
{
_timedHuntingZoneFinishTask.cancel(false);
diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 8530f47067..0f88d4b2ac 100644
--- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -169,7 +169,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -350,6 +349,7 @@ import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.network.serverpackets.sessionzones.TimedHuntingZoneExit;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -797,8 +797,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -825,26 +823,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -14012,11 +14002,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_timedHuntingZoneFinishTask != null) && !_timedHuntingZoneFinishTask.isDone() && !_timedHuntingZoneFinishTask.isCancelled())
{
_timedHuntingZoneFinishTask.cancel(false);
diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 4cf46298ba..22153e61f5 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -2939,36 +2939,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
}
}
- /**
- * Task lauching the function stopPvPFlag().
- */
- class PvPFlag implements Runnable
- {
- @Override
- public void run()
- {
- // try
- // {
- if (System.currentTimeMillis() > _pvpFlagLasts)
- {
- stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_pvpFlagLasts - 5000))
- {
- updatePvPFlag(2);
- }
- else
- {
- updatePvPFlag(1);
- }
- // }
- // catch (Exception e)
- // {
- // LOGGER.warning("error in pvp flag task: " + e);
- // }
- }
- }
-
/** Map 32 bits (0x0000) containing all abnormal effect in progress. */
private int _AbnormalEffects;
@@ -8326,71 +8296,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
_castInterruptTime = newSkillCastEndTime - 12;
}
- /** The _ pvp reg task. */
- private Future> _PvPRegTask;
-
- /** The _pvp flag lasts. */
- long _pvpFlagLasts;
-
- /**
- * Sets the pvp flag lasts.
- * @param time the new pvp flag lasts
- */
- public void setPvpFlagLasts(long time)
- {
- _pvpFlagLasts = time;
- }
-
- /**
- * Gets the pvp flag lasts.
- * @return the pvp flag lasts
- */
- public long getPvpFlagLasts()
- {
- return _pvpFlagLasts;
- }
-
- /**
- * Start pvp flag.
- */
- public void startPvPFlag()
- {
- updatePvPFlag(1);
-
- _PvPRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlag(), 1000, 1000);
- }
-
- /**
- * Stop pvp reg task.
- */
- public void stopPvpRegTask()
- {
- if (_PvPRegTask != null)
- {
- _PvPRegTask.cancel(true);
- }
- }
-
- /**
- * Stop pvp flag.
- */
- public void stopPvPFlag()
- {
- stopPvpRegTask();
-
- updatePvPFlag(0);
-
- _PvPRegTask = null;
- }
-
- /**
- * Update pvp flag.
- * @param value the value
- */
- public void updatePvPFlag(int value)
- {
- }
-
/**
* Return a Random Damage in function of the weapon.
* @param target the target
@@ -8409,7 +8314,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
@Override
public String toString()
{
- return "mob " + getObjectId();
+ return "Creature " + getObjectId();
}
/**
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 9dd64f8af2..aacb93ca35 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -221,6 +221,7 @@ import org.l2jmobius.gameserver.network.serverpackets.TradeStart;
import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
import org.l2jmobius.gameserver.network.serverpackets.ValidateLocation;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.FloodProtectors;
import org.l2jmobius.gameserver.util.IllegalPlayerAction;
@@ -299,6 +300,7 @@ public class PlayerInstance extends Playable
private int _lastKill = 0;
private int _count = 0;
private byte _pvpFlag;
+ private long _pvpFlagLasts;
private byte _siegeState = 0;
private int _curWeightPenalty = 0;
private byte _zoneValidateCounter = 4;
@@ -1638,7 +1640,50 @@ public class PlayerInstance extends Playable
return _pvpFlag;
}
- @Override
+ /**
+ * Sets the pvp flag lasts.
+ * @param time the new pvp flag lasts
+ */
+ public void setPvpFlagLasts(long time)
+ {
+ _pvpFlagLasts = time;
+ }
+
+ /**
+ * Gets the pvp flag lasts.
+ * @return the pvp flag lasts
+ */
+ public long getPvpFlagLasts()
+ {
+ return _pvpFlagLasts;
+ }
+
+ /**
+ * Start pvp flag.
+ */
+ public void startPvPFlag()
+ {
+ updatePvPFlag(1);
+ PvpFlagTaskManager.getInstance().add(this);
+ }
+
+ /**
+ * Stop pvp reg task.
+ */
+ public void stopPvpRegTask()
+ {
+ PvpFlagTaskManager.getInstance().remove(this);
+ }
+
+ /**
+ * Stop pvp flag.
+ */
+ public void stopPvPFlag()
+ {
+ stopPvpRegTask();
+ updatePvPFlag(0);
+ }
+
public void updatePvPFlag(int value)
{
if (getPvpFlag() == value)
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..cb93b9ced7
--- /dev/null
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 5000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java
index a46c6c04e5..6a13b5b031 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -2982,36 +2982,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
}
}
- /**
- * Task lauching the function stopPvPFlag().
- */
- class PvPFlag implements Runnable
- {
- @Override
- public void run()
- {
- // try
- // {
- if (System.currentTimeMillis() > _pvpFlagLasts)
- {
- stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_pvpFlagLasts - 5000))
- {
- updatePvPFlag(2);
- }
- else
- {
- updatePvPFlag(1);
- }
- // }
- // catch (Exception e)
- // {
- // LOGGER.warning("error in pvp flag task: " + e);
- // }
- }
- }
-
/** Map 32 bits (0x0000) containing all abnormal effect in progress. */
private int _AbnormalEffects;
@@ -8373,71 +8343,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
_castInterruptTime = newSkillCastEndTime - 12;
}
- /** The _ pvp reg task. */
- private Future> _PvPRegTask;
-
- /** The _pvp flag lasts. */
- long _pvpFlagLasts;
-
- /**
- * Sets the pvp flag lasts.
- * @param time the new pvp flag lasts
- */
- public void setPvpFlagLasts(long time)
- {
- _pvpFlagLasts = time;
- }
-
- /**
- * Gets the pvp flag lasts.
- * @return the pvp flag lasts
- */
- public long getPvpFlagLasts()
- {
- return _pvpFlagLasts;
- }
-
- /**
- * Start pvp flag.
- */
- public void startPvPFlag()
- {
- updatePvPFlag(1);
-
- _PvPRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlag(), 1000, 1000);
- }
-
- /**
- * Stop pvp reg task.
- */
- public void stopPvpRegTask()
- {
- if (_PvPRegTask != null)
- {
- _PvPRegTask.cancel(true);
- }
- }
-
- /**
- * Stop pvp flag.
- */
- public void stopPvPFlag()
- {
- stopPvpRegTask();
-
- updatePvPFlag(0);
-
- _PvPRegTask = null;
- }
-
- /**
- * Update pvp flag.
- * @param value the value
- */
- public void updatePvPFlag(int value)
- {
- }
-
/**
* Return a Random Damage in function of the weapon.
* @param target the target
@@ -8456,7 +8361,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
@Override
public String toString()
{
- return "mob " + getObjectId();
+ return "Creature " + getObjectId();
}
/**
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 97110e0eaf..35c94c643d 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -229,6 +229,7 @@ import org.l2jmobius.gameserver.network.serverpackets.TradeStart;
import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
import org.l2jmobius.gameserver.network.serverpackets.ValidateLocation;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.FloodProtectors;
import org.l2jmobius.gameserver.util.IllegalPlayerAction;
@@ -307,6 +308,7 @@ public class PlayerInstance extends Playable
private int _lastKill = 0;
private int _count = 0;
private byte _pvpFlag;
+ private long _pvpFlagLasts;
private byte _siegeState = 0;
private int _curWeightPenalty = 0;
private int _lastCompassZone; // the last compass zone update send to the client
@@ -1652,7 +1654,50 @@ public class PlayerInstance extends Playable
return _pvpFlag;
}
- @Override
+ /**
+ * Sets the pvp flag lasts.
+ * @param time the new pvp flag lasts
+ */
+ public void setPvpFlagLasts(long time)
+ {
+ _pvpFlagLasts = time;
+ }
+
+ /**
+ * Gets the pvp flag lasts.
+ * @return the pvp flag lasts
+ */
+ public long getPvpFlagLasts()
+ {
+ return _pvpFlagLasts;
+ }
+
+ /**
+ * Start pvp flag.
+ */
+ public void startPvPFlag()
+ {
+ updatePvPFlag(1);
+ PvpFlagTaskManager.getInstance().add(this);
+ }
+
+ /**
+ * Stop pvp reg task.
+ */
+ public void stopPvpRegTask()
+ {
+ PvpFlagTaskManager.getInstance().remove(this);
+ }
+
+ /**
+ * Stop pvp flag.
+ */
+ public void stopPvPFlag()
+ {
+ stopPvpRegTask();
+ updatePvPFlag(0);
+ }
+
public void updatePvPFlag(int value)
{
if (getPvpFlag() == value)
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..cb93b9ced7
--- /dev/null
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 5000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 3b4c08e4ed..9baf658ade 100644
--- a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -161,7 +161,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.LookingForFishTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetSoulsTask;
@@ -322,6 +321,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
import org.l2jmobius.gameserver.network.serverpackets.ValidateLocation;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -796,8 +796,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -864,27 +862,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask == null)
- {
- return;
- }
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Character UI
@@ -14420,11 +14409,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 20270b4438..64cf2a0c5f 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -162,7 +162,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.LookingForFishTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoBonusTaskEnd;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
@@ -327,6 +326,7 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
import org.l2jmobius.gameserver.network.serverpackets.ValidateLocation;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -815,8 +815,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -883,27 +881,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask == null)
- {
- return;
- }
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Character UI
@@ -14514,11 +14503,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 00094b633a..93bca978d7 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -167,7 +167,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -343,6 +342,7 @@ import org.l2jmobius.gameserver.network.serverpackets.commission.ExResponseCommi
import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -786,8 +786,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -814,26 +812,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -13766,11 +13756,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index dd7fbd8474..3964eb6a82 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -167,7 +167,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -343,6 +342,7 @@ import org.l2jmobius.gameserver.network.serverpackets.commission.ExResponseCommi
import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -786,8 +786,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -814,26 +812,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -13766,11 +13756,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index b1961233c9..49c387063a 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -167,7 +167,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -341,6 +340,7 @@ import org.l2jmobius.gameserver.network.serverpackets.commission.ExResponseCommi
import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -784,8 +784,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -812,26 +810,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -13751,11 +13741,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 34da11ff09..181e135d37 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -170,7 +170,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -345,6 +344,7 @@ import org.l2jmobius.gameserver.network.serverpackets.commission.ExResponseCommi
import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -791,8 +791,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -819,26 +817,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -13800,11 +13790,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 927a2a88e6..40d8a67906 100644
--- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -170,7 +170,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -345,6 +344,7 @@ import org.l2jmobius.gameserver.network.serverpackets.commission.ExResponseCommi
import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -791,8 +791,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -819,26 +817,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -13800,11 +13790,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 459c4310cc..e886cbb686 100644
--- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -173,7 +173,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -353,6 +352,7 @@ import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.network.serverpackets.sessionzones.TimedHuntingZoneExit;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -799,8 +799,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -827,26 +825,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -13778,11 +13768,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_timedHuntingZoneFinishTask != null) && !_timedHuntingZoneFinishTask.isDone() && !_timedHuntingZoneFinishTask.isCancelled())
{
_timedHuntingZoneFinishTask.cancel(false);
diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index d594b1d746..8571bc1571 100644
--- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -167,7 +167,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -343,6 +342,7 @@ import org.l2jmobius.gameserver.network.serverpackets.commission.ExResponseCommi
import org.l2jmobius.gameserver.network.serverpackets.friend.FriendStatus;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -788,8 +788,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -816,26 +814,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -13787,11 +13777,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_taskWarnUserTakeBreak != null) && !_taskWarnUserTakeBreak.isDone() && !_taskWarnUserTakeBreak.isCancelled())
{
_taskWarnUserTakeBreak.cancel(false);
diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}
diff --git a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 9fe28e305c..d8c19f06ba 100644
--- a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -173,7 +173,6 @@ import org.l2jmobius.gameserver.model.actor.tasks.player.FameTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.HennaDurationTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.InventoryEnableTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.PetFeedTask;
-import org.l2jmobius.gameserver.model.actor.tasks.player.PvPFlagTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RecoGiveTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.RentPetTask;
import org.l2jmobius.gameserver.model.actor.tasks.player.ResetChargesTask;
@@ -358,6 +357,7 @@ import org.l2jmobius.gameserver.network.serverpackets.limitshop.ExBloodyCoinCoun
import org.l2jmobius.gameserver.network.serverpackets.sessionzones.TimedHuntingZoneExit;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
+import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
import org.l2jmobius.gameserver.util.Broadcast;
import org.l2jmobius.gameserver.util.EnumIntBitmask;
import org.l2jmobius.gameserver.util.FloodProtectors;
@@ -813,8 +813,6 @@ public class PlayerInstance extends Playable
private volatile long _lastItemAuctionInfoRequest = 0;
- private Future> _pvpRegTask;
-
private long _pvpFlagLasts;
private long _notMoveUntil = 0;
@@ -841,26 +839,18 @@ public class PlayerInstance extends Playable
public void startPvPFlag()
{
updatePvPFlag(1);
- if (_pvpRegTask == null)
- {
- _pvpRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlagTask(this), 1000, 1000);
- }
+ PvpFlagTaskManager.getInstance().add(this);
}
public void stopPvpRegTask()
{
- if (_pvpRegTask != null)
- {
- _pvpRegTask.cancel(true);
- _pvpRegTask = null;
- }
+ PvpFlagTaskManager.getInstance().remove(this);
}
public void stopPvPFlag()
{
stopPvpRegTask();
updatePvPFlag(0);
- _pvpRegTask = null;
}
// Training Camp
@@ -13969,11 +13959,6 @@ public class PlayerInstance extends Playable
_fallingDamageTask.cancel(false);
_fallingDamageTask = null;
}
- if ((_pvpRegTask != null) && !_pvpRegTask.isDone() && !_pvpRegTask.isCancelled())
- {
- _pvpRegTask.cancel(false);
- _pvpRegTask = null;
- }
if ((_timedHuntingZoneFinishTask != null) && !_timedHuntingZoneFinishTask.isDone() && !_timedHuntingZoneFinishTask.isCancelled())
{
_timedHuntingZoneFinishTask.cancel(false);
diff --git a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
deleted file mode 100644
index 52a327acca..0000000000
--- a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/actor/tasks/player/PvPFlagTask.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.model.actor.tasks.player;
-
-import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
-
-/**
- * Task dedicated to update player's current pvp status.
- * @author UnAfraid
- */
-public class PvPFlagTask implements Runnable
-{
- private final PlayerInstance _player;
-
- public PvPFlagTask(PlayerInstance player)
- {
- _player = player;
- }
-
- @Override
- public void run()
- {
- if (_player == null)
- {
- return;
- }
-
- if (System.currentTimeMillis() > _player.getPvpFlagLasts())
- {
- _player.stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (_player.getPvpFlagLasts() - 20000))
- {
- _player.updatePvPFlag(2);
- }
- else
- {
- _player.updatePvPFlag(1);
- }
- }
-}
\ No newline at end of file
diff --git a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
new file mode 100644
index 0000000000..6a406a9591
--- /dev/null
+++ b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/taskmanager/PvpFlagTaskManager.java
@@ -0,0 +1,86 @@
+/*
+ * 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.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.l2jmobius.commons.concurrent.ThreadPool;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+
+/**
+ * @author Mobius
+ */
+public class PvpFlagTaskManager
+{
+ private static final Set PLAYERS = ConcurrentHashMap.newKeySet();
+ private static boolean _working = false;
+
+ public PvpFlagTaskManager()
+ {
+ ThreadPool.scheduleAtFixedRate(() ->
+ {
+ if (_working)
+ {
+ return;
+ }
+ _working = true;
+
+ if (!PLAYERS.isEmpty())
+ {
+ final long time = System.currentTimeMillis();
+ for (PlayerInstance player : PLAYERS)
+ {
+ if (time > player.getPvpFlagLasts())
+ {
+ player.stopPvPFlag();
+ }
+ else if (time > (player.getPvpFlagLasts() - 20000))
+ {
+ player.updatePvPFlag(2);
+ }
+ else
+ {
+ player.updatePvPFlag(1);
+ }
+ }
+ }
+
+ _working = false;
+ }, 1000, 1000);
+ }
+
+ public void add(PlayerInstance player)
+ {
+ PLAYERS.add(player);
+ }
+
+ public void remove(PlayerInstance player)
+ {
+ PLAYERS.remove(player);
+ }
+
+ public static PvpFlagTaskManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
+ }
+}