Skip to content

Commit 9382db0

Browse files
committed
Replace the CommandSource with a CommandCause
* Split out notion of a console to the Game object, which is a MessageReceiver & Subject named SystemSubject * Make sure JDs are consistent with causes, remove anything to do with CommandSources * Renamed Nameable -> Nameable.Translatable. * Most objects now inherit Subject, MessageReceiver and Nameable. * Introduce the notion of the CommandCause, which is effectively a wrapper class that provides simple methods to get common entities from the cause. It is also a superinterface of CommandContext. * Add ExecuteCommandEvent. * Update for the use of factories to remove any unchecked warnings. * Update for CheckerFramework.
1 parent d6a82f2 commit 9382db0

30 files changed

+713
-335
lines changed

src/main/java/org/spongepowered/api/Game.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public interface Game {
8686
*/
8787
Server getServer();
8888

89+
/**
90+
* Gets the {@link SystemSubject}. Depending on the implementation, this
91+
* may also represent the game console.
92+
*
93+
* @return The {@link SystemSubject}
94+
*/
95+
SystemSubject getSystemSubject();
96+
8997
/**
9098
* Returns if the {@link Client} is available for use. The result of this method is entirely
9199
* dependent on the implementation.

src/main/java/org/spongepowered/api/Server.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
*/
2525
package org.spongepowered.api;
2626

27-
import org.spongepowered.api.command.source.CommandSource;
2827
import org.spongepowered.api.entity.living.player.Player;
2928
import org.spongepowered.api.profile.GameProfileManager;
3029
import org.spongepowered.api.resourcepack.ResourcePack;
3130
import org.spongepowered.api.scoreboard.Scoreboard;
3231
import org.spongepowered.api.text.Text;
3332
import org.spongepowered.api.text.channel.MessageChannel;
33+
import org.spongepowered.api.text.channel.MessageReceiver;
3434
import org.spongepowered.api.world.WorldManager;
3535
import org.spongepowered.api.world.chunk.ChunkTicketManager;
3636
import org.spongepowered.api.world.storage.ChunkLayout;
@@ -43,7 +43,7 @@
4343
/**
4444
* Represents a typical Minecraft Server.
4545
*/
46-
public interface Server extends Engine, CommandSource {
46+
public interface Server extends Engine, MessageReceiver {
4747

4848
/**
4949
* Gets the {@link WorldManager}.

src/main/java/org/spongepowered/api/Sponge.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,16 @@ public static Server getServer() {
217217
return getGame().getServer();
218218
}
219219

220+
/**
221+
* Gets the {@link SystemSubject} instance from the {@link Game} instance.
222+
*
223+
* @see Game#getSystemSubject() ()
224+
* @return The system subject
225+
*/
226+
public static SystemSubject getSystemSubject() {
227+
return getGame().getSystemSubject();
228+
}
229+
220230
/**
221231
* Gets the {@link CauseStackManager} instance from the
222232
* {@link Game} instance.

src/main/java/org/spongepowered/api/command/source/CommandSource.java renamed to src/main/java/org/spongepowered/api/SystemSubject.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,22 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
package org.spongepowered.api.command.source;
25+
package org.spongepowered.api;
2626

2727
import org.spongepowered.api.service.permission.Subject;
2828
import org.spongepowered.api.text.channel.MessageReceiver;
29-
import org.spongepowered.api.text.translation.locale.Locales;
30-
31-
import java.util.Locale;
3229

3330
/**
34-
* Something that traditionally executes commands, can receive messages and
35-
* can have permissions associated with them.
31+
* Represents the "super user" of the game.
3632
*
37-
* <p>Examples of potential implementations include players, the server console,
38-
* Rcon clients, web-based clients, command blocks, and so on.</p>
33+
* <p>The {@link SystemSubject} is intended to be the {@link Subject} that
34+
* represents server actions. This subject may represent an interaction
35+
* through a console.</p>
3936
*
40-
* <p>Note that while this source is provided, it is done so as a courtesy to
41-
* provide an indication as to what will both receive messages and act as a
42-
* permission {@link Subject}.</p>
37+
* <p>This object is also a {@link MessageReceiver}. Any message sent here
38+
* should be directed to a system visible location, such as a log or a
39+
* console.</p>
4340
*/
44-
public interface CommandSource extends MessageReceiver, Subject {
45-
46-
/**
47-
* Gets the name identifying this command source.
48-
*
49-
* @return The name of this command source
50-
*/
51-
String getName();
41+
public interface SystemSubject extends Subject, MessageReceiver {
5242

5343
}

src/main/java/org/spongepowered/api/block/entity/CommandBlock.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@
2424
*/
2525
package org.spongepowered.api.block.entity;
2626

27-
import org.spongepowered.api.command.source.CommandSource;
2827
import org.spongepowered.api.data.Keys;
2928
import org.spongepowered.api.data.value.OptionalValue;
3029
import org.spongepowered.api.data.value.Value;
30+
import org.spongepowered.api.service.permission.Subject;
3131
import org.spongepowered.api.text.Text;
32+
import org.spongepowered.api.text.channel.MessageReceiver;
33+
import org.spongepowered.api.util.Nameable;
3234

3335
import java.util.Optional;
3436

3537
/**
3638
* Represents a Command Block.
3739
*/
38-
public interface CommandBlock extends BlockEntity, CommandSource {
40+
public interface CommandBlock extends BlockEntity, Subject, MessageReceiver, Nameable {
3941

4042
/**
4143
* Executes the currently stored command.

src/main/java/org/spongepowered/api/block/entity/Sign.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424
*/
2525
package org.spongepowered.api.block.entity;
2626

27-
import org.spongepowered.api.command.source.CommandSource;
2827
import org.spongepowered.api.data.Keys;
2928
import org.spongepowered.api.data.value.ListValue;
29+
import org.spongepowered.api.service.permission.Subject;
3030
import org.spongepowered.api.text.Text;
31+
import org.spongepowered.api.util.Nameable;
3132

3233
/**
3334
* Represents a sign.
3435
*/
35-
public interface Sign extends BlockEntity, CommandSource {
36+
public interface Sign extends BlockEntity, Subject, Nameable {
3637

3738
/**
3839
* Gets the {@link org.spongepowered.api.data.value.ListValue.Mutable} of {@link Text} for the {@link Sign}

src/main/java/org/spongepowered/api/command/Command.java

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
import org.spongepowered.api.command.exception.CommandException;
3030
import org.spongepowered.api.command.parameter.CommandContext;
3131
import org.spongepowered.api.command.parameter.Parameter;
32-
import org.spongepowered.api.command.source.CommandSource;
3332
import org.spongepowered.api.event.cause.Cause;
3433
import org.spongepowered.api.event.cause.EventContext;
3534
import org.spongepowered.api.event.cause.EventContextKeys;
3635
import org.spongepowered.api.plugin.PluginContainer;
36+
import org.spongepowered.api.service.permission.Subject;
3737
import org.spongepowered.api.text.Text;
3838
import org.spongepowered.api.util.ResettableBuilder;
3939
import org.spongepowered.api.world.Location;
@@ -63,10 +63,10 @@
6363
* as required. This <em>may</em> enable the use of client side command
6464
* completions, if the implementation is equipped to do so.</p>
6565
*
66-
* <p>Commands in Sponge are provided with a {@link Cause}, which explains
67-
* who <strong>directly</strong> invoked the command. In line with causes used
68-
* in events, you may assume that the {@link Cause#root()} is the
69-
* <strong>intended</strong> direct invoker.</p>
66+
* <p>Commands in Sponge are provided with a {@link CommandCause}, which
67+
* provides a {@link Cause} explains who <strong>directly</strong> invoked the
68+
* command. In line with causes used in events, you may assume that the
69+
* {@link Cause#root()} is the <strong>intended</strong> direct invoker.</p>
7070
*
7171
* <p>It is <em>very</em> important to note that no object in the {@link Cause}
7272
* is guaranteed to be a traditional "command source" - a plugin may invoke a
@@ -86,12 +86,16 @@
8686
* be handled, in addition to using the provided cause stack:</p>
8787
*
8888
* <ul>
89-
* <li>{@link EventContextKeys#MESSAGE_CHANNEL}, which indicates the
89+
* <li>{@link EventContextKeys#MESSAGE_TARGET}, which indicates the
9090
* where messages that should be sent back to the invoker should be sent
9191
* to (typically messages indicating the status of the command execution);
92-
* and,</li>
92+
* </li>
9393
* <li>{@link EventContextKeys#SUBJECT}, which indicates the subject that
94-
* should be subjected to any permission checks.</li>
94+
* should be subjected to any permission checks;</li>
95+
* <li>{@link EventContextKeys#LOCATION}, which indicates the location that
96+
* the command should be assumed to be executed around; and,</li>
97+
* <li>{@link EventContextKeys#BLOCK_TARGET}, which indicates the block that
98+
* the command should take into account when executing.</li>
9599
* </ul>
96100
*/
97101
public interface Command {
@@ -111,31 +115,31 @@ static Builder builder() {
111115
* <p>The implementing class must perform the necessary permission
112116
* checks.</p>
113117
*
114-
* @param cause The {@link Cause} of the invocation of command
118+
* @param cause The {@link CommandCause} of the invocation of command
115119
* @param arguments The raw arguments for this command
116120
* @return The result of a command being processed
117121
* @throws CommandException Thrown on a command error
118122
*/
119-
CommandResult process(Cause cause, String arguments) throws CommandException;
123+
CommandResult process(CommandCause cause, String arguments) throws CommandException;
120124

121125
/**
122126
* Gets a list of suggestions based on input.
123127
*
124128
* <p>If a suggestion is chosen by the user, it will replace the last
125129
* word.</p>
126130
*
127-
* @param cause The {@link Cause} of the command
131+
* @param cause The {@link CommandCause} of the command
128132
* @param arguments The arguments entered up to this point
129133
* @param targetPosition The position the source is looking at when
130134
* performing tab completion
131135
* @return A list of suggestions
132136
* @throws CommandException Thrown if there was a parsing error
133137
*/
134-
List<String> getSuggestions(Cause cause, String arguments, @Nullable Location targetPosition) throws CommandException;
138+
List<String> getSuggestions(CommandCause cause, String arguments, @Nullable Location targetPosition) throws CommandException;
135139

136140
/**
137141
* Test whether this command can probably be executed given this
138-
* {@link Cause} and {@link CommandSource}.
142+
* {@link Cause}.
139143
*
140144
* <p>If implementations are unsure if the command can be executed by
141145
* the source, {@code true} should be returned. Return values of this method
@@ -145,7 +149,7 @@ static Builder builder() {
145149
* @param cause The {@link Cause} to check
146150
* @return Whether this command will execute
147151
*/
148-
boolean canExecute(Cause cause);
152+
boolean canExecute(CommandCause cause);
149153

150154
/**
151155
* Gets a short one-line description of this command.
@@ -155,7 +159,7 @@ static Builder builder() {
155159
* @param cause The {@link Cause} of the help request
156160
* @return A description
157161
*/
158-
Optional<Text> getShortDescription(Cause cause);
162+
Optional<Text> getShortDescription(CommandCause cause);
159163

160164
/**
161165
* Gets a longer formatted help message about this command.
@@ -172,7 +176,7 @@ static Builder builder() {
172176
* @param cause The {@link Cause} of the help request
173177
* @return A help text
174178
*/
175-
Optional<Text> getHelp(Cause cause);
179+
Optional<Text> getHelp(CommandCause cause);
176180

177181
/**
178182
* Gets the usage string of this command.
@@ -185,7 +189,7 @@ static Builder builder() {
185189
* @param cause The {@link Cause} of the help request
186190
* @return A usage string
187191
*/
188-
Text getUsage(Cause cause);
192+
Text getUsage(CommandCause cause);
189193

190194
/**
191195
* A {@link Command} that has distinct steps for parsing arguments and
@@ -208,13 +212,13 @@ interface Parameterized extends Command, CommandExecutor {
208212
* @param arguments The argument {@link String}
209213
* @return The {@link CommandContext}
210214
*/
211-
CommandContext parseArguments(Cause cause, String arguments);
215+
CommandContext parseArguments(CommandCause cause, String arguments);
212216

213217
/**
214218
* Processes the command by parsing the arguments, then
215219
* executing command based on these arguments.
216220
*
217-
* <p>By default, this will call {@link #parseArguments(Cause, String)}
221+
* <p>By default, this will call {@link #parseArguments(CommandCause, String)}
218222
* and pass the resulting {@link CommandContext} to
219223
* {@link #execute(CommandContext)}.</p>
220224
*
@@ -223,7 +227,7 @@ interface Parameterized extends Command, CommandExecutor {
223227
* @return The result of a command being processed
224228
* @throws CommandException Thrown on a command error
225229
*/
226-
default CommandResult process(Cause cause, String arguments) throws CommandException {
230+
default CommandResult process(CommandCause cause, String arguments) throws CommandException {
227231
return execute(parseArguments(cause, arguments));
228232
}
229233

@@ -362,7 +366,7 @@ default Builder parameters(Iterable<Parameter> parameters) {
362366
* relevant description based on the supplied {@link Cause}
363367
* @return This builder, for chaining
364368
*/
365-
Builder setExtendedDescription(Function<Cause, Optional<Text>> extendedDescriptionFunction);
369+
Builder setExtendedDescription(Function<CommandCause, Optional<Text>> extendedDescriptionFunction);
366370

367371
/**
368372
* Provides the description for this command.
@@ -382,18 +386,17 @@ default Builder setExtendedDescription(@Nullable Text extendedDescription) {
382386

383387
/**
384388
* Provides a simple description for this command, typically no more
385-
* than one line, which is dependent on the {@link Cause} and the
386-
* responsible {@link CommandSource} that requests it.
389+
* than one line, which is dependent on the {@link Cause} that requests
390+
* it.
387391
*
388392
* <p>Fuller descriptions should be provided through
389393
* {@link #setExtendedDescription(Function)}</p>
390394
*
391395
* @param descriptionFunction A function that provides a relevant
392-
* description based on the supplied {@link Cause} and
393-
* {@link CommandSource}
396+
* description based on the supplied {@link Cause}
394397
* @return This builder, for chaining
395398
*/
396-
Builder setShortDescription(Function<Cause, Optional<Text>> descriptionFunction);
399+
Builder setShortDescription(Function<CommandCause, Optional<Text>> descriptionFunction);
397400

398401
/**
399402
* Provides a simple description for this command, typically no more
@@ -413,8 +416,9 @@ default Builder setShortDescription(@Nullable Text description) {
413416
}
414417

415418
/**
416-
* The permission that a {@link CommandSource} requires to run this
417-
* command, or {@code null} if no permission is required.
419+
* The permission that the responsible {@link Subject} in the given
420+
* {@link Cause} requires to run this command, or {@code null} if no
421+
* permission is required.
418422
*
419423
* <p>For more control over whether a command can be executed, use
420424
* {@link #setExecutionRequirements(Predicate)}. However, note that
@@ -423,7 +427,7 @@ default Builder setShortDescription(@Nullable Text description) {
423427
* during execution.</p>
424428
*
425429
* <p>Any permission checks set here will be performed during the
426-
* {@link Command#canExecute(Cause)}.</p>
430+
* {@link Command#canExecute(CommandCause)}.</p>
427431
*
428432
* <p>Calling this repeatedly will not add additional permission
429433
* checks, instead replacing the permission check. If multiple
@@ -438,21 +442,21 @@ default Builder setShortDescription(@Nullable Text description) {
438442

439443
/**
440444
* Sets a function that determines what is required of the provided
441-
* {@link Cause} and {@link CommandSource} before this command executes.
445+
* {@link Cause} before this command executes.
442446
*
443447
* <p>Any requirements here are in addition to the permission check
444448
* from {@link #setPermission(String)}</p>
445449
*
446450
* <p>Any requirements set here will be performed during the
447-
* {@link Command#canExecute(Cause)}.</p>
451+
* {@link Command#canExecute(CommandCause)}.</p>
448452
*
449453
* <p>Calling this repeatedly will not add additional checks, instead
450454
* replacing the previous requirements.</p>
451455
*
452456
* @param executionRequirements A function that sets the
453457
* @return This builder, for chaining
454458
*/
455-
Builder setExecutionRequirements(@Nullable Predicate<Cause> executionRequirements);
459+
Builder setExecutionRequirements(@Nullable Predicate<CommandCause> executionRequirements);
456460

457461
/**
458462
* Builds this command, creating a {@link Command.Parameterized}

0 commit comments

Comments
 (0)