Jump to content

Getting itemID by name


Recommended Posts

Posted

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());

 

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...