How to make a player variable compatible with a string

Discussion in 'Plugin Development' started by OptimalBread, Aug 10, 2014.

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

    OptimalBread

    How do I make this work?
    Code:java
    1. Player del = pl.getDisplayName();
    One is player and the other is a string but how would i make that work?
     
  2. Offline

    yupie_123

    Ehm, I believe you want to do: Player del = getServer().getPlayer(pl.getName())
     
  3. Offline

    CullanP

    Would you show the string? I'm a bit confused with what you're trying to do. I understand you're trying to make a string compatible with player, but what are you trying to do with it
     
  4. Offline

    yupie_123

    Edit: it is pl.getName() and not display name!
     
  5. Offline

    OptimalBread

    CullanP So here is what I want to use it for:
    Code:java
    1. List<Player> players = Bukkit.getServer().getWorld(p.getWorld().getName()).getPlayers();
    2. for (Player pl : players) {
    3. Player del = pl.getName();
    4. del.teleport(new Location(... Info));
    5.  
    6.  
    7. }

    I am trying to get a list of all players in a world and teleport them somewhere when a command is called. But when I do p.sendMessage(Bukkit.getServer().getWorld(p.getWorld().getName()).getPlayers()); it shows [CraftPlayer{name=Caamflyer64}] so the teleport part has no clue what to teleport. But p.sendMessage(pl.getName()); displays the name correctly but as a string and not a player for teleport. Does this clear somethings up?
     
  6. Offline

    CullanP

    OptimalBread
    Code:
    for(Player pl : Bukkit.getOnlinePlayers()) {
    Player del = pl.getPlayer();
    Instead of using a list, try what I used above
     
  7. Offline

    patey

    are you trying to get all players online in one world and teleport them somewhere?
     
  8. Offline

    CullanP

    Oh. If he's trying to only teleport players in the one world that the command is issued then I'll change what I posted
     
  9. Offline

    _Cookie_

    String name = pl.getDisplayName();

    ??
     
  10. Offline

    OptimalBread

    CullanP Yea patey has it right. all players in one world
     
  11. Offline

    Necrodoom


    First off, why aren't you using the existing p.getWorld() and instead getting the same world by going name and back?
    Also, you can't just print a list or a player object.

    You haven't really explained the problem however.
     
  12. Offline

    patey

    Code:java
    1. for (Player p: Bukkit.getServer().getOnlinePlayers()) {
    2.  
    3. if (p.getWorld().getName().toLowerCase().equals("world")){
    4. p.teleport(location)
    5. }
    6.  
    7. }


    that might do it
     
  13. Offline

    mythbusterma

    patey

    A World will never be equal to a String under any circumstance. Try again.
     
  14. Offline

    patey

  15. Offline

    TheWolfBadger

    patey Yes, but you need a location specified.
     
  16. Offline

    patey

    thats intentional. OptimalBread probably knows where he's sending the player
     
  17. Offline

    1Rogue

    Code:java
    1. Location loc = /* your location to teleport to */;
    2. for (Player p : p1.getWorld().getPlayers()) {
    3. p.teleport(loc);
    4. }
     
  18. Offline

    Rocoty

    Just take some steps back please. Learn Java. Learn Bukkit. Then come back here and the answer to your question should be pretty obvious.
     
Thread Status:
Not open for further replies.

Share This Page