mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-04 05:25:28 +02:00
Cache ItemMeta instead of creating a new ItemMeta for each potion check (#5075)
* Cache ItemMeta instead of creating a new ItemMeta for each potion check * Check if the item has item meta and, if it doesn't, bail out * Also cache the potion item meta too * Add requireNonNull to the potionItemMeta
This commit is contained in:
@@ -9,6 +9,7 @@ import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
@@ -334,9 +335,14 @@ public class PotionConfig extends LegacyConfigLoader {
|
||||
* @return AlchemyPotion that corresponds to the given ItemStack.
|
||||
*/
|
||||
public AlchemyPotion getPotion(ItemStack item) {
|
||||
// Fast return if the item does not have any item meta to avoid initializing an unnecessary ItemMeta instance
|
||||
if (!item.hasItemMeta())
|
||||
return null;
|
||||
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
final List<AlchemyPotion> potionList = alchemyPotions.values()
|
||||
.stream()
|
||||
.filter(potion -> potion.isSimilarPotion(item))
|
||||
.filter(potion -> potion.isSimilarPotion(item, itemMeta))
|
||||
.toList();
|
||||
if(potionList.size() > 1) {
|
||||
mcMMO.p.getLogger().severe("Multiple potions defined in config have matched this potion, for mcMMO to behave" +
|
||||
|
Reference in New Issue
Block a user