Simplify merge level application

- Checking and updating the new level of a merged enchantment used several calls to the map, which wasn't necessary.
This commit is contained in:
Pim van der Loos 2022-03-13 23:26:49 +01:00
parent ccdd5b9af1
commit bb40e20d90
No known key found for this signature in database
GPG Key ID: C16F020ADAE6D5A8

View File

@ -6,7 +6,13 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class EnchantmentContainer implements Iterable<Map.Entry<Enchantment, Integer>>
{
@ -232,17 +238,14 @@ public class EnchantmentContainer implements Iterable<Map.Entry<Enchantment, Int
Integer enchantLevel = combined.get(entry.getKey());
if (enchantLevel != null)
{
final int oldLevel = enchantLevel;
if (entry.getValue().equals(enchantLevel) && entry.getValue() < entry.getKey().getMaxLevel())
enchantLevel = entry.getValue() + 1;
else if (entry.getValue() > enchantLevel)
enchantLevel = entry.getValue();
// If the enchantment level has changed,
if (!enchantLevel.equals(combined.get(entry.getKey())))
{
combined.remove(entry.getKey());
if (enchantLevel != oldLevel)
combined.put(entry.getKey(), enchantLevel);
}
}
else
combined.put(entry.getKey(), entry.getValue());