Detect in what world is a player

Discussion in 'Plugin Development' started by 3751_Creator, Jan 15, 2013.

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

    3751_Creator

    Hello Bukkit community,

    Basicly, I would like to be able to list all the worlds on my server and tell what players they are in.

    EG: (this after command is executed)
    List of worlds:
    PVP:
    - P1
    - CER
    - 123_Player

    Nether:
    - fr
    - azer
    - 123456789

    End:
    NONE

    Thanks to all of you, ~3751_Creator
     
  2. Offline

    slater96

    Something along the lines of
    Code:
    for (Player player : Bukkit.getOnlinePlayers()) {
        if (p.getWorld().getName().equalsIgnoreCase(args[0]) {
            event.getPlayer().sendMessage("> " + player.getName());
     
  3. Offline

    3751_Creator

    Not working....
     
  4. Offline

    caxco93

  5. Offline

    3751_Creator

    Thanks a lot caxco93.

    If you d'ont mind, now I would like to do like /ww world see <Specifique world name>
    (I only need the thing so that it "scans" the arg and looks if there is a world called like that)
     
  6. Offline

    devilquak


    Code:
    if(Bukkit.getServer().getWorld(args[0]) != null)
    {
        for(Player p : args[0].getPlayers())
        {
            sender.sendMessage("- " + p.getName());
        }
    }
    
    Edit: Wow, having a lot of formatting issues.
     
  7. Offline

    3751_Creator

    Not working...
     
  8. devilquak
    6 edits. It must have been bad ;).

    3751_Creator
    Post what isn't working, more information would help us help you :).
     
  9. Offline

    turt2live

    You are not going to get code handed to you.
    You'll have to try a majority of things on your own
     
  10. Offline

    devilquak

    Sorry, I think I see an error I made:

    Code:
    if(Bukkit.getServer().getWorld(args[0]) != null)
    {
        for(Player p : Bukkit.getServer().getWorld(args[0]).getPlayers())
        {
            sender.sendMessage("- " + p.getName());
        }
    }
    Regardless of whether that works or not, if you're having a problem, the only way we can help is if you show us what you've got. So if this doesn't do it, let us see what you're trying to do.
     
  11. Offline

    3751_Creator

    Code:
    if(args.length == 2){
                    String arg11 = args[0];
                    String arg2 = args[1];
                    if(arg11.equalsIgnoreCase("show") && arg2.equalsIgnoreCase("all")){
                        pl.sendMessage("§cLites des mondes disponibles avec leurs joueurs:");
                        for( World w : Bukkit.getWorlds()) {
                            pl.sendMessage("§6" +w.getName()+"§6:");
                            pl.sendMessage(" ");
                            for( Player p : w.getPlayers()) {
                                    pl.sendMessage("§c- "+p.getName());
                            }
                        }
                    }else
                    if(arg11.equalsIgnoreCase("show")){
                        if(Bukkit.getServer().getWorld(args[1]) != null)
                        {
                            for(Player p : Bukkit.getServer().getWorld(args[0]).getPlayers())
                            {
                                sender.sendMessage("- " + p.getName());
                            }
                        }
                     
                    }
                }if(args.length == 2){
                    String arg11 = args[0];
                    String arg2 = args[1];
                    if(arg11.equalsIgnoreCase("show") && arg2.equalsIgnoreCase("all")){
                        pl.sendMessage("§cLites des mondes disponibles avec leurs joueurs:");
                        for( World w : Bukkit.getWorlds()) {
                            pl.sendMessage("§6" +w.getName()+"§6:");
                            pl.sendMessage(" ");
                            for( Player p : w.getPlayers()) {
                                    pl.sendMessage("§c- "+p.getName());
                            }
                        }
                    }else
                    if(arg11.equalsIgnoreCase("show")){
                        if(Bukkit.getServer().getWorld(args[1]) != null)
                        {
                            for(Player p : Bukkit.getServer().getWorld(args[0]).getPlayers())
                            {
                                sender.sendMessage("- " + p.getName());
                            }
                        }
                     
                    }
                }
    The part where I need help is here:
    Code:
          if(arg11.equalsIgnoreCase("show")){
                        if(Bukkit.getServer().getWorld(args[1]) != null)
                        {
                            for(Player p : Bukkit.getServer().getWorld(args[0]).getPlayers())
                            {
                                sender.sendMessage("- " + p.getName());
                            }
                        }
     
  12. Offline

    fireblast709

    3751_Creator you check if world args[1] exists, and then you try getting the players from world args[0] ;3.

    Either use args[0] or args[1] (whichever is the worldname)
     
  13. Offline

    devilquak

    3751_Creator

    Just a tip, if you want me to see your replies, either click "Reply" or tag me in your post by clicking "Tahg".

    Where it says args[0] and args[1], you need to put the same string in there that you want to convert into a world. If you type /<something> show world_nether, you would put args[1] in both of those lines. It's attempting to match args[1], in this case "world_nether", with a world, and both strings in these lines need to be the same for it to succeed.
     
  14. Offline

    microgeek

    I've posted tis in other threads, but to looks like you know very little Java and/or have not read any JavaDocs on the Api. Also putting 'Not working......' is not very helpful. try debugging on your own, and don't just copy and paste other people work.

    It would be a simple for loop and a few if statements.
     
Thread Status:
Not open for further replies.

Share This Page