Solved .scheduleSyncDelayedTask help

Discussion in 'Spigot Plugin Development' started by DecisionsYT, May 11, 2016.

Thread Status:
Not open for further replies.
  1. Hey!

    When creating my AntiSpam class for my plugin. When putting in:

    Code (Text):
    plugin.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    I'm getting an error underneath "scheduleSyncDelayedTask"

    This must be (I think ^_^) the reason why the time isn't working and it's not counting to 3 to then allow me to speak. Any suggestions??

    http://prntscr.com/b2w5yd
     
  2. Is AntiSpam extending JavaPlugin?
     
  3. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getServer().getPluginManager().getPlugin("your plugin name"), new Runnable()
     
  4. It can't, it's Implementing CommandExecutor
     
  5. When making a task it needs an instance of the class extending JavaPlugin passed in, else it wont work, either make a constructor for the command and pass the plugin in there, or make a static instance getter.
     
  6. I have!

    FULL CODE:

    Code (Text):
    package ChatFilter;

    import java.util.HashSet;
    import java.util.Set;

    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.plugin.Plugin;
    import me.DecisionsYT.Main;

    public class AntiSpam implements Listener {
       
    Main plugin;
       
        public AntiSpam(Main passedPlugin) {
            this.plugin = passedPlugin;
           
       
          }
       
       
      Set<String> antispam = new HashSet<String>();
      long time;


    @EventHandler
      public void onPlayerChat(AsyncPlayerChatEvent e) {
       Player player = e.getPlayer();

        this.time = plugin.getConfig().getLong("AntiSpam-Cooldown");
        this.time *= 20L;

        boolean spamhas = this.antispam.contains(player.getName());
        if (!player.hasPermission("ChatX.AntiSpam.Bypass")) {
          if (!spamhas) {
            this.antispam.add(player.getName());
            plugin.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                public void run() {
                AntiSpam.this.antispam.remove(player.getName());
              }
            }
            , this.time);
          } else {
            e.setCancelled(true);
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("AntiSpam-Message")));
                  }
            }
          }
    }
    The Main class (not shown here) checks if a command is run (for instance /heal) then finds the Class defined.
     
  7. So many errors doing that...
     
  8. Show me
     
  9. No you haven't.
    You passend the instance of the main class but you never used it.
     
  10. Look. The way I've done it, IS NOT causing the errors, I can prove this a number of ways. On including, other commands I've done are working.

    MAIN CLASS:

    Code (Text):
    package me.DecisionsYT;

    import org.bukkit.Bukkit;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    import ChatChannels.DonorChat;
    import ChatChannels.StaffChat;
    import ChatFilter.AntiSpam;
    import ChatFilter.AntiSwear;
    import ChatFilter.LockChat;
    import ChatFilter.Mute;
    import ClearChat.ClearChat;
    import Events.Join;
    import Events.Quit;
    import HelpCommand.Help;
    import Links.Shop;


    public class Main extends JavaPlugin implements Listener {

        public void onEnable() {
           
              saveDefaultConfig();
           
             
              //Events
              PluginManager pm = Bukkit.getServer().getPluginManager();
              LockChat lockChat = new LockChat(this);
              pm.registerEvents(this, this);
              pm.registerEvents(new AntiSwear(this), this);
              pm.registerEvents(lockChat, this);
              pm.registerEvents(new Join(this), this);
              pm.registerEvents(new Quit(this), this);
              pm.registerEvents(new Mute(this), this);
              pm.registerEvents(new AntiSpam(this), this);
             
              //Chat Channels
              getCommand("SC").setExecutor(new StaffChat(this));
              getCommand("StaffChat").setExecutor(new StaffChat(this));
              getCommand("DC").setExecutor(new DonorChat(this));
              getCommand("DonorChat").setExecutor(new DonorChat(this));
             
              //ClearChat
              getCommand("ClearChat").setExecutor(new ClearChat(this));
              getCommand("CC").setExecutor(new ClearChat(this));
             
              //LockChat
              getCommand("LockChat").setExecutor(lockChat);
             
              //Help
              getCommand("ChatX").setExecutor(new Help(this));
             
              //Links
              getCommand("Buy").setExecutor(new Shop(this));
              getCommand("Shop").setExecutor(new Shop(this));
              getCommand("Rules").setExecutor(new Shop(this));
              getCommand("Website").setExecutor(new Shop(this));
             
              //Mute
              getCommand("Mute").setExecutor(new Mute(this));
             
             
           
             
              Bukkit.getServer().getConsoleSender().sendMessage("§b§lChatChannels+ has been enabled!");
        }
       
        public void onDisable() {
           
            Bukkit.getServer().getConsoleSender().sendMessage("§b§lChatChannels+ has been enabled!");
           
        }
       
       
    }
     
     
    • Optimistic Optimistic x 1
  11. Agree,
    On top, u used:
    Main plugin;
    But then
    U used (this, new Runnable())
    Instead of this put plugin
     
  12. The way i told u before is best
     
  13. Aha!

    Worked! Thanks alot!
     
Thread Status:
Not open for further replies.