Addition of PvpFlagTaskManager.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<PlayerInstance> 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user