Please Help

Discussion in 'Spigot Plugin Development' started by Bravecity, Jun 16, 2015.

  1. I need help, i tried to make a delayed task but it is all underlined in red please tell me what i have done wrong

    Code:
    Code (Text):
    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            if(e.getPlayer().hasPermission("bc.staff.join")) {
               
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() {
                    Player p = e.getPlayer();
                    p.sendMessage(ChatColor.GREEN + "Welcome Back");
                },0, 20 * 10);
            }
        }
     
  2. I am new to java really, but this is some code I use in a plugin I've been working on.
    Of course, I tried to modify it to match yours. It seems to be working for me. Give it a try?

    Code (Text):
    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            if(e.getPlayer().hasPermission("bc.staff.join")) {
            BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
            scheduler.scheduleSyncDelayedTask(this, new Runnable() {
                @Override
                public void run()
                {
                    Player p = e.getPlayer();
                    p.sendMessage(ChatColor.GREEN + "Welcome Back");
                }
            }, 0, 36000L); //start counting immediately, then execute in 30 minutes (in ticks)
        }
    }
    No clue if this will work for you, because mine was for a repeating task. I changed "repeating" to "Delayed" for this example.
     
  3. @SeiRruf Your example is great. Note though, that you should omit the '36000L' as that is supposed to indicate the interval between repetitions for repeating tasks. If you want to schedule a delayed task, do:
    Code (Text):
    getServer().getScheduler().scheduleSyncDelayedTask(Plugin.instance, new Runnable() {
        @Override
        public void run() {
        // Do something
        }
    }, delay);
    *Plugin.instance - an instance of your main plugin class that extends JavaPlugin. You can use 'this' if your Listener is in your main class though I highly recommend not doing so unless you are attempting a small plugin.
    *delay - the delay in ticks after which the task will perform. The countdown for the delay starts as soon as the plugin loads. (TIP: 1 second = 20 ticks)
     
  4. Thank you so much this is gonna help me with alot of my projects