Tpall command

Discussion in 'Plugin Development' started by DaanSander, Feb 5, 2015.

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

    DaanSander

    does someone know how to make a /tpall command that teleports all the players to the sender
     
  2. Offline

    nverdier

    ChipDev likes this.
  3. Code:java
    1.  
    2. public voic tpAll(Player player) {
    3. for(Player online : Bukkit.getOnlinePlayer()) {
    4. if(player.getUniqueId().equals(online.getUniqueId())) { continue; }
    5. online.teleport(player);
    6. }
    7. }
    8.  
     
  4. Offline

    _Filip

    @MaTaMoR_ that wont work. Learn java.

    EDIT: Oops I didn't see the continue statement bit as I posted that on mobile..
     
    Last edited: Feb 6, 2015
    Datdenkikniet likes this.
  5. Offline

    fandemangas42

  6. Offline

    1Rogue

    It has the general idea (minus typos). Though I would teleport everyone in the world, not the server (as cross-world teleportation usually isn't a desired effect of a tpall command).
     
  7. Sure :D
     
  8. Offline

    Minesuchtiiii

    I'd do it like this:
    Code:
    public void tpAll(Player p) {
    
    for(Player all : Bukkit.getOnlinePlayers()) {
    if(all != p) {
    all.teleport(p);
    
    }
    else {
    return;
    }
    
    }
     
    Huffmanbran likes this.
  9. Offline

    DaanSander

    when i try that its says: Ambiguous method call. both
     
  10. Offline

    Huffmanbran

    That's your best bet.

    Is it an actual error or warning? Eclipse likes to be precise :p

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

    DaanSander

    its a actual warning and i use inteliJ
     
  12. Offline

    Minesuchtiiii

  13. Offline

    1Rogue

    Method ambiguity is a compile-time error. Additionally your code example is filled with bad formatting and logic errors
     
  14. Offline

    DaanSander

    but what do i have to do then??
     
  15. Offline

    BaconStripzMan

    Code:java
    1.  
    2. @Override
    3. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    4. if(cmd.getName().equalsIgnoreCase("tpall")){
    5. if(sender instanceof Player){
    6. Player p = (Player) sender;
    7. for(Player o : Bukkit.getOnlinePlayers()){
    8. if(o != p){
    9. if(o.getLocation().getWorld() == p.getLocation().getWorld()){
    10. o.teleport(p);
    11. }
    12. }
    13. }
    14. }
    15. }
    16. return false;
    17. }
     
    Last edited: Feb 8, 2015
Thread Status:
Not open for further replies.

Share This Page