Skip to content

Commit 10ea9f9

Browse files
committed
Entirely remove all else statements
1 parent 97f4881 commit 10ea9f9

File tree

7 files changed

+34
-53
lines changed

7 files changed

+34
-53
lines changed

docs/paper/dev/api/command-api/arguments/enums.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ public static LiteralCommandNode<CommandSourceStack> gameModeArgument() {
5555
player.sendRichMessage("Your gamemode has been set to <red><gamemode></red>!",
5656
Placeholder.component("gamemode", Component.translatable(gamemode.translationKey()))
5757
);
58+
return Command.SINGLE_SUCCESS;
5859
}
59-
else {
60-
ctx.getSource().getSender().sendPlainMessage("This command requires a player!");
61-
}
62-
60+
61+
ctx.getSource().getSender().sendPlainMessage("This command requires a player!");
6362
return Command.SINGLE_SUCCESS;
6463
}))
6564
.build();

docs/paper/dev/api/command-api/arguments/location.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ public static LiteralCommandNode<CommandSourceStack> worldArgument() {
8585
Placeholder.component("player", player.name()),
8686
Placeholder.unparsed("world", world.getName())
8787
);
88-
}
89-
else {
90-
ctx.getSource().getSender().sendRichMessage("<red>This command requires a player!");
88+
return Command.SINGLE_SUCCESS;
9189
}
9290

91+
ctx.getSource().getSender().sendRichMessage("<red>This command requires a player!");
9392
return Command.SINGLE_SUCCESS;
9493
})
9594
).build();

docs/paper/dev/api/command-api/arguments/paper.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ public static LiteralCommandNode<CommandSourceStack> itemStackArgument() {
5454
Placeholder.component("player", player.name()),
5555
Placeholder.component("item", Component.translatable(itemStack.translationKey()))
5656
);
57-
}
58-
else {
59-
ctx.getSource().getSender().sendRichMessage("<red>This argument requires a player!");
57+
return Command.SINGLE_SUCCESS;
6058
}
6159

60+
ctx.getSource().getSender().sendRichMessage("<red>This argument requires a player!");
6261
return Command.SINGLE_SUCCESS;
6362
}))
6463
.build();
@@ -117,11 +116,10 @@ public static LiteralCommandNode<CommandSourceStack> timeArgument() {
117116
if (ctx.getSource().getExecutor() instanceof Player player) {
118117
player.getWorld().setFullTime(player.getWorld().getFullTime() + timeInTicks);
119118
player.sendRichMessage("Moved time forward by " + timeInTicks + " ticks!");
120-
}
121-
else {
122-
ctx.getSource().getSender().sendPlainMessage("This argument requires a player!");
119+
return Command.SINGLE_SUCCESS;
123120
}
124121

122+
ctx.getSource().getSender().sendPlainMessage("This argument requires a player!");
125123
return Command.SINGLE_SUCCESS;
126124
})
127125
).build();

docs/paper/dev/api/command-api/arguments/predicate.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ private static int runIntegerRangeCommand(final CommandContext<CommandSourceStac
6060
ctx.getSource().getSender().sendRichMessage("<aqua><input></aqua> <green>is</green> inside the specified range!",
6161
Placeholder.unparsed("input", Integer.toString(integerToTest))
6262
);
63+
return Command.SINGLE_SUCCESS;
6364
}
64-
else {
65-
ctx.getSource().getSender().sendRichMessage("<aqua><input></aqua> <red>is not</red> inside the specified range!",
66-
Placeholder.unparsed("input", Integer.toString(integerToTest))
67-
);
68-
}
65+
66+
ctx.getSource().getSender().sendRichMessage("<aqua><input></aqua> <red>is not</red> inside the specified range!",
67+
Placeholder.unparsed("input", Integer.toString(integerToTest))
68+
);
6969

7070
return Command.SINGLE_SUCCESS;
7171
}

docs/paper/dev/api/command-api/arguments/registry.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ public static LiteralCommandNode<CommandSourceStack> enchantmentRegistry() {
6969
Placeholder.component("item", Component.translatable(stack.translationKey())),
7070
Placeholder.component("enchantment", enchantment.displayName(10))
7171
);
72-
}
73-
else {
74-
ctx.getSource().getSender().sendRichMessage("<red>This command requires a player!");
72+
return Command.SINGLE_SUCCESS;
7573
}
7674

75+
ctx.getSource().getSender().sendRichMessage("<red>This command requires a player!");
7776
return Command.SINGLE_SUCCESS;
7877
}))
7978
.build();

docs/paper/dev/api/command-api/basics/executors.mdx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ Commands.literal("flyspeed")
7373
if (sender == executor) {
7474
// If the player executed the command themselves
7575
player.sendPlainMessage("Successfully set your flight speed to " + speed);
76+
return Command.SINGLE_SUCCESS;
7677
}
77-
else {
78-
// If the speed was set by a different sender (Like using /execute)
79-
sender.sendRichMessage("Successfully set <playername>'s flight speed to " + speed, Placeholder.component("playername", player.name()));
80-
player.sendPlainMessage("Your flight speed has been set to " + speed);
81-
}
82-
78+
79+
// If the speed was set by a different sender (Like using /execute)
80+
sender.sendRichMessage("Successfully set <playername>'s flight speed to " + speed, Placeholder.component("playername", player.name()));
81+
player.sendPlainMessage("Your flight speed has been set to " + speed);
8382
return Command.SINGLE_SUCCESS;
8483
})
8584
);
@@ -152,13 +151,12 @@ public class FlightSpeedCommand {
152151
if (sender == executor) {
153152
// If the player executed the command themselves
154153
player.sendPlainMessage("Successfully set your flight speed to " + speed);
155-
}
156-
else {
157-
// If the speed was set by a different sender (Like using /execute)
158-
sender.sendRichMessage("Successfully set <playername>'s flight speed to " + speed, Placeholder.component("playername", player.name()));
159-
player.sendPlainMessage("Your flight speed has been set to " + speed);
154+
return Command.SINGLE_SUCCESS;
160155
}
161156

157+
// If the speed was set by a different sender (Like using /execute)
158+
sender.sendRichMessage("Successfully set <playername>'s flight speed to " + speed, Placeholder.component("playername", player.name()));
159+
player.sendPlainMessage("Your flight speed has been set to " + speed);
162160
return Command.SINGLE_SUCCESS;
163161
}
164162
}

docs/paper/dev/api/command-api/misc/basic-command.mdx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,9 @@ operator permissions. You can also set this permission to be `true` by default.
9393
Now, in our `execute` method, we can retrieve the name of the executor of that command. If we do not find one, we can just get the name of the command sender, like this:
9494

9595
```java
96-
final Component name;
97-
if (commandSourceStack.getExecutor() != null) {
98-
name = commandSourceStack.getExecutor().name();
99-
}
100-
else {
101-
name = commandSourceStack.getSender().name();
102-
}
96+
final Component name = commandSourceStack.getExecutor() != null
97+
? commandSourceStack.getExecutor().name()
98+
: commandSourceStack.getSender().name();
10399
```
104100

105101
This makes sure that we cover all cases and even allow the command to work correctly with `/execute as`.
@@ -146,13 +142,9 @@ public class BroadcastCommand implements BasicCommand {
146142

147143
@Override
148144
public void execute(CommandSourceStack commandSourceStack, String[] args) {
149-
final Component name;
150-
if (commandSourceStack.getExecutor() != null) {
151-
name = commandSourceStack.getExecutor().name();
152-
}
153-
else {
154-
name = commandSourceStack.getSender().name();
155-
}
145+
final Component name = commandSourceStack.getExecutor() != null
146+
? commandSourceStack.getExecutor().name()
147+
: commandSourceStack.getSender().name();
156148

157149
if (args.length == 0) {
158150
commandSourceStack.getSender().sendRichMessage("<red>You cannot send an empty broadcast!");
@@ -253,13 +245,9 @@ public class BroadcastCommand implements BasicCommand {
253245

254246
@Override
255247
public void execute(CommandSourceStack commandSourceStack, String[] args) {
256-
final Component name;
257-
if (commandSourceStack.getExecutor() != null) {
258-
name = commandSourceStack.getExecutor().name();
259-
}
260-
else {
261-
name = commandSourceStack.getSender().name();
262-
}
248+
final Component name = commandSourceStack.getExecutor() != null
249+
? commandSourceStack.getExecutor().name()
250+
: commandSourceStack.getSender().name();
263251

264252
if (args.length == 0) {
265253
commandSourceStack.getSender().sendRichMessage("<red>You cannot send an empty broadcast!");

0 commit comments

Comments
 (0)