Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
StopCommand.java
1 package org.bukkit.command.defaults;
2 
3 import java.util.List;
4 
5 import org.apache.commons.lang.StringUtils;
6 import org.apache.commons.lang.Validate;
7 
8 import org.bukkit.Bukkit;
11 import org.bukkit.entity.Player;
12 
13 import com.google.common.collect.ImmutableList;
14 
15 public class StopCommand extends VanillaCommand {
16  public StopCommand() {
17  super("stop");
18  this.description = "Stops the server with optional reason";
19  this.usageMessage = "/stop [reason]";
20  this.setPermission("bukkit.command.stop");
21  }
22 
23  @Override
24  public boolean execute(CommandSender sender, String currentAlias, String[] args) {
25  if (!testPermission(sender)) return true;
26 
27  Command.broadcastCommandMessage(sender, "Stopping the server..");
28  Bukkit.shutdown();
29 
30  String reason = this.createString(args, 0);
31  if (StringUtils.isNotEmpty(reason)) {
32  for (Player player : Bukkit.getOnlinePlayers()) {
33  player.kickPlayer(reason);
34  }
35  }
36 
37  return true;
38  }
39 
40  @Override
41  public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
42  Validate.notNull(sender, "Sender cannot be null");
43  Validate.notNull(args, "Arguments cannot be null");
44  Validate.notNull(alias, "Alias cannot be null");
45 
46  return ImmutableList.of();
47  }
48 }
boolean testPermission(CommandSender target)
static void shutdown()
Definition: Bukkit.java:406
void setPermission(String permission)
static Player[] getOnlinePlayers()
Definition: Bukkit.java:94