package carpetextra.commands; import carpetextra.CarpetExtraSettings; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; import static net.minecraft.server.command.CommandManager.literal; public class PingCommand { public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> command = literal("ping"). requires( (player) -> CarpetExtraSettings.commandPing). executes( c -> { ServerPlayerEntity playerEntity = c.getSource().getPlayer(); int ping = playerEntity.pingMilliseconds; playerEntity.sendMessage(new LiteralText("Your ping is: " + ping + " ms")); return 1; }); dispatcher.register(command); } }