/*
 * Copyright (c) 2017, Seth <Sethtroll3@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package net.runelite.api;

/**
 * Enumeration of message types that can be received in the chat.
 */
public enum ChatMessageType
{
	/**
	 * A message received from the server.
	 */
	SERVER(0),
	/**
	 * A message in the public chat.
	 */
	PUBLIC(2),
	/**
	 * A private message from another player.
	 */
	PRIVATE_MESSAGE_RECEIVED(3),
	/**
	 * A trade request received.
	 */
	TRADE_RECEIVED(4),
	/**
	 * A message received when a friend logs in or out.
	 */
	PRIVATE_MESSAGE_INFO(5),
	/**
	 * A private message sent to another player.
	 */
	PRIVATE_MESSAGE_SENT(6),
	/**
	 * A private message received from a moderator.
	 */
	PRIVATE_MESSAGE_RECEIVED_MOD(7),
	/**
	 * A message received in clan chat.
	 */
	CLANCHAT(9),
	/**
	 * A message received with information about the current clan chat.
	 */
	CLANCHAT_INFO(11),
	/**
	 * A trade request being sent.
	 */
	TRADE_SENT(12),
	/**
	 * An abuse report submitted.
	 */
	ABUSE_REPORT(26),
	/**
	 * Examine item description.
	 */
	EXAMINE_ITEM(27),
	/**
	 * Examine NPC description.
	 */
	EXAMINE_NPC(28),
	/**
	 * Examine object description.
	 */
	EXAMINE_OBJECT(29),
	/**
	 * Adding player to friend list.
	 */
	FRIENDS_LIST_ADD(30),
	/**
	 * Adding player to ignore list.
	 */
	IGNORE_LIST_ADD(31),
	/**
	 * An autochat message from a player.
	 */
	AUTOCHAT(90),
	/**
	 * A game message (ie. when a setting is changed).
	 */
	GAME(99),
	/**
	 * A message received when somebody sends a trade offer.
	 */
	TRADE(101),
	/**
	 * A message received when somebody sends a duel offer.
	 */
	DUEL(103),
	/**
	 * A message that was filtered.
	 */
	FILTERED(105),
	/**
	 * A message about an action.
	 */
	ACTION(109),
	/**
	 * An unknown message type.
	 */
	UNKNOWN(-1);

	private final int type;

	ChatMessageType(int type)
	{
		this.type = type;
	}

	/**
	 * Utility method that maps the type value to its respective
	 * {@link ChatMessageType} value.
	 *
	 * @param type the raw type
	 * @return appropriate message type, or {@link #UNKNOWN}
	 */
	public static ChatMessageType of(int type)
	{
		for (ChatMessageType ct : ChatMessageType.values())
		{
			if (ct.type == type)
			{
				return ct;
			}
		}
		return UNKNOWN;
	}

	/**
	 * Gets the raw type value of the message type.
	 *
	 * @return the raw type
	 */
	public int getType()
	{
		return type;
	}
}

@@ -1403,16 +1403,121 @@
 e.api;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0Aimport lombok.AllArgsConstructor;%0Aimport lombok.Getter;%0A%0A
 /**%0A * E
@@ -1582,16 +1582,44 @@
 at.%0A */%0A
+@AllArgsConstructor%0A@Getter%0A
 public e
@@ -3252,56 +3252,233 @@
 ;%0A%0A%09
-ChatMessageType(int type
+private static final Map%3CInteger, ChatMessageType%3E CHAT_MESSAGE_TYPES = new HashMap%3C%3E();%0A%0A%09static%0A%09%7B%0A%09%09for (ChatMessageType chatMessageType : values()
 )%0A
+%09
 %09%7B%0A%09%09
-this.type = type;
+%09CHAT_MESSAGE_TYPES.put(chatMessageType.type, chatMessageType);%0A%09%09%7D
 %0A%09%7D%0A
@@ -3729,265 +3729,61 @@
 %7B%0A%09%09
-for (ChatMessageType ct : ChatMessageType.values())%0A%09%09%7B%0A%09%09%09if (ct.type == type)%0A%09%09%09%7B%0A%09%09%09%09return ct;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return UNKNOWN;%0A%09%7D%0A%0A%09/**%0A%09 * Gets the raw type value of the message type.%0A%09 *%0A%09 * @return the raw type%0A%09 */%0A%09public int getType()%0A%09%7B%0A%09%09return type
+return CHAT_MESSAGE_TYPES.getOrDefault(type, UNKNOWN)
 ;%0A%09%7D

optimize ChatMessageType.of()