[Solved] Game Starter

Discussion in 'Spigot Plugin Development' started by Just_Jitse, Jul 10, 2015.

  1. Helloww people,
    I ran into a problem with this method and I already had a look at the stack trace but I don't really know how to solve it :s
    could someone help me?

    Code (Java):

        public static void StartTimer(){
            /*int task = */Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.plugin, new Runnable() {
               
                @Override
                public void run() {
                    if(Bukkit.getOnlinePlayers().size() >= 2){
                        Start.canStart = true;
                        GameState.setState(GameState.IN_GAME);
                    }else{
                        Start.canStart = false;
                    }
                    if(GameState.isState(GameState.IN_GAME)){
                        Game.Start.onStart();
                        //Bukkit.getScheduler().cancelTask(task);
                    }
               
                }
            }, 20, 20);
        }
     
  2. Post your Error, so we can see directly where your issue is
     
  3. @Moebius__ ah yeah ofcource, here it is:

    [​IMG]

    Code (Text):
            /*int task = */Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.plugin, new Runnable() {
    is line 47

    and

    Code (Text):
            StartTimer();
    is line 17

    EDIT: MERGED POST
     
    #3 Just_Jitse, Jul 10, 2015
    Last edited: Jul 10, 2015
  4. This is just a wild guess, but I think you're using two plugins here. One of them is called "Core". You need to make sure that Core is initialized before the StartTimer method is called. You can do so by adding Core as a depend for your plugin.
     
  5. @CoKoC No it's the main class, but I set the variable after calling the method. Which was the problem -,-
    oh well, ty!
     
  6. Initialize Core.plugin in onEnable().
    Code (Text):
    plugin = this;
     
  7. indeed, I called StartTimer(); before Core.plugin = this; which caused the problem @Web_
     
  8. But how would I cancel the task btw?

    something like this? But it says that the local variable may not have been initialized.

    Code (Java):

        public static void StartTimer(){
            int task = Bukkit.getScheduler().scheduleSyncRepeatingTask(Core.plugin, new Runnable() {
             
                @Override
                public void run() {
                    if(Bukkit.getOnlinePlayers().size() >= 2){
                        Start.canStart = true;
                        GameState.setState(GameState.IN_GAME);
                    }else{
                        Start.canStart = false;
                    }
                    if(GameState.isState(GameState.IN_GAME)){
                        Game.Start.onStart();
                        Bukkit.getScheduler().cancelTask(task);
                    }
             
                }
            }, 20, 20);
        }
     
  9. oh, nobody seems to want to help me. Okay, thx I guess.... :(
    Solved the problem myself, static ftw!