Page 1 of 1

Teleport All Command

Posted: Thu Jun 21, 2012 7:19 pm
by Carnexo
Anyone know why this does not want to work? The YML is setup fine.
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
			Player player = (Player)sender;
			if (commandLabel.equalsIgnoreCase("startgame")) {
				Location location = new Location(Bukkit.getWorld("world"), -31, 69, 7);
				Player [] players = getServer().getOnlinePlayers();
				for (int count = 0; count < players.length; count++){
				Player currentPlayer = players[count];
				currentPlayer.teleport(location);				 
				}
			return true;
			}
			if (commandLabel.equalsIgnoreCase("endgame")) {
				Location location = new Location(Bukkit.getWorld("world"), 0, 65, 0);
				Player [] players = getServer().getOnlinePlayers();
				for (int count = 0; count < players.length; count++){
					Player currentPlayer = players[count];
					currentPlayer.teleport(location);
				}
				return true;
			}
			return false;
		}

Re: Multi Teloport All Commands

Posted: Thu Jun 21, 2012 8:17 pm
by jacek
How does it not work ? What happens instead of what you expect ? As far as I can see there is nothing wrong, is the command registered in your plugin.yml file ?

Also a little tip, you can use a foreach loop instead of your for so you can do
for (Player currentPlayer : getServer().getOnlinePlayers()){
    currentPlayer.teleport(location);
}
Just a little bit neater :)

Re: Teleport All Command

Posted: Thu Jun 21, 2012 9:25 pm
by Carnexo
It didn't want to work for some reason, I figured out the problem though, for some reason my files were not being exported or uploaded correctly. (derp) But, before I figured that out.I just deleted it and did an onPlayerChat event instead to run the command. Which worked out. Thanks for the help!

Re: Teleport All Command

Posted: Thu Jun 21, 2012 10:33 pm
by jacek
Hmm okay :D

You're not really meant to do commands form the chat event though. I did a video on the correct way to do them which might be useful ;)