Skip to content

Commit 4b3b397

Browse files
authored
Port mspt command to brigadier (#12630)
1 parent c1408c2 commit 4b3b397

2 files changed

Lines changed: 24 additions & 30 deletions

File tree

paper-server/src/main/java/io/papermc/paper/command/PaperCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ private PaperCommands() {
2323

2424
public static void registerCommands(final MinecraftServer server) {
2525
COMMANDS.put("paper", new PaperCommand("paper"));
26-
COMMANDS.put("mspt", new MSPTCommand("mspt"));
2726

2827
COMMANDS.forEach((s, command) -> {
2928
server.server.getCommandMap().register(s, "Paper", command);
@@ -32,6 +31,7 @@ public static void registerCommands(final MinecraftServer server) {
3231

3332
public static void registerCommands() {
3433
// Paper commands go here
34+
registerInternalCommand(PaperMSPTCommand.create(), "paper", PaperMSPTCommand.DESCRIPTION, List.of(), Set.of());
3535
registerInternalCommand(PaperVersionCommand.create(), "bukkit", PaperVersionCommand.DESCRIPTION, List.of("ver", "about"), Set.of());
3636
registerInternalCommand(PaperPluginsCommand.create(), "bukkit", PaperPluginsCommand.DESCRIPTION, List.of("pl"), Set.of());
3737
}

paper-server/src/main/java/io/papermc/paper/command/MSPTCommand.java renamed to paper-server/src/main/java/io/papermc/paper/command/PaperMSPTCommand.java

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package io.papermc.paper.command;
22

33
import ca.spottedleaf.common.time.TickData;
4-
import net.kyori.adventure.text.Component;
5-
import net.minecraft.server.MinecraftServer;
6-
import org.bukkit.Location;
7-
import org.bukkit.command.Command;
8-
import org.bukkit.command.CommandSender;
9-
4+
import com.mojang.brigadier.Command;
5+
import com.mojang.brigadier.context.CommandContext;
6+
import com.mojang.brigadier.tree.LiteralCommandNode;
7+
import io.papermc.paper.command.brigadier.CommandSourceStack;
8+
import io.papermc.paper.command.brigadier.Commands;
109
import java.text.DecimalFormat;
1110
import java.util.ArrayList;
1211
import java.util.Arrays;
13-
import java.util.Collections;
1412
import java.util.List;
15-
import org.checkerframework.checker.nullness.qual.NonNull;
16-
import org.checkerframework.framework.qual.DefaultQualifier;
13+
import net.kyori.adventure.text.Component;
14+
import net.minecraft.server.MinecraftServer;
15+
import org.bukkit.command.CommandSender;
16+
import org.jspecify.annotations.NullMarked;
1717

1818
import static net.kyori.adventure.text.Component.text;
1919
import static net.kyori.adventure.text.format.NamedTextColor.GOLD;
@@ -22,30 +22,24 @@
2222
import static net.kyori.adventure.text.format.NamedTextColor.RED;
2323
import static net.kyori.adventure.text.format.NamedTextColor.YELLOW;
2424

25-
@DefaultQualifier(NonNull.class)
26-
public final class MSPTCommand extends Command {
27-
private static final ThreadLocal<DecimalFormat> ONE_DECIMAL_PLACES = ThreadLocal.withInitial(() -> {
28-
return new DecimalFormat("########0.0");
29-
});
25+
@NullMarked
26+
public class PaperMSPTCommand {
27+
public static final String DESCRIPTION = "View server tick times";
3028

29+
private static final DecimalFormat DF = new DecimalFormat("########0.0");
3130
private static final Component SLASH = text("/");
3231

33-
public MSPTCommand(final String name) {
34-
super(name);
35-
this.description = "View server tick times";
36-
this.usageMessage = "/mspt";
37-
this.setPermission("bukkit.command.mspt");
38-
}
32+
public static LiteralCommandNode<CommandSourceStack> create() {
33+
final PaperMSPTCommand command = new PaperMSPTCommand();
3934

40-
@Override
41-
public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
42-
return Collections.emptyList();
35+
return Commands.literal("mspt")
36+
.requires(source -> source.getSender().hasPermission("bukkit.command.mspt"))
37+
.executes(command::execute)
38+
.build();
4339
}
4440

45-
@Override
46-
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
47-
if (!testPermission(sender)) return true;
48-
41+
private int execute(CommandContext<CommandSourceStack> context) {
42+
CommandSender sender = context.getSource().getSender();
4943
MinecraftServer server = MinecraftServer.getServer();
5044

5145
List<Component> times = new ArrayList<>();
@@ -82,7 +76,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
8276
)
8377
)
8478
);
85-
return true;
79+
return Command.SINGLE_SUCCESS;
8680
}
8781

8882
private static List<Component> eval(TickData tickData) {
@@ -94,6 +88,6 @@ private static List<Component> eval(TickData tickData) {
9488
}
9589

9690
private static Component getColor(double avg) {
97-
return text(ONE_DECIMAL_PLACES.get().format(avg), avg >= 50 ? RED : avg >= 40 ? YELLOW : GREEN);
91+
return text(DF.format(avg), avg >= 50 ? RED : avg >= 40 ? YELLOW : GREEN);
9892
}
9993
}

0 commit comments

Comments
 (0)