11package io .papermc .paper .command ;
22
33import 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 ;
109import java .text .DecimalFormat ;
1110import java .util .ArrayList ;
1211import java .util .Arrays ;
13- import java .util .Collections ;
1412import 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
1818import static net .kyori .adventure .text .Component .text ;
1919import static net .kyori .adventure .text .format .NamedTextColor .GOLD ;
2222import static net .kyori .adventure .text .format .NamedTextColor .RED ;
2323import 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