Removal of func result conversions to arrays.

This commit is contained in:
MobiusDevelopment
2021-04-21 21:37:09 +00:00
parent fc1e82d451
commit 7fe7f49ab3
15 changed files with 179 additions and 221 deletions

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model; package org.l2jmobius.gameserver.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -104,8 +105,6 @@ public abstract class Effect
NEGATE NEGATE
} }
private static final Func[] _emptyFunctionSet = new Func[0];
// member _effector is the instance of Creature that cast/used the spell/skill that is causing this effect. Do not confuse with the instance of Creature that is being affected by this effect. // member _effector is the instance of Creature that cast/used the spell/skill that is causing this effect. Do not confuse with the instance of Creature that is being affected by this effect.
private final Creature _effector; private final Creature _effector;
@@ -538,12 +537,13 @@ public abstract class Effect
} }
} }
public Func[] getStatFuncs() public List<Func> getStatFuncs()
{ {
if (_funcTemplates == null) if (_funcTemplates == null)
{ {
return _emptyFunctionSet; return Collections.emptyList();
} }
final List<Func> funcs = new ArrayList<>(); final List<Func> funcs = new ArrayList<>();
for (FuncTemplate t : _funcTemplates) for (FuncTemplate t : _funcTemplates)
{ {
@@ -557,11 +557,8 @@ public abstract class Effect
funcs.add(f); funcs.add(f);
} }
} }
if (funcs.isEmpty())
{ return funcs;
return _emptyFunctionSet;
}
return funcs.toArray(new Func[funcs.size()]);
} }
public void addIcon(MagicEffectIcons mi) public void addIcon(MagicEffectIcons mi)

View File

@@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -380,9 +381,6 @@ public abstract class Skill
public static final int COND_GRADED = 0x080000; public static final int COND_GRADED = 0x080000;
public static final int COND_GRADES = 0x100000; public static final int COND_GRADES = 0x100000;
private static final Func[] _emptyFunctionSet = new Func[0];
private static final Effect[] _emptyEffectSet = new Effect[0];
// these two build the primary key // these two build the primary key
private final int _id; private final int _id;
private final int _level; private final int _level;
@@ -2611,16 +2609,16 @@ public abstract class Skill
return targets.get(0); return targets.get(0);
} }
public Func[] getStatFuncs(Effect effect, Creature creature) public List<Func> getStatFuncs(Effect effect, Creature creature)
{ {
if (!(creature instanceof PlayerInstance) && !(creature instanceof Attackable) && !(creature instanceof Summon)) if (!(creature instanceof PlayerInstance) && !(creature instanceof Attackable) && !(creature instanceof Summon))
{ {
return _emptyFunctionSet; return Collections.emptyList();
} }
if (_funcTemplates == null) if (_funcTemplates == null)
{ {
return _emptyFunctionSet; return Collections.emptyList();
} }
final List<Func> funcs = new ArrayList<>(); final List<Func> funcs = new ArrayList<>();
@@ -2635,12 +2633,8 @@ public abstract class Skill
funcs.add(f); funcs.add(f);
} }
} }
if (funcs.isEmpty())
{
return _emptyFunctionSet;
}
return funcs.toArray(new Func[funcs.size()]); return funcs;
} }
public boolean hasEffects() public boolean hasEffects()
@@ -2648,31 +2642,31 @@ public abstract class Skill
return (_effectTemplates != null) && (_effectTemplates.length > 0); return (_effectTemplates != null) && (_effectTemplates.length > 0);
} }
public Effect[] applyEffects(Creature effector, Creature effected) public List<Effect> applyEffects(Creature effector, Creature effected)
{ {
return applyEffects(effector, effected, false, false, false); return applyEffects(effector, effected, false, false, false);
} }
public Effect[] applyEffects(Creature effector, Creature effected, boolean ss, boolean sps, boolean bss) public List<Effect> applyEffects(Creature effector, Creature effected, boolean ss, boolean sps, boolean bss)
{ {
if (isPassive()) if (isPassive())
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
if (_effectTemplates == null) if (_effectTemplates == null)
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
if ((effector != effected) && effected.isInvul()) if ((effector != effected) && effected.isInvul())
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
if ((_skillType == SkillType.BUFF) && effected.isBlockBuff()) if ((_skillType == SkillType.BUFF) && effected.isBlockBuff())
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
final List<Effect> effects = new ArrayList<>(); final List<Effect> effects = new ArrayList<>();
@@ -2706,24 +2700,19 @@ public abstract class Skill
} }
} }
if (effects.isEmpty()) return effects;
{
return _emptyEffectSet;
} }
return effects.toArray(new Effect[effects.size()]); public List<Effect> applySelfEffects(Creature effector)
}
public Effect[] applySelfEffects(Creature effector)
{ {
if (isPassive()) if (isPassive())
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
if (_effectTemplatesSelf == null) if (_effectTemplatesSelf == null)
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
final List<Effect> effects = new ArrayList<>(); final List<Effect> effects = new ArrayList<>();
@@ -2767,12 +2756,8 @@ public abstract class Skill
} }
} }
} }
if (effects.isEmpty())
{
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]); return effects;
} }
public void attach(FuncTemplate f) public void attach(FuncTemplate f)

View File

@@ -4447,7 +4447,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
* <li>Use an active skill</li><br> * <li>Use an active skill</li><br>
* @param funcs The list of Func objects to add to the Calculator corresponding to the state affected * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
*/ */
public synchronized void addStatFuncs(Func[] funcs) public synchronized void addStatFuncs(List<Func> funcs)
{ {
final List<Stat> modifiedStats = new ArrayList<>(); final List<Stat> modifiedStats = new ArrayList<>();
for (Func f : funcs) for (Func f : funcs)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model.items; package org.l2jmobius.gameserver.model.items;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.l2jmobius.gameserver.data.SkillTable; import org.l2jmobius.gameserver.data.SkillTable;
@@ -147,14 +148,17 @@ public class Armor extends Item
* Returns array of Func objects containing the list of functions used by the armor * Returns array of Func objects containing the list of functions used by the armor
* @param instance : ItemInstance pointing out the armor * @param instance : ItemInstance pointing out the armor
* @param creature : Creature pointing out the player * @param creature : Creature pointing out the player
* @return Func[] : array of functions * @return List<Func> : List of functions
*/ */
@Override @Override
public Func[] getStatFuncs(ItemInstance instance, Creature creature) public List<Func> getStatFuncs(ItemInstance instance, Creature creature)
{ {
if (_funcTemplates == null)
{
return Collections.emptyList();
}
final List<Func> funcs = new ArrayList<>(); final List<Func> funcs = new ArrayList<>();
if (_funcTemplates != null)
{
for (FuncTemplate t : _funcTemplates) for (FuncTemplate t : _funcTemplates)
{ {
final Env env = new Env(); final Env env = new Env();
@@ -166,7 +170,7 @@ public class Armor extends Item
funcs.add(f); funcs.add(f);
} }
} }
}
return funcs.toArray(new Func[funcs.size()]); return funcs;
} }
} }

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model.items; package org.l2jmobius.gameserver.model.items;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.l2jmobius.Config; import org.l2jmobius.Config;
@@ -140,9 +141,6 @@ public abstract class Item
protected EffectTemplate[] _effectTemplates; protected EffectTemplate[] _effectTemplates;
protected Skill[] _skills; protected Skill[] _skills;
private static final Func[] _emptyFunctionSet = new Func[0];
protected static final Effect[] _emptyEffectSet = new Effect[0];
/** /**
* Constructor of the Item that fill class variables.<br> * Constructor of the Item that fill class variables.<br>
* <u><i>Variables filled :</i></u><br> * <u><i>Variables filled :</i></u><br>
@@ -507,14 +505,15 @@ public abstract class Item
* Returns array of Func objects containing the list of functions used by the item * Returns array of Func objects containing the list of functions used by the item
* @param instance : ItemInstance pointing out the item * @param instance : ItemInstance pointing out the item
* @param creature : Creature pointing out the player * @param creature : Creature pointing out the player
* @return Func[] : array of functions * @return List<Func> : List of functions
*/ */
public Func[] getStatFuncs(ItemInstance instance, Creature creature) public List<Func> getStatFuncs(ItemInstance instance, Creature creature)
{ {
if (_funcTemplates == null) if (_funcTemplates == null)
{ {
return _emptyFunctionSet; return Collections.emptyList();
} }
final List<Func> funcs = new ArrayList<>(); final List<Func> funcs = new ArrayList<>();
for (FuncTemplate t : _funcTemplates) for (FuncTemplate t : _funcTemplates)
{ {
@@ -528,25 +527,23 @@ public abstract class Item
funcs.add(f); funcs.add(f);
} }
} }
if (funcs.isEmpty())
{ return funcs;
return _emptyFunctionSet;
}
return funcs.toArray(new Func[funcs.size()]);
} }
/** /**
* Returns the effects associated with the item. * Returns the effects associated with the item.
* @param instance : ItemInstance pointing out the item * @param instance : ItemInstance pointing out the item
* @param creature : Creature pointing out the player * @param creature : Creature pointing out the player
* @return Effect[] : array of effects generated by the item * @return List<Effect> : List of effects generated by the item
*/ */
public Effect[] getEffects(ItemInstance instance, Creature creature) public List<Effect> getEffects(ItemInstance instance, Creature creature)
{ {
if (_effectTemplates == null) if (_effectTemplates == null)
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
final List<Effect> effects = new ArrayList<>(); final List<Effect> effects = new ArrayList<>();
for (EffectTemplate et : _effectTemplates) for (EffectTemplate et : _effectTemplates)
{ {
@@ -560,25 +557,23 @@ public abstract class Item
effects.add(e); effects.add(e);
} }
} }
if (effects.isEmpty())
{ return effects;
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
} }
/** /**
* Returns effects of skills associated with the item. * Returns effects of skills associated with the item.
* @param caster : Creature pointing out the caster * @param caster : Creature pointing out the caster
* @param target : Creature pointing out the target * @param target : Creature pointing out the target
* @return Effect[] : array of effects generated by the skill * @return List<Effect> : List of effects generated by the skill
*/ */
public Effect[] getSkillEffects(Creature caster, Creature target) public List<Effect> getSkillEffects(Creature caster, Creature target)
{ {
if (_skills == null) if (_skills == null)
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
final List<Effect> effects = new ArrayList<>(); final List<Effect> effects = new ArrayList<>();
for (Skill skill : _skills) for (Skill skill : _skills)
{ {
@@ -596,11 +591,8 @@ public abstract class Item
effects.add(e); effects.add(e);
} }
} }
if (effects.isEmpty())
{ return effects;
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
} }
/** /**

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model.items; package org.l2jmobius.gameserver.model.items;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.l2jmobius.gameserver.data.SkillTable; import org.l2jmobius.gameserver.data.SkillTable;
@@ -290,14 +291,17 @@ public class Weapon extends Item
* Returns array of Func objects containing the list of functions used by the weapon * Returns array of Func objects containing the list of functions used by the weapon
* @param instance : ItemInstance pointing out the weapon * @param instance : ItemInstance pointing out the weapon
* @param creature : Creature pointing out the player * @param creature : Creature pointing out the player
* @return Func[] : array of functions * @return List<Func> : List of functions
*/ */
@Override @Override
public Func[] getStatFuncs(ItemInstance instance, Creature creature) public List<Func> getStatFuncs(ItemInstance instance, Creature creature)
{ {
if (_funcTemplates == null)
{
return Collections.emptyList();
}
final List<Func> funcs = new ArrayList<>(); final List<Func> funcs = new ArrayList<>();
if (_funcTemplates != null)
{
for (FuncTemplate t : _funcTemplates) for (FuncTemplate t : _funcTemplates)
{ {
final Env env = new Env(); final Env env = new Env();
@@ -309,8 +313,8 @@ public class Weapon extends Item
funcs.add(f); funcs.add(f);
} }
} }
}
return funcs.toArray(new Func[funcs.size()]); return funcs;
} }
/** /**
@@ -318,14 +322,15 @@ public class Weapon extends Item
* @param caster : Creature pointing out the caster * @param caster : Creature pointing out the caster
* @param target : Creature pointing out the target * @param target : Creature pointing out the target
* @param crit : boolean tells whether the hit was critical * @param crit : boolean tells whether the hit was critical
* @return Effect[] : array of effects generated by the skill * @return List<Effect> : List of effects generated by the skill
*/ */
public Effect[] getSkillEffects(Creature caster, Creature target, boolean crit) public List<Effect> getSkillEffects(Creature caster, Creature target, boolean crit)
{ {
if ((_skillsOnCrit == null) || !crit) if ((_skillsOnCrit == null) || !crit)
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
final List<Effect> effects = new ArrayList<>(); final List<Effect> effects = new ArrayList<>();
for (Skill skill : _skillsOnCrit) for (Skill skill : _skillsOnCrit)
{ {
@@ -348,11 +353,8 @@ public class Weapon extends Item
effects.add(e); effects.add(e);
} }
} }
if (effects.isEmpty())
{ return effects;
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
} }
/** /**
@@ -360,7 +362,7 @@ public class Weapon extends Item
* @param caster : Creature pointing out the caster * @param caster : Creature pointing out the caster
* @param target : Creature pointing out the target * @param target : Creature pointing out the target
* @param trigger : Skill pointing out the skill triggering this action * @param trigger : Skill pointing out the skill triggering this action
* @return Effect[] : array of effects generated by the skill * @return List<Effect> : List of effects generated by the skill
*/ */
public boolean getSkillEffects(Creature caster, Creature target, Skill trigger) public boolean getSkillEffects(Creature caster, Creature target, Skill trigger)
{ {

View File

@@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model.items.instance;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.List;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
@@ -869,9 +870,9 @@ public class ItemInstance extends WorldObject
/** /**
* This function basically returns a set of functions from Item/Armor/Weapon, but may add additional functions, if this particular item instance is enhanched for a particular player. * This function basically returns a set of functions from Item/Armor/Weapon, but may add additional functions, if this particular item instance is enhanched for a particular player.
* @param creature : Creature designating the player * @param creature : Creature designating the player
* @return Func[] * @return List<Func>
*/ */
public Func[] getStatFuncs(Creature creature) public List<Func> getStatFuncs(Creature creature)
{ {
return _item.getStatFuncs(this, creature); return _item.getStatFuncs(this, creature);
} }

View File

@@ -237,10 +237,7 @@ public class Continuous implements ISkillHandler
final DuelManager dm = DuelManager.getInstance(); final DuelManager dm = DuelManager.getInstance();
if (dm != null) if (dm != null)
{ {
final Effect[] effects = skill.applyEffects(creature, target, ss, sps, bss); for (Effect buff : skill.applyEffects(creature, target, ss, sps, bss))
if (effects != null)
{
for (Effect buff : effects)
{ {
if (buff != null) if (buff != null)
{ {
@@ -249,7 +246,6 @@ public class Continuous implements ISkillHandler
} }
} }
} }
}
else else
{ {
skill.applyEffects(creature, target, ss, sps, bss); skill.applyEffects(creature, target, ss, sps, bss);

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model; package org.l2jmobius.gameserver.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -104,8 +105,6 @@ public abstract class Effect
NEGATE NEGATE
} }
private static final Func[] _emptyFunctionSet = new Func[0];
// member _effector is the instance of Creature that cast/used the spell/skill that is causing this effect. Do not confuse with the instance of Creature that is being affected by this effect. // member _effector is the instance of Creature that cast/used the spell/skill that is causing this effect. Do not confuse with the instance of Creature that is being affected by this effect.
private final Creature _effector; private final Creature _effector;
@@ -538,12 +537,13 @@ public abstract class Effect
} }
} }
public Func[] getStatFuncs() public List<Func> getStatFuncs()
{ {
if (_funcTemplates == null) if (_funcTemplates == null)
{ {
return _emptyFunctionSet; return Collections.emptyList();
} }
final List<Func> funcs = new ArrayList<>(); final List<Func> funcs = new ArrayList<>();
for (FuncTemplate t : _funcTemplates) for (FuncTemplate t : _funcTemplates)
{ {
@@ -557,11 +557,8 @@ public abstract class Effect
funcs.add(f); funcs.add(f);
} }
} }
if (funcs.isEmpty())
{ return funcs;
return _emptyFunctionSet;
}
return funcs.toArray(new Func[funcs.size()]);
} }
public void addIcon(MagicEffectIcons mi) public void addIcon(MagicEffectIcons mi)

View File

@@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -381,9 +382,6 @@ public abstract class Skill
public static final int COND_GRADED = 0x080000; public static final int COND_GRADED = 0x080000;
public static final int COND_GRADES = 0x100000; public static final int COND_GRADES = 0x100000;
private static final Func[] _emptyFunctionSet = new Func[0];
private static final Effect[] _emptyEffectSet = new Effect[0];
// these two build the primary key // these two build the primary key
private final int _id; private final int _id;
private final int _level; private final int _level;
@@ -2620,16 +2618,16 @@ public abstract class Skill
return targets.get(0); return targets.get(0);
} }
public Func[] getStatFuncs(Effect effect, Creature creature) public List<Func> getStatFuncs(Effect effect, Creature creature)
{ {
if (!(creature instanceof PlayerInstance) && !(creature instanceof Attackable) && !(creature instanceof Summon)) if (!(creature instanceof PlayerInstance) && !(creature instanceof Attackable) && !(creature instanceof Summon))
{ {
return _emptyFunctionSet; return Collections.emptyList();
} }
if (_funcTemplates == null) if (_funcTemplates == null)
{ {
return _emptyFunctionSet; return Collections.emptyList();
} }
final List<Func> funcs = new ArrayList<>(); final List<Func> funcs = new ArrayList<>();
@@ -2644,12 +2642,8 @@ public abstract class Skill
funcs.add(f); funcs.add(f);
} }
} }
if (funcs.isEmpty())
{
return _emptyFunctionSet;
}
return funcs.toArray(new Func[funcs.size()]); return funcs;
} }
public boolean hasEffects() public boolean hasEffects()
@@ -2657,31 +2651,31 @@ public abstract class Skill
return (_effectTemplates != null) && (_effectTemplates.length > 0); return (_effectTemplates != null) && (_effectTemplates.length > 0);
} }
public Effect[] applyEffects(Creature effector, Creature effected) public List<Effect> applyEffects(Creature effector, Creature effected)
{ {
return applyEffects(effector, effected, false, false, false); return applyEffects(effector, effected, false, false, false);
} }
public Effect[] applyEffects(Creature effector, Creature effected, boolean ss, boolean sps, boolean bss) public List<Effect> applyEffects(Creature effector, Creature effected, boolean ss, boolean sps, boolean bss)
{ {
if (isPassive()) if (isPassive())
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
if (_effectTemplates == null) if (_effectTemplates == null)
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
if ((effector != effected) && effected.isInvul()) if ((effector != effected) && effected.isInvul())
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
if ((_skillType == SkillType.BUFF) && effected.isBlockBuff()) if ((_skillType == SkillType.BUFF) && effected.isBlockBuff())
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
final List<Effect> effects = new ArrayList<>(); final List<Effect> effects = new ArrayList<>();
@@ -2715,24 +2709,19 @@ public abstract class Skill
} }
} }
if (effects.isEmpty()) return effects;
{
return _emptyEffectSet;
} }
return effects.toArray(new Effect[effects.size()]); public List<Effect> applySelfEffects(Creature effector)
}
public Effect[] applySelfEffects(Creature effector)
{ {
if (isPassive()) if (isPassive())
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
if (_effectTemplatesSelf == null) if (_effectTemplatesSelf == null)
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
final List<Effect> effects = new ArrayList<>(); final List<Effect> effects = new ArrayList<>();
@@ -2777,12 +2766,8 @@ public abstract class Skill
} }
} }
} }
if (effects.isEmpty())
{
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]); return effects;
} }
public void attach(FuncTemplate f) public void attach(FuncTemplate f)

View File

@@ -4493,7 +4493,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
* <li>Use an active skill</li><br> * <li>Use an active skill</li><br>
* @param funcs The list of Func objects to add to the Calculator corresponding to the state affected * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
*/ */
public synchronized void addStatFuncs(Func[] funcs) public synchronized void addStatFuncs(List<Func> funcs)
{ {
final List<Stat> modifiedStats = new ArrayList<>(); final List<Stat> modifiedStats = new ArrayList<>();
for (Func f : funcs) for (Func f : funcs)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model.items; package org.l2jmobius.gameserver.model.items;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.l2jmobius.gameserver.data.SkillTable; import org.l2jmobius.gameserver.data.SkillTable;
@@ -147,14 +148,17 @@ public class Armor extends Item
* Returns array of Func objects containing the list of functions used by the armor * Returns array of Func objects containing the list of functions used by the armor
* @param instance : ItemInstance pointing out the armor * @param instance : ItemInstance pointing out the armor
* @param creature : Creature pointing out the player * @param creature : Creature pointing out the player
* @return Func[] : array of functions * @return List<Func> : List of functions
*/ */
@Override @Override
public Func[] getStatFuncs(ItemInstance instance, Creature creature) public List<Func> getStatFuncs(ItemInstance instance, Creature creature)
{ {
if (_funcTemplates == null)
{
return Collections.emptyList();
}
final List<Func> funcs = new ArrayList<>(); final List<Func> funcs = new ArrayList<>();
if (_funcTemplates != null)
{
for (FuncTemplate t : _funcTemplates) for (FuncTemplate t : _funcTemplates)
{ {
final Env env = new Env(); final Env env = new Env();
@@ -166,7 +170,7 @@ public class Armor extends Item
funcs.add(f); funcs.add(f);
} }
} }
}
return funcs.toArray(new Func[funcs.size()]); return funcs;
} }
} }

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model.items; package org.l2jmobius.gameserver.model.items;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.l2jmobius.Config; import org.l2jmobius.Config;
@@ -140,9 +141,6 @@ public abstract class Item
protected EffectTemplate[] _effectTemplates; protected EffectTemplate[] _effectTemplates;
protected Skill[] _skills; protected Skill[] _skills;
private static final Func[] _emptyFunctionSet = new Func[0];
protected static final Effect[] _emptyEffectSet = new Effect[0];
/** /**
* Constructor of the Item that fill class variables.<br> * Constructor of the Item that fill class variables.<br>
* <u><i>Variables filled :</i></u><br> * <u><i>Variables filled :</i></u><br>
@@ -507,14 +505,15 @@ public abstract class Item
* Returns array of Func objects containing the list of functions used by the item * Returns array of Func objects containing the list of functions used by the item
* @param instance : ItemInstance pointing out the item * @param instance : ItemInstance pointing out the item
* @param creature : Creature pointing out the player * @param creature : Creature pointing out the player
* @return Func[] : array of functions * @return List<Func> : List of functions
*/ */
public Func[] getStatFuncs(ItemInstance instance, Creature creature) public List<Func> getStatFuncs(ItemInstance instance, Creature creature)
{ {
if (_funcTemplates == null) if (_funcTemplates == null)
{ {
return _emptyFunctionSet; return Collections.emptyList();
} }
final List<Func> funcs = new ArrayList<>(); final List<Func> funcs = new ArrayList<>();
for (FuncTemplate t : _funcTemplates) for (FuncTemplate t : _funcTemplates)
{ {
@@ -528,25 +527,23 @@ public abstract class Item
funcs.add(f); funcs.add(f);
} }
} }
if (funcs.isEmpty())
{ return funcs;
return _emptyFunctionSet;
}
return funcs.toArray(new Func[funcs.size()]);
} }
/** /**
* Returns the effects associated with the item. * Returns the effects associated with the item.
* @param instance : ItemInstance pointing out the item * @param instance : ItemInstance pointing out the item
* @param creature : Creature pointing out the player * @param creature : Creature pointing out the player
* @return Effect[] : array of effects generated by the item * @return List<Effect> : List of effects generated by the item
*/ */
public Effect[] getEffects(ItemInstance instance, Creature creature) public List<Effect> getEffects(ItemInstance instance, Creature creature)
{ {
if (_effectTemplates == null) if (_effectTemplates == null)
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
final List<Effect> effects = new ArrayList<>(); final List<Effect> effects = new ArrayList<>();
for (EffectTemplate et : _effectTemplates) for (EffectTemplate et : _effectTemplates)
{ {
@@ -560,25 +557,23 @@ public abstract class Item
effects.add(e); effects.add(e);
} }
} }
if (effects.isEmpty())
{ return effects;
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
} }
/** /**
* Returns effects of skills associated with the item. * Returns effects of skills associated with the item.
* @param caster : Creature pointing out the caster * @param caster : Creature pointing out the caster
* @param target : Creature pointing out the target * @param target : Creature pointing out the target
* @return Effect[] : array of effects generated by the skill * @return List<Effect> : List of effects generated by the skill
*/ */
public Effect[] getSkillEffects(Creature caster, Creature target) public List<Effect> getSkillEffects(Creature caster, Creature target)
{ {
if (_skills == null) if (_skills == null)
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
final List<Effect> effects = new ArrayList<>(); final List<Effect> effects = new ArrayList<>();
for (Skill skill : _skills) for (Skill skill : _skills)
{ {
@@ -596,11 +591,8 @@ public abstract class Item
effects.add(e); effects.add(e);
} }
} }
if (effects.isEmpty())
{ return effects;
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
} }
/** /**

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.model.items; package org.l2jmobius.gameserver.model.items;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.l2jmobius.gameserver.data.SkillTable; import org.l2jmobius.gameserver.data.SkillTable;
@@ -290,14 +291,17 @@ public class Weapon extends Item
* Returns array of Func objects containing the list of functions used by the weapon * Returns array of Func objects containing the list of functions used by the weapon
* @param instance : ItemInstance pointing out the weapon * @param instance : ItemInstance pointing out the weapon
* @param creature : Creature pointing out the player * @param creature : Creature pointing out the player
* @return Func[] : array of functions * @return List<Func> : List of functions
*/ */
@Override @Override
public Func[] getStatFuncs(ItemInstance instance, Creature creature) public List<Func> getStatFuncs(ItemInstance instance, Creature creature)
{ {
if (_funcTemplates == null)
{
return Collections.emptyList();
}
final List<Func> funcs = new ArrayList<>(); final List<Func> funcs = new ArrayList<>();
if (_funcTemplates != null)
{
for (FuncTemplate t : _funcTemplates) for (FuncTemplate t : _funcTemplates)
{ {
final Env env = new Env(); final Env env = new Env();
@@ -309,8 +313,8 @@ public class Weapon extends Item
funcs.add(f); funcs.add(f);
} }
} }
}
return funcs.toArray(new Func[funcs.size()]); return funcs;
} }
/** /**
@@ -318,14 +322,15 @@ public class Weapon extends Item
* @param caster : Creature pointing out the caster * @param caster : Creature pointing out the caster
* @param target : Creature pointing out the target * @param target : Creature pointing out the target
* @param crit : boolean tells whether the hit was critical * @param crit : boolean tells whether the hit was critical
* @return Effect[] : array of effects generated by the skill * @return List<Effect> : List of effects generated by the skill
*/ */
public Effect[] getSkillEffects(Creature caster, Creature target, boolean crit) public List<Effect> getSkillEffects(Creature caster, Creature target, boolean crit)
{ {
if ((_skillsOnCrit == null) || !crit) if ((_skillsOnCrit == null) || !crit)
{ {
return _emptyEffectSet; return Collections.emptyList();
} }
final List<Effect> effects = new ArrayList<>(); final List<Effect> effects = new ArrayList<>();
for (Skill skill : _skillsOnCrit) for (Skill skill : _skillsOnCrit)
{ {
@@ -348,11 +353,8 @@ public class Weapon extends Item
effects.add(e); effects.add(e);
} }
} }
if (effects.isEmpty())
{ return effects;
return _emptyEffectSet;
}
return effects.toArray(new Effect[effects.size()]);
} }
/** /**
@@ -360,7 +362,7 @@ public class Weapon extends Item
* @param caster : Creature pointing out the caster * @param caster : Creature pointing out the caster
* @param target : Creature pointing out the target * @param target : Creature pointing out the target
* @param trigger : Skill pointing out the skill triggering this action * @param trigger : Skill pointing out the skill triggering this action
* @return Effect[] : array of effects generated by the skill * @return List<Effect> : List of effects generated by the skill
*/ */
public boolean getSkillEffects(Creature caster, Creature target, Skill trigger) public boolean getSkillEffects(Creature caster, Creature target, Skill trigger)
{ {

View File

@@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.model.items.instance;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.List;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
@@ -918,9 +919,9 @@ public class ItemInstance extends WorldObject
/** /**
* This function basically returns a set of functions from Item/Armor/Weapon, but may add additional functions, if this particular item instance is enhanched for a particular player. * This function basically returns a set of functions from Item/Armor/Weapon, but may add additional functions, if this particular item instance is enhanched for a particular player.
* @param creature : Creature designating the player * @param creature : Creature designating the player
* @return Func[] * @return List<Func>
*/ */
public Func[] getStatFuncs(Creature creature) public List<Func> getStatFuncs(Creature creature)
{ {
return _item.getStatFuncs(this, creature); return _item.getStatFuncs(this, creature);
} }