how to get all online players teleported on command

Discussion in 'Plugin Development' started by RuthlessRage, Nov 20, 2014.

?

Which would you play most

  1. Factions

    12.5%
  2. Kit-Pvp

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

    RuthlessRage

    id like to type /here and have all players on server teleport to me. sorry english not very good. but i understand i will have to use getlocation of my player correct?
     
    ChipDev likes this.
  2. Offline

    Burnsalan18

    Just so you know, you double posted the thread. But in an on topic note this is what you need:
    Code:
    for (Player player : Bukkit.getOnlinePlayers()) {
     
    player.teleport(new Location(world, x,y,z));
    }
    That will get all online players and teleport them to the location.
     
  3. Offline

    xTrollxDudex

    For-each online players, teleport to player location.
     
  4. Offline

    Creeoer

    Ehh, what's with the poll?
     
  5. Offline

    Burnsalan18

  6. Offline

    RW_Craft

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. Player p = (Player) sender;
    3. if (cmd.getName().equalsIgnoreCase("mycommand")) {
    4. for (Player players: Bukkitfor (Player player : Bukkit.getOnlinePlayers()) {
    5. World w = p.getLocation().get world();
    6. double x = p.getLocation().getX();
    7. double y = p.getLocation().getY();
    8. double z = p.getLocation().getZ();
    9. p.teleport(new Location(w, x, y, z));
    10. }
    11. }
    12. return true:
    13. }
     
  7. Offline

    mythbusterma

    RW_Craft

    So this thread was going well. Then you come in and spoonfeed in some pretty awful code. Please refrain from trying to write code for others in the future.
     
    ROTN likes this.
  8. Offline

    Burnsalan18

    Butthurt much?
     
    TheOatBaron and ChipDev like this.
  9. Offline

    ChipDev

    So much wrong bro.

    *You create 4 new variables every time it loops through the player list.
    *Your code does NOT compile!!?
    *You are spoon feeding
    *Return true: ? no, ; bro.
    Burnsalan18 Yes, butthurt much, but he has a point..
     
  10. Offline

    AoH_Ruthless

    ChipDev
    • Spoon feeding is technically not an inherent error in itself.
    • Why are you against the concept of returning true? It is necessary in a boolean method. What would you advise?
    • By "wrong", it might also be fair to point out that a cast is performed without any sort of instance check, and that the for loop is incoherent.
    Burnsalan18
    No need for insults, especially since the code is indeed nonsensical.
     
  11. Offline

    mythbusterma


    Yes, I am, spoonfeeding shit-tier code makes me upset.
     
  12. Offline

    Burnsalan18

    Take a chill pill, sit back, and relax. Dont worry about the crap code he posted. At least it was helpful, which is why we are here correct?

    Sorry, the insult was uncalled for, but atleast now the use has something to build on, even if the code was bad.

    <Edit by mrCookieSlime: Merged Posts. Please dont double post. There is an Edit-Button right next to the Date.>
     
  13. Offline

    AoH_Ruthless

    Burnsalan18
    Not really, the code was incorrect, inefficient, and made use of bad practices.
     
  14. Offline

    Burnsalan18

    But now he has something to learn how to fix himself. If the code was bad, then nothing was spoonfed.

    Edit: But it is kinda hard to help his case sense hes not asking questions about the code.
     
  15. Offline

    teej107


     
  16. Offline

    mythbusterma



    Not really, he's going to copy/paste that and then completely ignore the comments, which is why it's so upsetting.
     
  17. Offline

    Burnsalan18

    teej107 lol good job.

    mythbusterma Well if he wants a good plugin, he will ask questions on how to make it better. I dont care either way.
     
  18. Offline

    ChipDev

    He put : not ; for return true;
     
  19. Offline

    Burnsalan18

    Meh
     
  20. Offline

    RW_Craft

    ChipDev I wrote it on a phone with autocorrect, I promise I typed ; but it auto corrected (It kept changing works like getName() to get name)
     
    ChipDev likes this.
  21. Offline

    AronTheGamer

    onCommand 'here'
    - check if sender is player
    - if it's a player, loop through every online player
    - teleport the player in the loop to ((Player) sender).getLocation();
     
  22. Offline

    ChipDev

    Oh! Ok.
     
  23. Offline

    TheOatBaron

    Improved code where Player p is the sender. Part of the code was messing with Bukkit post format so I am linking to pastebin. http://pastebin.com/54HKzPh6
     
  24. Offline

    teej107

    TheOatBaron You can make your code segment compatible with older and newer Bukkit versions by just using a for-each loop
     
    AoH_Ruthless likes this.
  25. Offline

    RuthlessRage

    thanks for th ehelp,
     
Thread Status:
Not open for further replies.

Share This Page