private final String selectedItemCheckFieldName = "is", selectedSlotIdFieldName = "gw";
private Field selectedItemCheck = null, selectedSlotId = null;
public boolean isItemSelected(String name) {
try {
if (selectedItemCheck == null) {
try {
ClassLoader loader = client.instance.getClass().getClassLoader();
Class clazz = Class.forName("client", false, loader);
selectedItemCheck = clazz.getDeclaredField(selectedItemCheckFieldName);
selectedSlotId = clazz.getDeclaredField(selectedSlotIdFieldName);
selectedSlotId.setAccessible(true);
selectedItemCheck.setAccessible(true);
} catch (NoSuchFieldException | SecurityException | ClassNotFoundException ex) {
Logger.getLogger(AbstractScript.class.getName()).log(Level.SEVERE, null, ex);
}
}
int i = (int) selectedItemCheck.get(null);
if (i == 0) {
return false;
} else {
final Item item = client.getInventory().getItems()[(int) selectedSlotId.get(null) * 1168746611];
if (item.getName().equalsIgnoreCase(name)) {
return true;
}
}
} catch (IllegalArgumentException | IllegalAccessException ex) {
Logger.getLogger(AbstractScript.class.getName()).log(Level.SEVERE, null, ex);
}
return false;
}