private boolean waitUntilItem(int item, int timeOut) { long startTime = System.currentTimeMillis(); int oldCount = getInventoryCount(item); while(true) { int newCount = getInventoryCount(item); long currentTime = System.currentTimeMillis(); if(newCount > oldCount) return true; if(timeOut >= 0 && currentTime - startTime > timeOut) return false; wait(random(200, 300)); } }