how can I fix this error? no suitable method found for runTaskLater(me.topilom.mainplugin.Events.BlockBreakOnSpawn,()->{ even[...]E); },int) package me.topilom.mainplugin.Events; import me.topilom.mainplugin.MainPlugin; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitTask; public class BlockBreakOnSpawn implements Listener { public ItemStack pinkBlocks = new ItemStack(Material.PINK_CONCRETE); @EventHandler public void blockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); if(event.getBlock().getType() == Material.PINK_CONCRETE) { player.getInventory().addItem(pinkBlocks); event.getBlock().setType(Material.AIR); Bukkit.getScheduler().runTaskLater(this, () -> { event.getBlock().setType(Material.PINK_CONCRETE); }, 20); } }}
@topilov The required type should be your main class. You put "this", implying that your plugin is the class you're running the scheduler from. Code: MainClass main; public YourRunnableClass(MainClass main) { this.main = main; } and do this inside of your void Code: Bukkit.getScheduler().runTaskLater(main, () -> { event.getBlock().setType(Material.PINK_CONCRETE); }, 20); You can also fetch the main from a static, but I've had issues with that before, so I wouldn't recommend it.
thank you very much But now I'm faced with one problem, this line works in the main class because all the classes that are responsible for attaching MySQL base they refer to the Main Class. But how do I make it work in a different class
@topilov Assuming 'data' is a public instance variable in your main class, you could use your new 'main' variable to access it.