ok so this is what i have run if a player right clicks a piston this runs Code:java for (int x1 = 0; x1 <= 70; x1 += 10) { Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { Collections.shuffle(list); ItemStack rItem = new ItemStack(list.get(0), 1); world.dropItem(newLoc, rItem); } }, x1);} i have an array list that i shuffle then take a value from and the goal was to get a mysterybox feel to it and have items flashing above the piston. My problem is that i cant think of a way to remove the item. I planed in another delayed task inside that delayed task removing the item but you cant do that. Any ideas?
15987632 simply do rItem.remove(); Edit: My bad. I meant: Code:java Item i = world.dropItem(newLoc, rItem);i.remove(); Also if you want to remove it later then make a variable outside of the run method and just change that each time run is called and remove it before you change it again.
Forseth11 wont it just remove the item right away? i want to remove the item 10 ticks after i create it
15987632 In that case do this: Code:java for (int x1 = 0; x1 <= 70; x1 += 10) { Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { private Item i = null; public void run() { if(i != null){ i.remove(); } Collections.shuffle(list); ItemStack rItem = new ItemStack(list.get(0), 1); i = world.dropItem(newLoc, rItem); } }, x1);}
Yes it would. In that case make Item i in your class so when you cancel the loop (Which btw your task will only run once since it is a delayedTask) you could remove the item.
Yes ik the for loop. The for loop is just going to run in several milliseconds then all those delayedTasks will run at the same time. You need to use a delayed repeated task.
Forseth11 all the delayed tasks will run 10 ticks behind each other ive tested that part and its worked before