Explv Posted June 5, 2018 Share Posted June 5, 2018 2 hours ago, Pegasus said: great example, but if you input item name with Apostrophe character, e.g Greenman's ale, it doesn't print anything. Updated my answer to fix this issue. 1 Quote Link to comment Share on other sites More sharing options...
liverare Posted June 5, 2018 Share Posted June 5, 2018 Items are known constants, so make an enumerator and populate it with relevant items. Enumerators can also have interfaces implemented into them, so you can include an item filter and then simply refer to the entries: public enum ItemData implements Filter<Item> { ABYSSAL_WHIP(4151, "Abyssal whip"), COINS(995, "Coins"), ; private final int id; private final String name; private ItemData(int id, String name) { this.id = id; this.name = name; } @Override public String toString() { return String.format("[%s] %s", id, name); } @Override public boolean match(Item item) { return item.getId() == id || item.getName().equals(name); } public int getId() { return id; } public String getName() { return name; } } Then you can do: Item item1 = inventory.getItem(ItemData.ABYSSAL_WHIP); Item item2 = inventory.getItem(ItemData.values()); 1 Quote Link to comment Share on other sites More sharing options...