Solved Scheduler problems out of main class

Discussion in 'Plugin Development' started by _Ogle, Mar 25, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    _Ogle

    Code:
                    if (KPMain.HappyHour == false);
                    {
                        //if happy hour is off
                        Happyhours.put(sender.getName(), happyHour - 1);
                        KPMain.HappyHour=true;
                        //make happyhour on
                        Bukkit.broadcastMessage(ChatColor.RED + "Happy Hour Activated by " + sender.getName());
                        //let them know now wait an amount of time until it comes back on
                        plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
                            public void run()
                            {
                                //run this after the delay
                                Bukkit.broadcastMessage(ChatColor.RED + sender.getName() + "'s Happyhour has ended");
                                KPMain.HappyHour=false;
                            }
                        }, 100L);
                        return true;
                    }
    So my problem is that everything works but the scheduler part, It says an internal server error occurs. Also know that this is not the main class yet a class specifically for this command. this is a part of code in the command that is not working because I am not 100% sure how the scheduler works. I have the line
    Code:
    Main plugin;
    at the top so thats not the issue. Help is appreciated, Thanks ;)
     
  2. Offline

    mehboss

    Any errors?

    EDIT #1:
    You should be setting the variable "plugin" like so
    Code:
        private MAINCLASSS plugin;
    
        public YOURCLASS(MAINCLASS plugin) {
            this.plugin = plugin;
        }
    You could also do:
    Code:
    Plugin plugin = Bukkit.getPluginManager().getPlugin("YOURPLUGIN");
     
  3. Offline

    _Ogle

    So i tried what you said by setting the plugin variable like this:
    Code:
        private KPMain plugin;
        public HappyHourKP(KPMain plugin)
        {
            this.plugin = plugin;
        }
    
    But now I'm getting an error in the main class calling this command
    Code:
    this.getCommand("happyhour").setExecutor(new HappyHourKP());
     
  4. Offline

    Zombie_Striker

    @_Ogle
    You have to provide the main instance in the HappyHourKP constructor. Just add "this" to the parameters.
     
  5. Offline

    _Ogle

    oh, duh. sry works fine now guys ty :)
     
Thread Status:
Not open for further replies.

Share This Page