What is wrong with this?

Discussion in 'Plugin Development' started by Woobie, Nov 9, 2012.

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

    Woobie

    Code:
    @EventHandler
        public void onJoin(final PlayerJoinEvent e){
            System.out.println("1");
            this.getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
                public void run(){   
                    if(Bukkit.getServer().getOnlinePlayers().length == getConfig().getInt("players")){
                        System.out.println("2");
                    startCountDown(e.getPlayer());
                }
            }
        }, 10L);
    }
    On join, if 'x' amount of players are online, start task.
    It never got the the 2nd debug.. whats wrong?

    My config:
    Code:
    players: 1
     
  2. Offline

    andf54

    Since the code seems ok, I think the reason is that getConfig().getInt("players") is wrong or null;
    something == null is false (unless null)

    What does
    System.out.println(Bukkit.getServer().getOnlinePlayers().length + "==" + getConfig().getInt("players") + "?");
    give?

    Place it before if(Bukkit.getServer()...
     
  3. Offline

    Woobie

    Code:
    1==10?
    Means that it should work.

    Code:
    Bukkit.getServer().getOnlinePlayers().length
    is equals to "1"

    then

    Code:
    + "==" + 
    Obviously equals to the "=="

    Code:
    getConfig().getInt("players")
    And then the int from config, which is 10

    EDIT: Oops, dumb me, just a sec :p
     
  4. Offline

    andf54

    It only works when you have 10 players online. Change to >=

    My derp, sry.
     
  5. Offline

    Woobie

    Okay.. so I found the problem I had all the time.
    Code:
        @EventHandler
        public void onJoin(final PlayerJoinEvent e){
            System.out.println("1");
            this.getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
                public void run(){
                    System.out.println(Bukkit.getServer().getOnlinePlayers().length + "==" + getConfig().getInt("players") + "?");
                    if(Bukkit.getServer().getOnlinePlayers().length == getConfig().getInt("players")){
                        System.out.println("2");
                    startCountDown(e.getPlayer());
                }
            }
        }, 10L);
    }
                @EventHandler
                public void startCountDown(final Player p){
                    System.out.println("3");
    It never got to the 3rd debug, and that is becouse I forgot the @EventHandler ontop of my method.

    But now back to the old problem.. this is not working, any idea why?
    Code:
    @EventHandler
                public void startCountDown(final Player p){
                    System.out.println("3");
                    Countdown = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                        int count = 180;
                        public void run() {
                            count--;
                       
                            if(count == 180){
                                Bukkit.broadcastMessage(ChatColor.GREEN+ "[FF] 3 minutes until next game!");
                                count--;
                            }
                       
                            if(count == 60){
                                Bukkit.broadcastMessage(ChatColor.GREEN+ "[FF] 1 minute until game starts!");
                                count--;
                            }
               
                            if(count == 30){
                                Bukkit.broadcastMessage(ChatColor.GREEN+ "[FF] 30 seconds until game starts!");
                                count--;
                            }
                         
                            if(count == 15){
                                Bukkit.broadcastMessage(ChatColor.GREEN+ "[FF] 15 seconds until game starts!");
                                count--;
                             
                            }
                         
                            if(count < 10){
                                Bukkit.broadcastMessage("[FF] " +count+ " seconds until game starts!");
                                count--;
                         
                            }
                            if(count == 0){
                                count--;
                                System.out.println("4");
                                Bukkit.broadcastMessage(ChatColor.DARK_GREEN+ "[FF] Game starts NOW!");
                                Bukkit.broadcastMessage(ChatColor.DARK_GREEN+ "[FF] You have 10 minutes to build your fort!");
                                gameOn = true;
                                startCountdown2(p);
                                Bukkit.getScheduler().cancelTask(Countdown);
                            }         
                        }
                    }, 0L, 20L);
                }
        
    EDIT: This MIGHT (lol) have something to do with it, but when I launch my server, I see these lines:

    Lalallala attempted to register an invalid EventHandler method signature "me.woobie.lalallalala.Main.startCountDown<org.bukkit.entity.player>"
     
  6. Offline

    maxp0wer789

    I can't see an obvious mistake if it is: "players: 1" in the config.
    Code:
    getConfig().getInt("players")
    if this is 10 like u stated above, it won't work of course ;)
    Also: u want the task to start when
    Code:
    if(Bukkit.getServer().getOnlinePlayers().length == getConfig().getInt("players"))
    is true, but u start the task and THEN check if the condition is true.

    If u need further help post your whole class.

    greetings maxp0wer
     
  7. Offline

    Woobie

    Actually I start the task after I checked the int from the config
    Code:
    if(Bukkit.getServer().getOnlinePlayers().length == getConfig().getInt("players")){
              System.out.println("2");
              startCountDown(e.getPlayer());
     
  8. Offline

    maxp0wer789

    u tell the compiler that startCountDown() is an EventHandler method which it isn't, remove the @EventHandler annotation ontop of the method

    no, actually u are starting two tasks ;), on in the onJoin() method another one in the startCountDown(), which starts a new task everytime the registered task in onJoin() gets executed.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  9. Offline

    Woobie

    Oh.. I thought the problem was that I was missing them, that's why I added it to the rest of the methods..

    Well any ideas why the first one wasnt launching, even though I didnt have the @EventHandler?
     
  10. Offline

    andf54

    You should get to 3rd debug only if you have precisely 10 players online.

    You don’t need EventHandler for normal methods. Also, fix your tabs in run() method.

    You also might want to do:
    if(Bukkit.getServer().getOnlinePlayers().length >= getConfig().getInt("players") && !isGameRunning()){ ... }
     
  11. Offline

    maxp0wer789

    is what u said. so if you wrote in your config player: 1, check if your config gets loaded properly.
    you can send me your whole code via pm (if u don't want to post it here), if u need more accurate help

    Edit: andf54 is right, if you have more than 10 players on your server, or less then 10, the method will not get executed, change the operator to >=
     
  12. Offline

    Woobie

    Edited my post earlier :D
    "EDIT: Oops, dumb me, just a sec :p"

    Still not launching.. I'll pm you the code.
     
  13. Offline

    andf54

    Ofc it does nothing. You need (at least) 10 players online. You test it with only 1 player (yourself).
    Change your config to 1;
     
  14. Offline

    Woobie

    I am testing it with 1 player online, and it still doesnt launch.
    I edited the config to need only 1 player online to launch, and it got to the 3rd debug, which is just before the first scheduler, but no further, it stopped there.
     
Thread Status:
Not open for further replies.

Share This Page