From e15c8d72578600c0cd4fdf1dc14a64f6dd9f150d Mon Sep 17 00:00:00 2001 From: Hugo Kerstens Date: Tue, 22 Mar 2016 20:16:39 +0100 Subject: [PATCH] Optimise sound searching --- .../protocol1_9to1_8/sounds/SoundEffect.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java index dd0f31af3..d725ee9e6 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java @@ -1,6 +1,9 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds; import lombok.Getter; +import org.bukkit.Sound; + +import java.util.HashMap; @Getter public enum SoundEffect { @@ -257,6 +260,14 @@ public enum SoundEffect { private final SoundCategory category; private final boolean breaksound; + private static HashMap effects; + static { + effects = new HashMap(); + for(SoundEffect e : SoundEffect.values()) { + effects.put(e.getName(), e); + } + } + SoundEffect(String name, String newname, SoundCategory cat) { this.category = cat; this.newName = newname; @@ -273,10 +284,8 @@ public enum SoundEffect { public static SoundEffect getByName(String name) { name = name.toLowerCase(); - for (SoundEffect e : SoundEffect.values()) { - if (e.getName().equals(name)) - return e; - } + if(effects.containsKey(name)) + return effects.get(name); return null; }