diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index d3ae690656..f3e4aa2c81 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2204,17 +2201,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/items/Item.java index 6a6a0a407f..f5eb49c798 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -159,7 +159,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -667,11 +667,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -720,9 +715,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1007,8 +1005,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 9ef5508aa1..9da29a9c79 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final int bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index e97f4f6dde..e38fdfabf9 100644 --- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 92390024b5..c1dcd68abd 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2210,17 +2207,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/items/Item.java index 6a6a0a407f..f5eb49c798 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -159,7 +159,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -667,11 +667,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -720,9 +715,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1007,8 +1005,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 9ef5508aa1..9da29a9c79 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final int bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index e97f4f6dde..e38fdfabf9 100644 --- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 92390024b5..c1dcd68abd 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2210,17 +2207,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/items/Item.java index 6a6a0a407f..f5eb49c798 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -159,7 +159,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -667,11 +667,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -720,9 +715,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1007,8 +1005,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 9ef5508aa1..9da29a9c79 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final int bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index e97f4f6dde..e38fdfabf9 100644 --- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index bb9401f681..3a7ba91768 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2210,17 +2207,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/items/Item.java index 2f237b3276..13d78dad6d 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -159,7 +159,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -667,11 +667,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -720,9 +715,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1007,8 +1005,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 9ef5508aa1..9da29a9c79 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final int bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index e97f4f6dde..e38fdfabf9 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index ecc3d52416..cbaa213cb0 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2223,17 +2220,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/items/Item.java index 4bd3aab41b..e8169a357c 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -160,7 +160,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -668,11 +668,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -721,9 +716,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1008,8 +1006,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 6f56ab9818..3286b91bf0 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final long bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index e97f4f6dde..e38fdfabf9 100644 --- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 5a2850f4ad..9dc46553a0 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2520,17 +2517,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/items/Item.java index feddbe9f58..baa1a07392 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -162,7 +162,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -673,11 +673,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -726,9 +721,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1018,8 +1016,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 6f56ab9818..3286b91bf0 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final long bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index e97f4f6dde..e38fdfabf9 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 5a2850f4ad..9dc46553a0 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2520,17 +2517,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/items/Item.java index 8bc69ec806..145ac0e436 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -162,7 +162,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -674,11 +674,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -727,9 +722,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1019,8 +1017,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 6f56ab9818..3286b91bf0 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final long bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index e97f4f6dde..e38fdfabf9 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 0852fe84eb..32cce45ba1 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2504,17 +2501,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/items/Item.java index 8bc69ec806..145ac0e436 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -162,7 +162,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -674,11 +674,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -727,9 +722,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1019,8 +1017,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 6f56ab9818..3286b91bf0 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final long bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index e97f4f6dde..e38fdfabf9 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 92390024b5..c1dcd68abd 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2210,17 +2207,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/items/Item.java index 546daca8d9..b67d114258 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -159,7 +159,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -667,11 +667,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -720,9 +715,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1007,8 +1005,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 9ef5508aa1..9da29a9c79 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final int bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index 2f49a2a387..352783f486 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 92390024b5..c1dcd68abd 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2210,17 +2207,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/items/Item.java index 546daca8d9..b67d114258 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -159,7 +159,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -667,11 +667,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -720,9 +715,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1007,8 +1005,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 9ef5508aa1..9da29a9c79 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final int bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index 2f49a2a387..352783f486 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 082090fc10..1c36492afd 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2229,17 +2226,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/items/Item.java index fa2fc63e0c..e2f9a6d25b 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -160,7 +160,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -668,11 +668,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -721,9 +716,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1008,8 +1006,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 6f56ab9818..3286b91bf0 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final long bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index 2f49a2a387..352783f486 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 3cbac3a6eb..3f08e4f239 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2520,17 +2517,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/items/Item.java index 2461bd922b..dd4528790b 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -162,7 +162,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -670,11 +670,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -723,9 +718,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1010,8 +1008,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 6f56ab9818..3286b91bf0 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final long bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index 2f49a2a387..352783f486 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 3cbac3a6eb..3f08e4f239 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2520,17 +2517,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/items/Item.java index 2461bd922b..dd4528790b 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -162,7 +162,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -670,11 +670,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -723,9 +718,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1010,8 +1008,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 6f56ab9818..3286b91bf0 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final long bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index 2f49a2a387..352783f486 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 54179297c1..311104562c 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2504,17 +2501,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/items/Item.java index 2461bd922b..dd4528790b 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -162,7 +162,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -670,11 +670,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -723,9 +718,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1010,8 +1008,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 6f56ab9818..3286b91bf0 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final long bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index 2f49a2a387..352783f486 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java index 92390024b5..c1dcd68abd 100644 --- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java +++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/itemcontainer/Inventory.java @@ -20,9 +20,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; @@ -31,7 +29,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.l2jmobius.Config; import org.l2jmobius.commons.database.DatabaseFactory; @@ -2210,17 +2207,35 @@ public abstract class Inventory extends ItemContainer { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).collect(Collectors.toCollection(LinkedList::new)); + + final List items = new ArrayList<>(); + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + items.add(item); + } + } + return items; } @SafeVarargs - public final long getPaperdollItemCount(Predicate... filters) + public final int getPaperdollItemCount(Predicate... filters) { Predicate filter = Objects::nonNull; for (Predicate additionalFilter : filters) { filter = filter.and(additionalFilter); } - return Arrays.stream(_paperdoll).filter(filter).count(); + + int count = 0; + for (ItemInstance item : _paperdoll) + { + if (filter.test(item)) + { + count++; + } + } + return count; } } diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/items/Item.java index 6a6a0a407f..f5eb49c798 100644 --- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/items/Item.java @@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model.items; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; +import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -159,7 +159,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable protected int _type1; // needed for item list (inventory) protected int _type2; // different lists for armor, weapon, etc private Map _elementals = null; - protected List _funcTemplates; + protected Map _funcTemplates; protected List _preConditions; private List _skills; @@ -667,11 +667,6 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return getItemType() == EtcItemType.SCROLL; } - public List getFunctionTemplates() - { - return _funcTemplates != null ? _funcTemplates : Collections.emptyList(); - } - /** * Add the FuncTemplate f to the list of functions used with the item * @param template : FuncTemplate to add @@ -720,9 +715,12 @@ public abstract class Item extends ListenersContainer implements IIdentifiable if (_funcTemplates == null) { - _funcTemplates = new ArrayList<>(); + _funcTemplates = new EnumMap<>(Stat.class); + } + if (_funcTemplates.put(template.getStat(), template) != null) + { + LOGGER.warning("Item with id " + _itemId + " has 2 func templates with same stat: " + template.getStat()); } - _funcTemplates.add(template); } public void attachCondition(Condition c) @@ -1007,8 +1005,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable { if (_funcTemplates != null) { - final FuncTemplate template = _funcTemplates.stream().filter(func -> (func.getStat() == stat) && ((func.getFunctionClass() == FuncAdd.class) || (func.getFunctionClass() == FuncSet.class))).findFirst().orElse(null); - if (template != null) + final FuncTemplate template = _funcTemplates.get(stat); + if ((template != null) && ((template.getFunctionClass() == FuncAdd.class) || (template.getFunctionClass() == FuncSet.class))) { return template.getValue(); } diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java index 9ef5508aa1..9da29a9c79 100644 --- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java +++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/stats/IStatFunction.java @@ -92,7 +92,7 @@ public interface IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); } @@ -110,7 +110,7 @@ public interface IStatFunction } double value = 0; - for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEquipped, ItemInstance::isEnchanted)) + for (ItemInstance equippedItem : creature.getInventory().getPaperdollItems(ItemInstance::isEnchanted)) { final Item item = equippedItem.getItem(); final int bodypart = item.getBodyPart(); diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java index 2f49a2a387..352783f486 100644 --- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java +++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/stats/finalizers/MDefenseFinalizer.java @@ -57,7 +57,7 @@ public class MDefenseFinalizer implements IStatFunction final Inventory inv = creature.getInventory(); if (inv != null) { - for (ItemInstance item : inv.getPaperdollItems(ItemInstance::isEquipped)) + for (ItemInstance item : inv.getPaperdollItems()) { baseValue += item.getItem().getStats(stat, 0); }