So this is a really nooby question, but how would I put an item in a gui wait a few seconds then do it again for the next slot then after a while stop? I tried thread.sleep(2000); but instead of putting an item then stopping then doing it again, it waited until the whole try/catch thing was over then put it. Heres my code: https://hastebin.com/ofoxibilen.scala
It also has a #runTaskTimer method, so the task it will be called every X ticks. If you want to stop the runnable, use #cancel method
Yeah I got that, but now I need to figure out how to make the block be put in the next slot so it doesnt place it in the same slot every time
Well, I found another way anyway but I got another error(not really an error, just something rlly annoying). https://hastebin.com/rareredoju.cs It only makes the first block green but then stops
as said, use a repeating task, run it every x ticks, then cancel it when needed. ex: Code (Java): new BukkitRunnable() { int i = 0; @Override public void run() { if (i < 10) { inventory.setItem(i, new ItemStack(Material.LOG)); i++; return; } cancel(); //cancels the repeating task } }.runTaskTimer(...);
miner.getItem(11) != null You are checking if the item in the 11th slot is not null, then you are setting it. If it is empty, nothing happend
You will break all plugins that have tasks running if you use Bukkit.getScheduler().cancelAllTasks(). That is a silly thing to think you can do. But as Parozzz pointed out, you are checking if the slots are not empty and then setting them. You need to check if they are empty and if they are set them. "i < 9"*
What error did you get the console will show you what line is creating the error. Sent from my iPhone using Tapatalk
Code (Java): //start loop Integer timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(PLUGIN, new Runnable() { @Override public void run() { //code here //stop so it does not loop Bukkit.getScheduler().cancelTask(timer); } }, 20, 20); //first number is after how many ticks to start and the other is the time for loop (also in ticks)