Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
import org.spongepowered.api.status.StatusClient;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.util.Direction;
import org.spongepowered.api.util.command.CommandResult;
import org.spongepowered.api.util.command.CommandSource;
import org.spongepowered.api.util.event.factory.ClassGeneratorProvider;
import org.spongepowered.api.util.event.factory.EventFactory;
Expand Down Expand Up @@ -904,14 +905,16 @@ public static ProjectileLaunchEvent createProjectileLaunch(Game game, Cause caus
* @param arguments The arguments provided
* @param source The source of the command
* @param command The command name
* @param result The result of the command, or null
* @return A new instance of the event
*/
public static CommandEvent createCommand(Game game, String arguments, CommandSource source, String command) {
public static CommandEvent createCommand(Game game, String arguments, CommandSource source, String command, @Nullable CommandResult result) {
Map<String, Object> values = Maps.newHashMap();
values.put("game", game);
values.put("arguments", arguments);
values.put("source", source);
values.put("command", command);
values.put("result", Optional.fromNullable(result));
return createEvent(CommandEvent.class, values);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@

package org.spongepowered.api.event.message;

import com.google.common.base.Optional;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.GameEvent;
import org.spongepowered.api.util.command.CommandResult;
import org.spongepowered.api.util.command.CommandSource;

import javax.annotation.Nullable;

/**
* Fired when a command has been used and needs to be processed.
*/
Expand Down Expand Up @@ -61,4 +65,19 @@ public interface CommandEvent extends GameEvent, Cancellable {
*/
String getArguments();

/**
* The result of the command. This is only available after the execution
* of the command.
*
* @return The result of the command, if present
*/
Optional<CommandResult> getResult();

/**
* Sets the result of the command.
*
* @param result The result of the command, or null
*/
void setResult(@Nullable CommandResult result);

}
8 changes: 8 additions & 0 deletions src/main/java/org/spongepowered/api/plugin/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,13 @@
*/
String dependencies() default "";

/**
* Gets a list of command prefixes that can be used to call commands from
* this plugin.
*
* @return A list of command prefixes that can be used to call commands from
* this plugin
*/
String[] commandPrefixes() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package org.spongepowered.api.plugin;

import java.util.Set;

/**
* A wrapper around a class marked with an {@link Plugin} annotation to retrieve
* information from the annotation for easier use.
Expand Down Expand Up @@ -59,4 +61,11 @@ public interface PluginContainer {
*/
Object getInstance();

/**
* Gets the command prefixes associated with this plugin.
*
* @return The command prefixes associated with this plugin
*/
Set<String> getCommandPrefixes();

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@
* THE SOFTWARE.
*/

package org.spongepowered.api.util.command.completion;
package org.spongepowered.api.service.command;

import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;

import org.junit.Test;
import com.google.common.base.Optional;
import org.spongepowered.api.util.command.CommandSource;

public class NullCompleterTest {
/**
*
* A function that determines what plugin, by ID should be used for a command
* when sent by a certain source.
*
*/
public interface AliasContext {

@Test
public void testGetSuggestions() throws Exception {
assertThat(new NullCompleter().getSuggestions(mock(CommandSource.class), ""), empty());
assertThat(new NullCompleter().getSuggestions(mock(CommandSource.class), "example"), empty());
assertThat(new NullCompleter().getSuggestions(mock(CommandSource.class), "parent child"), empty());
}
/**
* Gets the ID of the plugin to be used for the specified source
*
* @param source The source of the command
* @return The ID, or {@link Optional#absent()} if normal handling should
* continue
*/
Optional<String> getPluginId(CommandSource source);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.service.command;

@org.spongepowered.api.util.annotation.NonnullByDefault package org.spongepowered.api.util.command.completion;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

class CommandMessageFormatting {

public static Text error(Text error) {
return error.builder().color(TextColors.RED).build();
}

public static Text debug(Text debug) {
return debug.builder().color(TextColors.GRAY).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import com.google.common.base.Function;
import com.google.common.base.Optional;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.util.command.CommandCallable;
import org.spongepowered.api.util.command.CommandMapping;
import org.spongepowered.api.util.command.CommandSpec;
import org.spongepowered.api.util.command.dispatcher.Dispatcher;

import java.util.List;
Expand All @@ -53,12 +53,12 @@ public interface CommandService extends Dispatcher {
* <p>The first non-conflicted alias becomes the "primary alias."</p>
*
* @param plugin A plugin instance
* @param callable The command
* @param spec The command
* @param alias An array of aliases
* @return The registered command mapping, unless no aliases could be registered
* @throws IllegalArgumentException Thrown if {@code plugin} is not a plugin instance
*/
Optional<CommandMapping> register(Object plugin, CommandCallable callable, String... alias);
Optional<CommandMapping> register(Object plugin, CommandSpec spec, String... alias);

/**
* Register a given command using the given list of aliases.
Expand All @@ -72,12 +72,12 @@ public interface CommandService extends Dispatcher {
* <p>The first non-conflicted alias becomes the "primary alias."</p>
*
* @param plugin A plugin instance
* @param callable The command
* @param spec The command
* @param aliases A list of aliases
* @return The registered command mapping, unless no aliases could be registered
* @throws IllegalArgumentException Thrown if {@code plugin} is not a plugin instance
*/
Optional<CommandMapping> register(Object plugin, CommandCallable callable, List<String> aliases);
Optional<CommandMapping> register(Object plugin, CommandSpec spec, List<String> aliases);

/**
* Register a given command using a given list of aliases.
Expand All @@ -94,22 +94,14 @@ public interface CommandService extends Dispatcher {
* <p>The first non-conflicted alias becomes the "primary alias."</p>
*
* @param plugin A plugin instance
* @param callable The command
* @param spec The command
* @param aliases A list of aliases
* @param callback The callback
* @return The registered command mapping, unless no aliases could be registered
* @throws IllegalArgumentException Thrown if new conflicting aliases are added in the callback
* @throws IllegalArgumentException Thrown if {@code plugin} is not a plugin instance
*/
Optional<CommandMapping> register(Object plugin, CommandCallable callable, List<String> aliases, Function<List<String>, List<String>> callback);

/**
* Remove a mapping identified by the given alias.
*
* @param alias The alias
* @return The previous mapping associated with the alias, if one was found
*/
Optional<CommandMapping> remove(String alias);
Optional<CommandMapping> register(Object plugin, CommandSpec spec, List<String> aliases, Function<List<String>, List<String>> callback);

/**
* Remove a command identified by the given mapping.
Expand Down
Loading