please dont use while loops
if (myPlayer().getHealth() > 51 && inventory.contains(myPotions2)){
while (getTabs().getOpen() != Tab.INVENTORY){
getTabs().open(Tab.INVENTORY);
sleep(random(147,412));
}
while (myPlayer().getHealth() > 51){
inventory.interact("Drink", myPotions2);
sleep(random(457,1024));
}
}