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
HappyLDE
Posts: 123 Joined: Tue Sep 10, 2013 6:22 pm
Location: Belgium
Contact:
Post
by HappyLDE » Fri Nov 14, 2014 3:07 pm
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!
"
If you believe you will fail or succeed, in both ways you are right. " - Henry Ford
UnAfraid
L2j Veteran
Posts: 4199 Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:
Post
by UnAfraid » Fri Nov 14, 2014 3:58 pm
Map<Integer, BuffInfo> buffs = activeChar.getEffectList().getBuffs();
its not a copy its reference
HappyLDE
Posts: 123 Joined: Tue Sep 10, 2013 6:22 pm
Location: Belgium
Contact:
Post
by HappyLDE » Fri Nov 14, 2014 4:03 pm
How to make a copy instead of references? Thank you very much for answer
Thank you for making L2JServer happen!
"
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
Post
by Starter » Fri Nov 14, 2014 4:50 pm
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.
UnAfraid
L2j Veteran
Posts: 4199 Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:
Post
by UnAfraid » Fri Nov 14, 2014 4:52 pm
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());
Starter
Posts: 484 Joined: Sat Jan 23, 2010 4:42 pm
Post
by Starter » Fri Nov 14, 2014 4:54 pm
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.
UnAfraid
L2j Veteran
Posts: 4199 Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:
Post
by UnAfraid » Fri Nov 14, 2014 4:55 pm
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
Starter
Posts: 484 Joined: Sat Jan 23, 2010 4:42 pm
Post
by Starter » Fri Nov 14, 2014 6:35 pm
Cant, I have a ban allergy.
I have promises to keep and miles to go before I sleep.
HappyLDE
Posts: 123 Joined: Tue Sep 10, 2013 6:22 pm
Location: Belgium
Contact:
Post
by HappyLDE » Fri Nov 14, 2014 8:49 pm
Thank you guys that did it and now works!!
Thank you for making L2JServer happen!
"
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
Post
by Starter » Fri Nov 14, 2014 9:01 pm
HappyLDE wrote: Thank you guys that did it and now works!!
like
I have promises to keep and miles to go before I sleep.
HappyLDE
Posts: 123 Joined: Tue Sep 10, 2013 6:22 pm
Location: Belgium
Contact:
Post
by HappyLDE » Fri Nov 14, 2014 9:37 pm
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!
"
If you believe you will fail or succeed, in both ways you are right. " - Henry Ford
Zoey76
L2j Inner Circle
Posts: 7008 Joined: Tue Aug 11, 2009 3:36 am
Post
by Zoey76 » Sat Nov 15, 2014 1:16 am
Check StealAbnormal, that's a perfect example.