summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDinnerbone <dinnerbone@dinnerbone.com>2011-09-03 04:37:23 +0100
committerDinnerbone <dinnerbone@dinnerbone.com>2011-09-03 15:56:35 +0100
commit1fd394bc7c15246d72b9957f62f79454663182d4 (patch)
treef8536016e166cce0684740189dfb307f0a4bb5ac
parenteecc6f1252b787d6740df2f5cc81058353b60fe9 (diff)
downloadbukkit-1fd394bc7c15246d72b9957f62f79454663182d4.tar
bukkit-1fd394bc7c15246d72b9957f62f79454663182d4.tar.gz
bukkit-1fd394bc7c15246d72b9957f62f79454663182d4.tar.lz
bukkit-1fd394bc7c15246d72b9957f62f79454663182d4.tar.xz
bukkit-1fd394bc7c15246d72b9957f62f79454663182d4.zip
Moved all vanilla commands into Bukkit
-rw-r--r--src/main/java/org/bukkit/Bukkit.java16
-rw-r--r--src/main/java/org/bukkit/OfflinePlayer.java14
-rw-r--r--src/main/java/org/bukkit/Server.java27
-rw-r--r--src/main/java/org/bukkit/command/Command.java25
-rw-r--r--src/main/java/org/bukkit/command/SimpleCommandMap.java51
-rw-r--r--src/main/java/org/bukkit/command/defaults/BanCommand.java34
-rw-r--r--src/main/java/org/bukkit/command/defaults/BanIpCommand.java34
-rw-r--r--src/main/java/org/bukkit/command/defaults/DeopCommand.java42
-rw-r--r--src/main/java/org/bukkit/command/defaults/GiveCommand.java61
-rw-r--r--src/main/java/org/bukkit/command/defaults/HelpCommand.java43
-rw-r--r--src/main/java/org/bukkit/command/defaults/KickCommand.java41
-rw-r--r--src/main/java/org/bukkit/command/defaults/KillCommand.java39
-rw-r--r--src/main/java/org/bukkit/command/defaults/ListCommand.java39
-rw-r--r--src/main/java/org/bukkit/command/defaults/MeCommand.java39
-rw-r--r--src/main/java/org/bukkit/command/defaults/OpCommand.java42
-rw-r--r--src/main/java/org/bukkit/command/defaults/PardonCommand.java34
-rw-r--r--src/main/java/org/bukkit/command/defaults/PardonIpCommand.java34
-rw-r--r--src/main/java/org/bukkit/command/defaults/SaveCommand.java37
-rw-r--r--src/main/java/org/bukkit/command/defaults/SaveOffCommand.java33
-rw-r--r--src/main/java/org/bukkit/command/defaults/SaveOnCommand.java33
-rw-r--r--src/main/java/org/bukkit/command/defaults/SayCommand.java33
-rw-r--r--src/main/java/org/bukkit/command/defaults/StopCommand.java29
-rw-r--r--src/main/java/org/bukkit/command/defaults/TeleportCommand.java44
-rw-r--r--src/main/java/org/bukkit/command/defaults/TellCommand.java54
-rw-r--r--src/main/java/org/bukkit/command/defaults/TimeCommand.java64
-rw-r--r--src/main/java/org/bukkit/command/defaults/VanillaCommand.java16
-rw-r--r--src/main/java/org/bukkit/command/defaults/WhitelistCommand.java90
27 files changed, 1038 insertions, 10 deletions
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index baa5c086..8438831d 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -229,6 +229,10 @@ public final class Bukkit {
return server.getOfflinePlayer(name);
}
+ public static Player getPlayerExact(String name) {
+ return server.getPlayerExact(name);
+ }
+
public static Set<String> getIPBans() {
return server.getIPBans();
}
@@ -244,4 +248,16 @@ public final class Bukkit {
public static Set<OfflinePlayer> getBannedPlayers() {
return server.getBannedPlayers();
}
+
+ public static void setWhitelist(boolean value) {
+ server.setWhitelist(value);
+ }
+
+ public static Set<OfflinePlayer> getWhitelistedPlayers() {
+ return server.getWhitelistedPlayers();
+ }
+
+ public static void reloadWhitelist() {
+ server.reloadWhitelist();
+ }
}
diff --git a/src/main/java/org/bukkit/OfflinePlayer.java b/src/main/java/org/bukkit/OfflinePlayer.java
index 469e54dc..fff8aa8b 100644
--- a/src/main/java/org/bukkit/OfflinePlayer.java
+++ b/src/main/java/org/bukkit/OfflinePlayer.java
@@ -30,4 +30,18 @@ public interface OfflinePlayer extends ServerOperator {
* @param banned true if banned
*/
public void setBanned(boolean banned);
+
+ /**
+ * Checks if this player is whitelisted or not
+ *
+ * @return true if whitelisted
+ */
+ public boolean isWhitelisted();
+
+ /**
+ * Sets if this player is whitelisted or not
+ *
+ * @param value true if whitelisted
+ */
+ public void setWhitelisted(boolean value);
}
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 9467d749..1ef6cfa7 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -115,6 +115,25 @@ public interface Server {
public boolean hasWhitelist();
/**
+ * Sets the whitelist on or off
+ *
+ * @param value true if whitelist is on, otherwise false
+ */
+ public void setWhitelist(boolean value);
+
+ /**
+ * Gets a list of whitelisted players
+ *
+ * @return Set containing all whitelisted players
+ */
+ public Set<OfflinePlayer> getWhitelistedPlayers();
+
+ /**
+ * Reloads the whitelist from disk
+ */
+ public void reloadWhitelist();
+
+ /**
* Broadcast a message to all players.
*
* This is the same as calling {@link #broadcast(java.lang.String, java.lang.String)} to {@link #BROADCAST_CHANNEL_USERS}
@@ -143,6 +162,14 @@ public interface Server {
public Player getPlayer(String name);
/**
+ * Gets the player with the exact given name, case insensitive
+ *
+ * @param name Exact name of the player to retrieve
+ * @return Player object or null if not found
+ */
+ public Player getPlayerExact(String name);
+
+ /**
* Attempts to match any players with the given name, and returns a list
* of all possibly matches
*
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
index 002e1129..db681a74 100644
--- a/src/main/java/org/bukkit/command/Command.java
+++ b/src/main/java/org/bukkit/command/Command.java
@@ -2,7 +2,10 @@ package org.bukkit.command;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
+import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
+import org.bukkit.Server;
import org.bukkit.permissions.Permissible;
/**
@@ -221,4 +224,26 @@ public abstract class Command {
this.usageMessage = usage;
return this;
}
+
+ public static void broadcastCommandMessage(CommandSender source, String message) {
+ Set<Permissible> users = Bukkit.getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
+ String result = source.getName() + ": " + message;
+ String colored = ChatColor.GRAY + "(" + result + ")";
+
+ if (!(source instanceof ConsoleCommandSender)) {
+ source.sendMessage(message);
+ }
+
+ for (Permissible user : users) {
+ if (user instanceof CommandSender) {
+ CommandSender target = (CommandSender)user;
+
+ if (target instanceof ConsoleCommandSender) {
+ target.sendMessage(result);
+ } else if (target != source) {
+ target.sendMessage(colored);
+ }
+ }
+ }
+ }
}
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index 178edabb..2abd87e5 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -1,27 +1,45 @@
package org.bukkit.command;
-import org.bukkit.command.defaults.ReloadCommand;
-import org.bukkit.command.defaults.PluginsCommand;
import org.bukkit.command.defaults.*;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Iterator;
-
-import org.bukkit.ChatColor;
import org.bukkit.Server;
-
-import org.bukkit.plugin.Plugin;
import static org.bukkit.util.Java15Compat.Arrays_copyOfRange;
-public final class SimpleCommandMap implements CommandMap {
- private final Map<String, Command> knownCommands = new HashMap<String, Command>();
- private final Set<String> aliases = new HashSet<String>();
+public class SimpleCommandMap implements CommandMap {
+ protected final Map<String, Command> knownCommands = new HashMap<String, Command>();
+ protected final Set<String> aliases = new HashSet<String>();
private final Server server;
+ protected static final Set<VanillaCommand> fallbackCommands = new HashSet<VanillaCommand>();
+
+ static {
+ fallbackCommands.add(new ListCommand());
+ fallbackCommands.add(new StopCommand());
+ fallbackCommands.add(new SaveCommand());
+ fallbackCommands.add(new SaveOnCommand());
+ fallbackCommands.add(new SaveOffCommand());
+ fallbackCommands.add(new OpCommand());
+ fallbackCommands.add(new DeopCommand());
+ fallbackCommands.add(new BanIpCommand());
+ fallbackCommands.add(new PardonIpCommand());
+ fallbackCommands.add(new BanCommand());
+ fallbackCommands.add(new PardonCommand());
+ fallbackCommands.add(new KickCommand());
+ fallbackCommands.add(new TeleportCommand());
+ fallbackCommands.add(new GiveCommand());
+ fallbackCommands.add(new TimeCommand());
+ fallbackCommands.add(new SayCommand());
+ fallbackCommands.add(new WhitelistCommand());
+ fallbackCommands.add(new TellCommand());
+ fallbackCommands.add(new MeCommand());
+ fallbackCommands.add(new KillCommand());
+ fallbackCommands.add(new HelpCommand());
+ }
public SimpleCommandMap(final Server server) {
this.server = server;
@@ -110,6 +128,16 @@ public final class SimpleCommandMap implements CommandMap {
return registerdPassedLabel;
}
+ protected Command getFallback(String label) {
+ for (VanillaCommand cmd : fallbackCommands) {
+ if (cmd.matches(label)) {
+ return cmd;
+ }
+ }
+
+ return null;
+ }
+
/**
* {@inheritDoc}
*/
@@ -123,6 +151,9 @@ public final class SimpleCommandMap implements CommandMap {
String sentCommandLabel = args[0].toLowerCase();
Command target = getCommand(sentCommandLabel);
if (target == null) {
+ target = getFallback(commandLine.toLowerCase());
+ }
+ if (target == null) {
return false;
}
diff --git a/src/main/java/org/bukkit/command/defaults/BanCommand.java b/src/main/java/org/bukkit/command/defaults/BanCommand.java
new file mode 100644
index 00000000..7d6b0ffa
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/BanCommand.java
@@ -0,0 +1,34 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class BanCommand extends VanillaCommand {
+ public BanCommand() {
+ super("ban");
+ this.description = "Prevents the specified player from using this server";
+ this.usageMessage = "/ban <player>";
+ this.setPermission("bukkit.command.ban.player");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Bukkit.getOfflinePlayer(args[0]).setBanned(true);
+ Command.broadcastCommandMessage(sender, "Banning " + args[0]);
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("ban ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/BanIpCommand.java b/src/main/java/org/bukkit/command/defaults/BanIpCommand.java
new file mode 100644
index 00000000..e03a3cb3
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/BanIpCommand.java
@@ -0,0 +1,34 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class BanIpCommand extends VanillaCommand {
+ public BanIpCommand() {
+ super("ban-ip");
+ this.description = "Prevents the specified IP address from using this server";
+ this.usageMessage = "/ban-ip <address>";
+ this.setPermission("bukkit.command.ban.ip");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Bukkit.banIP(args[0]);
+ Command.broadcastCommandMessage(sender, "Banning ip " + args[0]);
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("ban-ip ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/DeopCommand.java b/src/main/java/org/bukkit/command/defaults/DeopCommand.java
new file mode 100644
index 00000000..29b5d957
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/DeopCommand.java
@@ -0,0 +1,42 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class DeopCommand extends VanillaCommand {
+ public DeopCommand() {
+ super("deop");
+ this.description = "Takes the specified player's operator status";
+ this.usageMessage = "/deop <player>";
+ this.setPermission("bukkit.command.op.take");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Command.broadcastCommandMessage(sender, "De-opping " + args[0]);
+
+ OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
+ player.setOp(false);
+
+ if (player instanceof Player) {
+ ((Player)player).sendMessage(ChatColor.YELLOW + "You are no longer op!");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("deop ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/GiveCommand.java b/src/main/java/org/bukkit/command/defaults/GiveCommand.java
new file mode 100644
index 00000000..25dbd84d
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/GiveCommand.java
@@ -0,0 +1,61 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+public class GiveCommand extends VanillaCommand {
+ public GiveCommand() {
+ super("give");
+ this.description = "Gives the specified player a certain amount of items";
+ this.usageMessage = "/give <player> <item> [amount]";
+ this.setPermission("bukkit.command.give");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if ((args.length < 2) || (args.length > 3)) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Player player = Bukkit.getPlayerExact(args[0]);
+
+ if (player != null) {
+ Material material = Material.matchMaterial(args[1]);
+
+ if (material != null) {
+ Command.broadcastCommandMessage(sender, "Giving " + player.getName() + " some " + material.getId() + "(" + material + ")");
+
+ int amount = 1;
+
+ if (args.length >= 3) {
+ try {
+ amount = Integer.parseInt(args[2]);
+ } catch (NumberFormatException ex) {}
+
+ if (amount < 1) amount = 1;
+ if (amount > 64) amount = 64;
+ }
+
+ player.getInventory().addItem(new ItemStack(material, amount));
+ } else {
+ sender.sendMessage("There's no item called " + args[1]);
+ }
+ } else {
+ sender.sendMessage("Can't find user " + args[0]);
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("give ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/HelpCommand.java b/src/main/java/org/bukkit/command/defaults/HelpCommand.java
new file mode 100644
index 00000000..7fd39934
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/HelpCommand.java
@@ -0,0 +1,43 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.command.CommandSender;
+
+public class HelpCommand extends VanillaCommand {
+ public HelpCommand() {
+ super("help");
+ this.description = "Shows the help menu";
+ this.usageMessage = "/help";
+ this.setPermission("bukkit.command.help");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+
+ sender.sendMessage("help or ? shows this message");
+ sender.sendMessage("kick <player> removes a player from the server");
+ sender.sendMessage("ban <player> bans a player from the server");
+ sender.sendMessage("pardon <player> pardons a banned player so that they can connect again");
+ sender.sendMessage("ban-ip <ip> bans an IP address from the server");
+ sender.sendMessage("pardon-ip <ip> pardons a banned IP address so that they can connect again");
+ sender.sendMessage("op <player> turns a player into an op");
+ sender.sendMessage("deop <player> removes op status from a player");
+ sender.sendMessage("tp <player1> <player2> moves one player to the same location as another player");
+ sender.sendMessage("give <player> <id> [num] gives a player a resource");
+ sender.sendMessage("tell <player> <message> sends a private message to a player");
+ sender.sendMessage("stop gracefully stops the server");
+ sender.sendMessage("save-all forces a server-wide level save");
+ sender.sendMessage("save-off disables terrain saving (useful for backup scripts)");
+ sender.sendMessage("save-on re-enables terrain saving");
+ sender.sendMessage("list lists all currently connected players");
+ sender.sendMessage("say <message> broadcasts a message to all players");
+ sender.sendMessage("time <add|set> <amount> adds to or sets the world time (0-24000)");
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("help") || input.startsWith("?");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/KickCommand.java b/src/main/java/org/bukkit/command/defaults/KickCommand.java
new file mode 100644
index 00000000..e3b5a08b
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/KickCommand.java
@@ -0,0 +1,41 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class KickCommand extends VanillaCommand {
+ public KickCommand() {
+ super("kick");
+ this.description = "Removes the specified player from the server";
+ this.usageMessage = "/kick <player>";
+ this.setPermission("bukkit.command.kick");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length < 1) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Player player = Bukkit.getPlayerExact(args[0]);
+
+ if (player != null) {
+ Command.broadcastCommandMessage(sender, "Kicking " + player.getName());
+ player.kickPlayer("Kicked by admin");
+ } else {
+ sender.sendMessage("Can't find user " + args[0] + ". No kick.");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("kick ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/KillCommand.java b/src/main/java/org/bukkit/command/defaults/KillCommand.java
new file mode 100644
index 00000000..e6c2fa13
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/KillCommand.java
@@ -0,0 +1,39 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.event.entity.EntityDamageEvent;
+
+public class KillCommand extends VanillaCommand {
+ public KillCommand() {
+ super("kill");
+ this.description = "Commits suicide, only usable as a player";
+ this.usageMessage = "/kill";
+ this.setPermission("bukkit.command.kill");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+
+ if (sender instanceof Player) {
+ Player player = (Player)sender;
+
+ EntityDamageEvent ede = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.SUICIDE, 1000);
+ Bukkit.getPluginManager().callEvent(ede);
+ if (ede.isCancelled()) return true;
+
+ player.damage(ede.getDamage());
+ } else {
+ sender.sendMessage("You can only perform this command as a player");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("kill");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/ListCommand.java b/src/main/java/org/bukkit/command/defaults/ListCommand.java
new file mode 100644
index 00000000..ef3d544e
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/ListCommand.java
@@ -0,0 +1,39 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class ListCommand extends VanillaCommand {
+ public ListCommand() {
+ super("list");
+ this.description = "Lists all online players";
+ this.usageMessage = "/list";
+ this.setPermission("bukkit.command.list");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+
+ String players = "";
+
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ if (players.length() > 0) {
+ players += ", ";
+ }
+
+ players += player.getDisplayName();
+ }
+
+ sender.sendMessage("Connected players: " + players);
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("list");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/MeCommand.java b/src/main/java/org/bukkit/command/defaults/MeCommand.java
new file mode 100644
index 00000000..8c079415
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/MeCommand.java
@@ -0,0 +1,39 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+
+public class MeCommand extends VanillaCommand {
+ public MeCommand() {
+ super("me");
+ this.description = "Performs the specified action in chat";
+ this.usageMessage = "/me <action>";
+ this.setPermission("bukkit.command.me");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length < 1) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ String message = "";
+
+ for (int i = 0; i < args.length; i++) {
+ if (i > 0) message += " ";
+ message += args[i];
+ }
+
+ Bukkit.broadcastMessage("* " + sender.getName() + " " + message);
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("me ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/OpCommand.java b/src/main/java/org/bukkit/command/defaults/OpCommand.java
new file mode 100644
index 00000000..36ee25a7
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/OpCommand.java
@@ -0,0 +1,42 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class OpCommand extends VanillaCommand {
+ public OpCommand() {
+ super("op");
+ this.description = "Gives the specified player operator status";
+ this.usageMessage = "/op <player>";
+ this.setPermission("bukkit.command.op.give");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Command.broadcastCommandMessage(sender, "Oping " + args[0]);
+
+ OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
+ player.setOp(true);
+
+ if (player instanceof Player) {
+ ((Player)player).sendMessage(ChatColor.YELLOW + "You are now op!");
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("op ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/PardonCommand.java b/src/main/java/org/bukkit/command/defaults/PardonCommand.java
new file mode 100644
index 00000000..866cccf7
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/PardonCommand.java
@@ -0,0 +1,34 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class PardonCommand extends VanillaCommand {
+ public PardonCommand() {
+ super("pardon");
+ this.description = "Allows the specified player to use this server";
+ this.usageMessage = "/pardon <player>";
+ this.setPermission("bukkit.command.unban.player");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Bukkit.getOfflinePlayer(args[0]).setBanned(false);
+ Command.broadcastCommandMessage(sender, "Pardoning " + args[0]);
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("pardon ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/PardonIpCommand.java b/src/main/java/org/bukkit/command/defaults/PardonIpCommand.java
new file mode 100644
index 00000000..83bd2ccb
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/PardonIpCommand.java
@@ -0,0 +1,34 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class PardonIpCommand extends VanillaCommand {
+ public PardonIpCommand() {
+ super("pardon-ip");
+ this.description = "Allows the specified IP address to use this server";
+ this.usageMessage = "/pardon-ip <address>";
+ this.setPermission("bukkit.command.unban.ip");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Bukkit.unbanIP(args[0]);
+ Command.broadcastCommandMessage(sender, "Pardoning ip " + args[0]);
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("pardon-ip ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/SaveCommand.java b/src/main/java/org/bukkit/command/defaults/SaveCommand.java
new file mode 100644
index 00000000..d73983d2
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/SaveCommand.java
@@ -0,0 +1,37 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class SaveCommand extends VanillaCommand {
+ public SaveCommand() {
+ super("save-all");
+ this.description = "Saves the server to disk";
+ this.usageMessage = "/save-all";
+ this.setPermission("bukkit.command.save.perform");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+
+ Command.broadcastCommandMessage(sender, "Forcing save..");
+
+ Bukkit.savePlayers();
+
+ for (World world : Bukkit.getWorlds()) {
+ world.save();
+ }
+
+ Command.broadcastCommandMessage(sender, "Save complete.");
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("save-all");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/SaveOffCommand.java b/src/main/java/org/bukkit/command/defaults/SaveOffCommand.java
new file mode 100644
index 00000000..67f9b407
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/SaveOffCommand.java
@@ -0,0 +1,33 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class SaveOffCommand extends VanillaCommand {
+ public SaveOffCommand() {
+ super("save-off");
+ this.description = "Disables server autosaving";
+ this.usageMessage = "/save-off";
+ this.setPermission("bukkit.command.save.disable");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+
+ Command.broadcastCommandMessage(sender, "Disabling level saving..");
+
+ for (World world : Bukkit.getWorlds()) {
+ world.setAutoSave(false);
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("save-off");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/SaveOnCommand.java b/src/main/java/org/bukkit/command/defaults/SaveOnCommand.java
new file mode 100644
index 00000000..84be37f8
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/SaveOnCommand.java
@@ -0,0 +1,33 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class SaveOnCommand extends VanillaCommand {
+ public SaveOnCommand() {
+ super("save-on");
+ this.description = "Enables server autosaving";
+ this.usageMessage = "/save-on";
+ this.setPermission("bukkit.command.save.enable");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+
+ Command.broadcastCommandMessage(sender, "Enabling level saving..");
+
+ for (World world : Bukkit.getWorlds()) {
+ world.setAutoSave(true);
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("save-on");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/SayCommand.java b/src/main/java/org/bukkit/command/defaults/SayCommand.java
new file mode 100644
index 00000000..5cfc2374
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/SayCommand.java
@@ -0,0 +1,33 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+
+public class SayCommand extends VanillaCommand {
+ public SayCommand() {
+ super("say");
+ this.description = "Broadcasts the given message as the console";
+ this.usageMessage = "/say <message>";
+ this.setPermission("bukkit.command.say");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Bukkit.getLogger().info("[" + sender.getName() + "] " + args[1]);
+ Bukkit.broadcastMessage("[Server] " + args[1]);
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("say ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/StopCommand.java b/src/main/java/org/bukkit/command/defaults/StopCommand.java
new file mode 100644
index 00000000..5097317b
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/StopCommand.java
@@ -0,0 +1,29 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class StopCommand extends VanillaCommand {
+ public StopCommand() {
+ super("stop");
+ this.description = "Stops the server";
+ this.usageMessage = "/stop";
+ this.setPermission("bukkit.command.stop");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+
+ Command.broadcastCommandMessage(sender, "Stopping the server..");
+ Bukkit.shutdown();
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("stop");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/TeleportCommand.java b/src/main/java/org/bukkit/command/defaults/TeleportCommand.java
new file mode 100644
index 00000000..aa2321fb
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/TeleportCommand.java
@@ -0,0 +1,44 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class TeleportCommand extends VanillaCommand {
+ public TeleportCommand() {
+ super("tp");
+ this.description = "Teleports the given player to another player";
+ this.usageMessage = "/tp <player> <target>";
+ this.setPermission("bukkit.command.teleport");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Player victim = Bukkit.getPlayerExact(args[0]);
+ Player target = Bukkit.getPlayerExact(args[1]);
+
+ if (victim == null) {
+ sender.sendMessage("Can't find user " + args[0] + ". No tp.");
+ } else if (target == null) {
+ sender.sendMessage("Can't find user " + args[1] + ". No tp.");
+ } else {
+ Command.broadcastCommandMessage(sender, "Teleporting " + victim.getName() + " to " + target.getName());
+ victim.teleport(target);
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("tp ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/TellCommand.java b/src/main/java/org/bukkit/command/defaults/TellCommand.java
new file mode 100644
index 00000000..69dd9745
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/TellCommand.java
@@ -0,0 +1,54 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.entity.Player;
+
+public class TellCommand extends VanillaCommand {
+ public TellCommand() {
+ super("tell");
+ this.description = "Sends a private message to the given player";
+ this.usageMessage = "/tell <player> <message>";
+ this.setPermission("bukkit.command.tell");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length < 2) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Player player = Bukkit.getPlayerExact(args[0]);
+
+ if (player == null) {
+ sender.sendMessage("There's no player by that name online.");
+ } else {
+ String message = "";
+
+ for (int i = 1; i < args.length; i++) {
+ if (i > 1) message += " ";
+ message += args[i];
+ }
+
+ String result = ChatColor.GRAY + sender.getName() + " whispers " + message;
+
+ if (sender instanceof ConsoleCommandSender) {
+ Bukkit.getLogger().info("[" + sender.getName() + "->" + player.getName() + "] " + message);
+ Bukkit.getLogger().info(result);
+ }
+
+ player.sendMessage(result);
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("tell ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/TimeCommand.java b/src/main/java/org/bukkit/command/defaults/TimeCommand.java
new file mode 100644
index 00000000..63f67ba7
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/TimeCommand.java
@@ -0,0 +1,64 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.World;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class TimeCommand extends VanillaCommand {
+ public TimeCommand() {
+ super("time");
+ this.description = "Changes the time on each world";
+ this.usageMessage = "/time set <value>\n/time add <value>";
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Incorrect usage. Correct usage:\n" + usageMessage);
+ return false;
+ }
+
+ int value = 0;
+
+ try {
+ value = Integer.parseInt(args[1]);
+ } catch (NumberFormatException ex) {
+ sender.sendMessage("Unable to convert time value, " + args[1]);
+ return true;
+ }
+
+ if (args[0].equalsIgnoreCase("add")) {
+ if (!sender.hasPermission("bukkit.command.time.add")) {
+ sender.sendMessage(ChatColor.RED + "You don't have permission to add to the time");
+ } else {
+ for (World world : Bukkit.getWorlds()) {
+ world.setFullTime(world.getFullTime() + value);
+ }
+
+ Command.broadcastCommandMessage(sender, "Added " + value + " to time");
+ }
+ } else if (args[0].equalsIgnoreCase("set")) {
+ if (!sender.hasPermission("bukkit.command.time.set")) {
+ sender.sendMessage(ChatColor.RED + "You don't have permission to set the time");
+ } else {
+ for (World world : Bukkit.getWorlds()) {
+ world.setTime(value);
+ }
+
+ Command.broadcastCommandMessage(sender, "Set time to " + value);
+ }
+ } else {
+ sender.sendMessage("Unknown method, use either \"add\" or \"set\"");
+ return true;
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("time ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/VanillaCommand.java b/src/main/java/org/bukkit/command/defaults/VanillaCommand.java
new file mode 100644
index 00000000..cfb0769a
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/VanillaCommand.java
@@ -0,0 +1,16 @@
+package org.bukkit.command.defaults;
+
+import java.util.List;
+import org.bukkit.command.Command;
+
+public abstract class VanillaCommand extends Command {
+ protected VanillaCommand(String name) {
+ super(name);
+ }
+
+ protected VanillaCommand(String name, String description, String usageMessage, List<String> aliases) {
+ super(name, description, usageMessage, aliases);
+ }
+
+ public abstract boolean matches(String input);
+}
diff --git a/src/main/java/org/bukkit/command/defaults/WhitelistCommand.java b/src/main/java/org/bukkit/command/defaults/WhitelistCommand.java
new file mode 100644
index 00000000..749ccdf2
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/WhitelistCommand.java
@@ -0,0 +1,90 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class WhitelistCommand extends VanillaCommand {
+ public WhitelistCommand() {
+ super("whitelist");
+ this.description = "Prevents the specified player from using this server";
+ this.usageMessage = "/whitelist (add|remove) <player>\n/whitelist (on|off|list|reload)";
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+
+ if (args.length == 1) {
+ if (args[0].equalsIgnoreCase("reload")) {
+ if (badPerm(sender, "reload")) return true;
+
+ Bukkit.reloadWhitelist();
+ Command.broadcastCommandMessage(sender, "Reloaded white-list from file");
+ return true;
+ } else if (args[0].equalsIgnoreCase("on")) {
+ if (badPerm(sender, "enable")) return true;
+
+ Bukkit.setWhitelist(true);
+ Command.broadcastCommandMessage(sender, "Turned on white-listing");
+ return true;
+ } else if (args[0].equalsIgnoreCase("off")) {
+ if (badPerm(sender, "disable")) return true;
+
+ Bukkit.setWhitelist(false);
+ Command.broadcastCommandMessage(sender, "Turned off white-listing");
+ return true;
+ } else if (args[0].equalsIgnoreCase("list")) {
+ if (badPerm(sender, "list")) return true;
+
+ String result = "";
+
+ for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
+ if (result.length() > 0) {
+ result += " ";
+ }
+
+ result += player.getName();
+ }
+
+ sender.sendMessage("White-listed players: " + result);
+ return true;
+ }
+ } else if (args.length == 2) {
+ if (args[0].equalsIgnoreCase("add")) {
+ if (badPerm(sender, "add")) return true;
+
+ Bukkit.getOfflinePlayer(args[1]).setWhitelisted(true);
+
+ Command.broadcastCommandMessage(sender, "Added " + args[1] + " to white-list");
+ return true;
+ } else if (args[0].equalsIgnoreCase("remove")) {
+ if (badPerm(sender, "remove")) return true;
+
+ Bukkit.getOfflinePlayer(args[1]).setWhitelisted(false);
+
+ Command.broadcastCommandMessage(sender, "Removed " + args[1] + " from white-list");
+ return true;
+ }
+ }
+
+ sender.sendMessage(ChatColor.RED + "Correct command usage:\n" + usageMessage);
+ return false;
+ }
+
+ private boolean badPerm(CommandSender sender, String perm) {
+ if (!sender.hasPermission("bukkit.command.whitelist." + perm)) {
+ sender.sendMessage(ChatColor.RED + "You do not have permission to perform this action.");
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("whitelist ");
+ }
+}