Small optimization for armor searching

This commit is contained in:
HugoDaBosss 2016-03-18 22:57:16 +01:00
parent 615128eba2
commit 9b6a9fca3d

View File

@ -1,7 +1,10 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8; package us.myles.ViaVersion.protocols.protocol1_9to1_8;
import java.util.HashMap;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -35,11 +38,17 @@ public enum ArmorType {
private final int id; private final int id;
private final Material type; private final Material type;
private static HashMap<Material, ArmorType> armor;
static {
armor = new HashMap<Material, ArmorType>();
for(ArmorType a : ArmorType.values()) {
armor.put(a.getType(), a);
}
}
public static ArmorType findByType(Material type) { public static ArmorType findByType(Material type) {
for (ArmorType a : ArmorType.values()) ArmorType t = armor.get(type);
if (a.getType() == type) return t == null ? ArmorType.NONE : t;
return a;
return ArmorType.NONE;
} }
public static int calculateArmorPoints(ItemStack[] armor) { public static int calculateArmorPoints(ItemStack[] armor) {