Interface CommandCause

  • All Superinterfaces:
    Contextual, Subject, SubjectProxy

    @DoNotStore
    public interface CommandCause
    extends SubjectProxy
    The CommandCause represents the Cause of a command, and also contains utility methods to obtain key information about said cause.

    In line with causes used in events, you may assume that the Cause.root() (from cause()) is the direct invoker of the command, though it should also be noted that the invoker and intended target of a command may be different, which will be indicated by entries in the Cause.context()

    It is very important to note that no object in the Cause is guaranteed to be a traditional "command source" - a plugin may invoke a command without pushing anything to the cause stack and thus the PluginContainer of the plugin in question will be the root of the cause.

    In the case of a command being executed as a "proxy", such as a command block executing a command by virtue of an entity stepping on a pressure plate, the direct cause will be the command block. However, the player in question will also be present in the cause stack, allowing command providers to obtain richer information about the invocation of their command. This is inline with how Causes work in Sponge and its events, for more information about how Causes work, see the Cause and CauseStackManager javadocs and associated documentation.

    The EventContext that is attached to Cause.context() may offer other indications as to how the command should be handled, in addition to using the provided cause stack:

    This object acts as a Subject, and simply redirects all calls inherited by this interface to the subject returned by subject().

    There are utility methods on this interface that provide hints as to what the implementation will select for different tasks, for example, the implementation will use the result of subject() for permission checks. Third party command consumers are under no obligation to use these utility methods as all methods obtain their information from the Cause.

    No method on this interface, apart from cause(), should be taken a guarantee of what may be present, however, they indicate what typically would be of interest to command API consumers.