Saving Player buffs to give them later

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
HappyLDE
Posts: 123
Joined: Tue Sep 10, 2013 6:22 pm
Location: Belgium
Contact:

Saving Player buffs to give them later

Post by HappyLDE »

Hello i want to store the character buffs and when needed give them back:

Code: Select all

Map<Integer, BuffInfo> buffs = activeChar.getEffectList().getBuffs();            activeChar.sendMessage("buffs count "+buffs.size());                        activeChar.stopAllEffects();                        activeChar.sendMessage("buffs count "+buffs.size());             for (Entry<Integer, BuffInfo> entry : buffs.entrySet())            {                try                {                    SkillData.getInstance().getSkill(entry.getValue().getSkill().getId(), entry.getValue().getSkill().getLevel()).applyEffects(activeChar, activeChar);                } catch (RuntimeException e) { }            }
But after stopAllEffects(), buffs.size() gets to zero, therefore no buffs in my list to give back, what should i do?
Thank you for making L2JServer happen! :D
"If you believe you will fail or succeed, in both ways you are right." - Henry Ford
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Saving Player buffs to give them later

Post by UnAfraid »

Map<Integer, BuffInfo> buffs = activeChar.getEffectList().getBuffs();
its not a copy its reference
Image
User avatar
HappyLDE
Posts: 123
Joined: Tue Sep 10, 2013 6:22 pm
Location: Belgium
Contact:

Re: Saving Player buffs to give them later

Post by HappyLDE »

How to make a copy instead of references? Thank you very much for answer :D
Thank you for making L2JServer happen! :D
"If you believe you will fail or succeed, in both ways you are right." - Henry Ford
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Saving Player buffs to give them later

Post by Starter »

Add player buffs to a list like this:

Code: Select all

        for (L2Effect effect : playerInstance.getAllEffects())        {            if (effect == null)                continue;                        playerInstance._buffs.addIfAbsent(effect);        } 
?
I have promises to keep and miles to go before I sleep.
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Saving Player buffs to give them later

Post by UnAfraid »

Starter wrote:Add player buffs to a list like this:

Code: Select all

        for (L2Effect effect : playerInstance.getAllEffects())        {            if (effect == null)                continue;                        playerInstance._buffs.addIfAbsent(effect);        } 
?
Hell no!
If you need it a list: List<BuffInfo> buffs = new ArrayList<>(activeChar.getEffectList().getBuffs().values());
if you need it as map: Map<Integer, BuffInfo> buffs = new HashMap<>(activeChar.getEffectList().getBuffs());
Image
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Saving Player buffs to give them later

Post by Starter »

UnAfraid wrote:
Starter wrote:Add player buffs to a list like this:

Code: Select all

        for (L2Effect effect : playerInstance.getAllEffects())        {            if (effect == null)                continue;                        playerInstance._buffs.addIfAbsent(effect);        } 
?
Hell no!
List<BuffInfo> buffs = new ArrayList<>(activeChar.getEffectList().getBuffs().values());
What about:

public final CopyOnWriteArrayList<L2Effect> _buffs = new CopyOnWriteArrayList<L2Effect>();

Added in l2pcinstance. Dont remember atm why I did it that way in the past but I think it was the best solution avoiding several bad situations.
Last edited by Starter on Fri Nov 14, 2014 4:57 pm, edited 1 time in total.
I have promises to keep and miles to go before I sleep.
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Saving Player buffs to give them later

Post by UnAfraid »

Not needed to be thread safe since hes going to use it right away.
BTW xban1x made an effect that restores canceled effects after some time u may want to check it
Image
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Saving Player buffs to give them later

Post by Starter »

Cant, I have a ban allergy.
I have promises to keep and miles to go before I sleep.
User avatar
HappyLDE
Posts: 123
Joined: Tue Sep 10, 2013 6:22 pm
Location: Belgium
Contact:

Re: Saving Player buffs to give them later

Post by HappyLDE »

Thank you guys that did it and now works!! :D
Thank you for making L2JServer happen! :D
"If you believe you will fail or succeed, in both ways you are right." - Henry Ford
Starter
Posts: 484
Joined: Sat Jan 23, 2010 4:42 pm

Re: Saving Player buffs to give them later

Post by Starter »

HappyLDE wrote:Thank you guys that did it and now works!! :D
like
I have promises to keep and miles to go before I sleep.
User avatar
HappyLDE
Posts: 123
Joined: Tue Sep 10, 2013 6:22 pm
Location: Belgium
Contact:

Re: Saving Player buffs to give them later

Post by HappyLDE »

UnAfraid wrote:Not needed to be thread safe since hes going to use it right away.
BTW xban1x made an effect that restores canceled effects after some time u may want to check it
What if i don't give them back right away but in 10 hours, is that bad?
Thank you for making L2JServer happen! :D
"If you believe you will fail or succeed, in both ways you are right." - Henry Ford
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7008
Joined: Tue Aug 11, 2009 3:36 am

Re: Saving Player buffs to give them later

Post by Zoey76 »

Check StealAbnormal, that's a perfect example. :wink:
Powered by Eclipse 4.34 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
Post Reply