Solved getOnlinePlayers() doesnt work!?

Discussion in 'Plugin Development' started by Schaakmatth, May 27, 2014.

Thread Status:
Not open for further replies.
  1. ZRC2011 Which method? The this.getServer().getOnlinePlayers()? Yes, that will work fine a lot of the time, but move it to a class that isn't your main class. It won't work. You'll have to change to using an instance of your main class, whereas Bukkit.getOnlinePlayers() both exists and would work without adjusting.

    Schaakmatth I'd be surprised if no dutch tutorials for Java existed.
     
  2. Offline

    ZRC2011

    AdamQpzm it would be better to get the referal to the server, from a player etc. It is very easy to make a variable in the main class which is static and assign it to the Server Therefore Plugin.server.getOnlinePlayers would work elsewhere... I do it enough
     
  3. Offline

    Schaakmatth

    AdamQpzm there are tutorials in dutch but not with else ifs but by the way heres the code:
    Code:java
    1. @EventHandler
    2. public void PlayerJoin(PlayerJoinEvent e) {
    3. final Player p = e.getPlayer();
    4. final World world1 = p.getWorld();
    5. Location loc = new Location(world1, 112, 1, 66);
    6. p.teleport(loc);
    7. p.getInventory().clear();
    8.  
    9. //waitTimer
    10. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    11. public void run() {
    12. if(Bukkit.getServer().getOnlinePlayers().length == 2) {
    13. Location loca = new Location(world1, 182, 1, 71);
    14. p.teleport(loca);
    15. Bukkit.broadcastMessage(ChatColor.GREEN + "FIGHT!!!");
    16. }
    17.  
    18. }
    19. }, 20 * 10);
    20.  
    21. } else if(Bukkit.getServer().getOnlinePlayers().length == 2){ //error on else Syntax error on "else" , delete this token
    22. Bukkit.broadcastMessage("You will be teleported in 10 seconds...");
    23. }
    24. } else if(Bukkit.getServer().getOnlinePlayers().length == 1) { //error on else Syntax error on "else" , delete this token Bukkit.broadcastMessage(ChatColor.RED + "Need 1 Player");
    25. }
    26.  
    27. }
    28. }
     
  4. ZRC2011 ... You could break the rules for encapsulation sure, but again why would you? You seem to have some sort of strange bias against the Bukkit class for no reason. For the record, it just refers to Server anyway. I'm not saying that you shouldn't use Server (but I am saying that you shouldn't use Plugin.server) but your original point that Bukkit.getOnlinePlayers() didn't exist is completely invalid.

    Schaakmatth That's not likely to be true - any non-terrible basic tutorial would include if-then-else, and I find it hard to believe that none of those exist.
     
  5. Offline

    ZRC2011

    I didn't say it doesn't exist. I just don't trust using it, as I have done before and its resulted in many errors, you seem as if you know what you are doing, are you able to help me with an issue I'm facing with my current project please
     
  6. Offline

    1Rogue

    Code:java
    1. if (/* boolean condition 1 */) {
    2. //do stuff
    3. } else if (/* boolean condition 2 */) {
    4. //do stuff
    5. } else if (/* boolean condition 3 */) {
    6. //do stuff
    7. } else {
    8. //do stuff
    9. }



    Bukkit.getOnlinePlayers(), and JavaPlugin#getServer().getOnlinePlayers() both point to the same method

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  7. Offline

    ZRC2011

    I have opened a Thread but no one has yet replied could you? Don't wanna post link here cause this guy still needs hit problem fixed, and a link would take people away from here
     
  8. Offline

    Schaakmatth

    whats a boolean condition? 1Rogue
     
  9. Offline

    Necrodoom

    Please stop filling this thread with offtopic, not only you are giving the OP bad advice but also derailing the topic.
    Also, for a fact, you have never actually posted a thread about your problem with bukkit class.
     
  10. Offline

    ZRC2011

    I was on about a different topic hence why I didn't want to link it if it was about the bukkit class I would have done as it is slightly related and might actually help however it's about something different some doesn't matter
     
  11. Offline

    Schaakmatth

    ok still i dont know why that else if doesnt work ....
     
  12. Schaakmatth Question: Which if does the else come directly after?
     
  13. Just stop helping this guy. He's clearly crying for free code and he doesn't even understand half of what you guys post here. Just stop. This thread has been in the front page for 3 days in a row with him constantly begging for spoonfeeding.
     
  14. Offline

    Schaakmatth

    ok found someone thats dutch and want to help me i think CLOSE THIS THREAD!

    Solved!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page