Here's a lil' rewrite, hopefully you'll learn something(s) from it ^^
Gl coding!
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.Arrays;
import java.util.List;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.input.mouse.InventorySlotDestination;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
@ScriptManifest(author = "Botrepreneur", info = "HerbIdentifier", name = "HerbIdentifier", version = 0.0, logo = "")
public class HerbIdentifier extends Script {
private enum Herb {
GUAM(199, 200),
MARRENTIL(201, 202),
TARROMIN(203, 204),
HARRALANDER(205, 206),
RANARR(207, 208),
IRIT(209, 210),
AVANTOE(211, 212),
KWUARM(213, 214),
CANDANTINE(215, 216),
DWARF_WEED(217, 218),
TORSOL(219, 220),
LANTADYME(2485, 2486),
SNAPDRAGON(3051, 3052);
private final Integer[] ids;
private Herb(final Integer... ids) {
this.ids = ids;
}
public List<Integer> getIds() {
return Arrays.asList(ids);
}
}
@Override
public int onLoop() throws InterruptedException {
return Integer.MAX_VALUE;
}
public void onPaint(Graphics2D paint) {
int slot = -1;
Item item = null;
Rectangle rectangle = null;
if (getBot().getClient().isLoggedIn()) {
Point point = getMouse().getPosition();
for (int i = 0; i < 28; i++) {
if ((InventorySlotDestination.getSlot(i)).contains(point)) {
slot = i;
break;
}
}
if (slot > -1 && (item = getInventory().getItemInSlot(slot)) != null && item.getDefinition() != null && (rectangle = InventorySlotDestination.getSlot(slot)) != null) {
int id = item.getId();
String string = null;
for (Herb herb : Herb.values()) {
if (herb.getIds().contains(id)) {
string = herb.toString();
break;
}
}
if (string != null) {
paint.drawString(string, rectangle.x, rectangle.y);
}
}
}
}
}