problem with scheduler

Discussion in 'Plugin Development' started by topilov, Apr 22, 2022.

  1. Offline

    topilov

    how can I fix this error?

    no suitable method found for runTaskLater(me.topilom.mainplugin.Events.BlockBreakOnSpawn,()->{ even[...]E); },int)


    upload_2022-4-22_23-33-38.png


    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);
    }

    }}
     
  2. Offline

    xpaintall

    @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.
     
  3. Offline

    topilov

    thank you very much

    But now I'm faced with one problem,

    this line works in the main class
    upload_2022-4-24_21-23-24.png

    because all the classes that are responsible for attaching MySQL base they refer to the Main Class.
    upload_2022-4-24_21-24-4.png

    But how do I make it work in a different class upload_2022-4-24_21-24-29.png
     
  4. Offline

    KarimAKL

    @topilov Assuming 'data' is a public instance variable in your main class, you could use your new 'main' variable to access it.
     

Share This Page