diff options
author | Nathan Adams <dinnerbone@dinnerbone.com> | 2012-01-15 09:18:20 +0000 |
---|---|---|
committer | Nathan Adams <dinnerbone@dinnerbone.com> | 2012-01-15 09:18:20 +0000 |
commit | 5ba2e0e158a0494512b38b8f0e2dfa083a84e3d9 (patch) | |
tree | cdc6f89de88abeac9ed90cfd503f178968cde2c5 /src/main/java/org | |
parent | 11adb74a23847d2922ca088c8d7bdf67324f3fb9 (diff) | |
download | bukkit-5ba2e0e158a0494512b38b8f0e2dfa083a84e3d9.tar bukkit-5ba2e0e158a0494512b38b8f0e2dfa083a84e3d9.tar.gz bukkit-5ba2e0e158a0494512b38b8f0e2dfa083a84e3d9.tar.lz bukkit-5ba2e0e158a0494512b38b8f0e2dfa083a84e3d9.tar.xz bukkit-5ba2e0e158a0494512b38b8f0e2dfa083a84e3d9.zip |
Changed Material to use an array for lookups, instead of a hashmap. Thanks to zml2008 for the PR
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/Material.java | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index c0bafe88..49e47993 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -2,11 +2,13 @@ package org.bukkit; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.material.*; +import org.bukkit.util.Java15Compat; /** * An enum of all material ids accepted by the official server + client @@ -278,7 +280,7 @@ public enum Material { private final int id; private final Class<? extends MaterialData> data; - private static final Map<Integer, Material> lookupId = new HashMap<Integer, Material>(); + private static Material[] lookupId = new Material[3200]; private static final Map<String, Material> lookupName = new HashMap<String, Material>(); private final int maxStack; private final short durability; @@ -419,7 +421,11 @@ public enum Material { * @return Material if found, or null */ public static Material getMaterial(final int id) { - return lookupId.get(id); + if (lookupId.length > id) { + return lookupId[id]; + } else { + return null; + } } /** @@ -461,7 +467,12 @@ public enum Material { static { for (Material material : values()) { - lookupId.put(material.getId(), material); + if (lookupId.length > material.id) { + lookupId[material.id] = material; + } else { + lookupId = Java15Compat.Arrays_copyOfRange(lookupId, 0, material.id + 2); + lookupId[material.id] = material; + } lookupName.put(material.name(), material); } } |