Teleport All Command

Any help topics that don't fit in the current categories can go here.
Post Reply
Carnexo
Posts: 2
Joined: Thu Jun 21, 2012 6:59 pm

Teleport All Command

Post 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;
		}
Last edited by Carnexo on Thu Jun 21, 2012 9:26 pm, edited 1 time in total.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Multi Teloport All Commands

Post 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 :)
Image
Carnexo
Posts: 2
Joined: Thu Jun 21, 2012 6:59 pm

Re: Teleport All Command

Post 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!
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Teleport All Command

Post 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 ;)
Image
Post Reply