diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java index 137dfaade4..91dbb0372a 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5412,4 +5418,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java index 137dfaade4..91dbb0372a 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5412,4 +5418,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java index 137dfaade4..91dbb0372a 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5412,4 +5418,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java index 137dfaade4..91dbb0372a 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5412,4 +5418,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java index 137dfaade4..91dbb0372a 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5412,4 +5418,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java index 137dfaade4..91dbb0372a 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5412,4 +5418,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java index f7f77447d8..639572137a 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5412,4 +5418,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java index c0edf55723..20c01cab60 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.StampedLock; import java.util.logging.Level; @@ -114,6 +115,7 @@ import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; import org.l2jmobius.gameserver.model.skills.AbnormalVisualEffect; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.CommonSkill; import org.l2jmobius.gameserver.model.skills.EffectScope; @@ -243,6 +245,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + /** Map 32 bits, containing all abnormal visual effects in progress. */ private int _abnormalVisualEffects; /** Map 32 bits, containing all special abnormal visual effects in progress. */ @@ -2439,6 +2443,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe getAI().stopAITask(); } + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -6741,4 +6748,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index 5afc193c28..2bf3d2bcde 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -52,8 +52,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks = new ConcurrentHashMap<>(); - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -227,11 +225,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -253,7 +248,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } boolean update = false; @@ -463,6 +458,6 @@ public final class BuffInfo @Override public String toString() { - return "BuffInfo [effector=" + _effector + ", effected=" + _effected + ", skill=" + _skill + ", effects=" + _effects + ", tasks=" + _tasks + ", scheduledFutureTimeTask=" + _scheduledFutureTimeTask + ", abnormalTime=" + _abnormalTime + ", periodStartTicks=" + _periodStartTicks + ", isRemoved=" + _isRemoved + ", isInUse=" + _isInUse + "]"; + return "BuffInfo [effector=" + _effector + ", effected=" + _effected + ", skill=" + _skill + ", effects=" + _effects + ", tasks=" + _tasks + ", abnormalTime=" + _abnormalTime + ", periodStartTicks=" + _periodStartTicks + ", isRemoved=" + _isRemoved + ", isInUse=" + _isInUse + "]"; } } \ No newline at end of file diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 27e16a0cbc..0000000000 --- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java index cc4b4afe35..6e35d9299d 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5411,4 +5417,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java index cc4b4afe35..6e35d9299d 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5411,4 +5417,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java index cc4b4afe35..6e35d9299d 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5411,4 +5417,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java index cc4b4afe35..6e35d9299d 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5411,4 +5417,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -} diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java index cc4b4afe35..6e35d9299d 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java @@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.options.OptionsSkillHolder; import org.l2jmobius.gameserver.model.options.OptionsSkillType; import org.l2jmobius.gameserver.model.skills.AbnormalType; +import org.l2jmobius.gameserver.model.skills.BuffFinishTask; import org.l2jmobius.gameserver.model.skills.BuffInfo; import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.SkillCaster; @@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe private SkillChannelized _channelized = null; + private BuffFinishTask _buffFinishTask = null; + private Optional _transform = Optional.empty(); /** Movement data of this Creature */ @@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe // Cancel all timers related to this Creature TimersManager.getInstance().cancelTimers(getObjectId()); + // Cancel the BuffFinishTask related to this creature. + cancelBuffFinishTask(); + // Set world region to null. setWorldRegion(null); @@ -5411,4 +5417,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe { return _fakePlayerDrops; } + + public void addBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask == null) + { + _buffFinishTask = new BuffFinishTask(); + } + _buffFinishTask.addBuffInfo(info); + } + + public void removeBuffInfoTime(BuffInfo info) + { + if (_buffFinishTask != null) + { + _buffFinishTask.removeBuffInfo(info); + } + } + + public void cancelBuffFinishTask() + { + if (_buffFinishTask != null) + { + final ScheduledFuture task = _buffFinishTask.getTask(); + if ((task != null) && !task.isCancelled() && !task.isDone()) + { + task.cancel(true); + } + _buffFinishTask = null; + } + } } diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java new file mode 100644 index 0000000000..79a1c5dfb3 --- /dev/null +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/skills/BuffFinishTask.java @@ -0,0 +1,59 @@ +/* + * 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.skills; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicInteger; + +import org.l2jmobius.commons.concurrent.ThreadPool; + +/** + * @author Mobius + */ +public class BuffFinishTask +{ + private final Map _buffInfos = new ConcurrentHashMap<>(); + private final ScheduledFuture _task = ThreadPool.scheduleAtFixedRate(() -> + { + for (Entry entry : _buffInfos.entrySet()) + { + final BuffInfo info = entry.getKey(); + if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime())) + { + info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId()); + } + } + }, 0, 1000); + + public ScheduledFuture getTask() + { + return _task; + } + + public void addBuffInfo(BuffInfo info) + { + _buffInfos.put(info, new AtomicInteger()); + } + + public void removeBuffInfo(BuffInfo info) + { + _buffInfos.remove(info); + } +} diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java index c7c8e7ebd7..7ebc6bef2c 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -55,8 +55,6 @@ public final class BuffInfo // Tasks /** Effect tasks for ticks. */ private volatile Map _tasks; - /** Scheduled future. */ - private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks /** Abnormal time. */ private int _abnormalTime; @@ -296,11 +294,8 @@ public final class BuffInfo public void stopAllEffects(boolean removed) { setRemoved(removed); - // Cancels the task that will end this buff info - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } + // Remove this buff info from BuffFinishTask. + _effected.removeBuffInfoTime(this); finishEffects(); } @@ -322,7 +317,7 @@ public final class BuffInfo // Creates a task that will stop all the effects. if (_abnormalTime > 0) { - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.addBuffInfoTime(this); } for (AbstractEffect effect : _effects) @@ -453,11 +448,8 @@ public final class BuffInfo { _periodStartTicks = GameTimeController.getInstance().getGameTicks(); _abnormalTime = abnormalTime; - if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled()) - { - _scheduledFutureTimeTask.cancel(true); - } - _scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000); + _effected.removeBuffInfoTime(this); + _effected.addBuffInfoTime(this); } } diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java deleted file mode 100644 index 5b93ee4045..0000000000 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/skills/BuffTimeTask.java +++ /dev/null @@ -1,56 +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.skills; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Effect time task finish the effect when the abnormal time is reached. - * @author Zoey76 - */ -public class BuffTimeTask implements Runnable -{ - private final AtomicInteger _time = new AtomicInteger(); - private final BuffInfo _info; - - /** - * EffectTimeTask constructor. - * @param info the buff info - */ - public BuffTimeTask(BuffInfo info) - { - _info = info; - } - - /** - * Gets the elapsed time. - * @return the tick count - */ - public int getElapsedTime() - { - return _time.get(); - } - - @Override - public void run() - { - if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime())) - { - _info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId()); - } - } -}