@@ -30,7 +30,7 @@ public abstract class Command {
|
||||
|
||||
/**
|
||||
* Returns the name of this command
|
||||
*
|
||||
*
|
||||
* @return Name of this command
|
||||
*/
|
||||
public String getName() {
|
||||
@@ -96,4 +96,4 @@ public abstract class Command {
|
||||
this.usageMessage = usage;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package org.bukkit.command;
|
||||
|
||||
/**
|
||||
@@ -9,9 +8,7 @@ public class CommandException extends RuntimeException {
|
||||
/**
|
||||
* Creates a new instance of <code>CommandException</code> without detail message.
|
||||
*/
|
||||
public CommandException() {
|
||||
}
|
||||
|
||||
public CommandException() {}
|
||||
|
||||
/**
|
||||
* Constructs an instance of <code>CommandException</code> with the specified detail message.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
package org.bukkit.command;
|
||||
|
||||
/**
|
||||
* Represents a class which contains a single method for executing commands
|
||||
*/
|
||||
public interface CommandExecutor {
|
||||
|
||||
/**
|
||||
* Executes the given command, returning its success
|
||||
*
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.bukkit.command;
|
||||
import java.util.List;
|
||||
|
||||
public interface CommandMap {
|
||||
|
||||
/**
|
||||
* Registers all the commands belonging to a certain plugin.
|
||||
* @param plugin
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.bukkit.command;
|
||||
|
||||
import org.bukkit.Server;
|
||||
|
||||
|
||||
public interface CommandSender {
|
||||
|
||||
/**
|
||||
* Sends this sender a message
|
||||
*
|
||||
@@ -24,4 +24,4 @@ public interface CommandSender {
|
||||
* @return Server instance
|
||||
*/
|
||||
public Server getServer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package org.bukkit.command;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
@@ -39,10 +39,10 @@ public final class PluginCommand extends Command {
|
||||
|
||||
if (!success && usageMessage.length() > 0) {
|
||||
for (String line: usageMessage.replace("<command>", commandLabel).split("\n")) {
|
||||
sender.sendMessage( line );
|
||||
sender.sendMessage(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -72,4 +72,4 @@ public final class PluginCommand extends Command {
|
||||
public Plugin getPlugin() {
|
||||
return owningPlugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,23 @@ public class PluginCommandYamlParser {
|
||||
public static List<Command> parse(Plugin plugin) {
|
||||
List<Command> pluginCmds = new ArrayList<Command>();
|
||||
Object object = plugin.getDescription().getCommands();
|
||||
if (object == null)
|
||||
return pluginCmds;
|
||||
|
||||
Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>)object;
|
||||
if (object == null) {
|
||||
return pluginCmds;
|
||||
}
|
||||
|
||||
Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>) object;
|
||||
|
||||
if (map != null) {
|
||||
for(Entry<String, Map<String, Object>> entry : map.entrySet()) {
|
||||
Command newCmd = new PluginCommand(entry.getKey(),plugin);
|
||||
for (Entry<String, Map<String, Object>> entry : map.entrySet()) {
|
||||
Command newCmd = new PluginCommand(entry.getKey(), plugin);
|
||||
Object description = entry.getValue().get("description");
|
||||
Object usage = entry.getValue().get("usage");
|
||||
Object aliases = entry.getValue().get("aliases");
|
||||
|
||||
if (description != null)
|
||||
if (description != null) {
|
||||
newCmd.setDescription(description.toString());
|
||||
}
|
||||
|
||||
if (usage != null) {
|
||||
newCmd.setUsage(usage.toString());
|
||||
@@ -34,9 +37,9 @@ public class PluginCommandYamlParser {
|
||||
|
||||
if (aliases != null) {
|
||||
List<String> aliasList = new ArrayList<String>();
|
||||
|
||||
|
||||
if (aliases instanceof List) {
|
||||
for (Object o : (List<Object>)aliases) {
|
||||
for (Object o : (List<Object>) aliases) {
|
||||
aliasList.add(o.toString());
|
||||
}
|
||||
} else {
|
||||
@@ -51,5 +54,4 @@ public class PluginCommandYamlParser {
|
||||
}
|
||||
return pluginCmds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class SimpleCommandMap implements CommandMap {
|
||||
*/
|
||||
public void registerAll(String fallbackPrefix, List<Command> commands) {
|
||||
if (commands != null) {
|
||||
for(Command c : commands) {
|
||||
for (Command c : commands) {
|
||||
register(fallbackPrefix, c);
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ public final class SimpleCommandMap implements CommandMap {
|
||||
|
||||
private void register(String fallbackPrefix, Command command) {
|
||||
List<String> names = new ArrayList<String>();
|
||||
|
||||
names.add(command.getName());
|
||||
names.addAll(command.getAliases());
|
||||
|
||||
@@ -55,7 +56,7 @@ public final class SimpleCommandMap implements CommandMap {
|
||||
*/
|
||||
public boolean register(String name, String fallbackPrefix, Command command) {
|
||||
boolean nameInUse = (getCommand(name) != null);
|
||||
|
||||
|
||||
if (nameInUse) {
|
||||
name = fallbackPrefix + ":" + name;
|
||||
}
|
||||
@@ -63,7 +64,7 @@ public final class SimpleCommandMap implements CommandMap {
|
||||
knownCommands.put(name.toLowerCase(), command);
|
||||
return !nameInUse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -80,6 +81,7 @@ public final class SimpleCommandMap implements CommandMap {
|
||||
|
||||
Command target = getCommand(sentCommandLabel);
|
||||
boolean isRegisteredCommand = (target != null);
|
||||
|
||||
if (isRegisteredCommand) {
|
||||
try {
|
||||
target.execute(sender, sentCommandLabel, args);
|
||||
@@ -117,8 +119,7 @@ public final class SimpleCommandMap implements CommandMap {
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("This server is running " + ChatColor.GREEN
|
||||
+ server.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + server.getVersion());
|
||||
sender.sendMessage("This server is running " + ChatColor.GREEN + server.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + server.getVersion());
|
||||
sender.sendMessage("This server is also sporting some funky dev build of Bukkit!");
|
||||
} else {
|
||||
StringBuilder name = new StringBuilder();
|
||||
@@ -134,6 +135,7 @@ public final class SimpleCommandMap implements CommandMap {
|
||||
|
||||
if (plugin != null) {
|
||||
PluginDescriptionFile desc = plugin.getDescription();
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion());
|
||||
|
||||
if (desc.getDescription() != null) {
|
||||
@@ -242,4 +244,4 @@ public final class SimpleCommandMap implements CommandMap {
|
||||
return pluginList.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user