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; }
Teleport All Command
Teleport All Command
Anyone know why this does not want to work? The YML is setup fine.
Last edited by Carnexo on Thu Jun 21, 2012 9:26 pm, edited 1 time in total.
Re: Multi Teloport All Commands
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
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
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
Hmm okay
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
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